You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/03/17 06:56:54 UTC
svn commit: r519244 [4/5] - in
/incubator/tuscany/java/sca/services/databinding/databinding-framework: ./
src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/data...
Added: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLDocumentStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLDocumentStreamReader.java?view=auto&rev=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLDocumentStreamReader.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLDocumentStreamReader.java Fri Mar 16 22:56:48 2007
@@ -0,0 +1,432 @@
+package org.apache.tuscany.databinding.xml;
+
+import java.util.NoSuchElementException;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * This class is derived from Apache Axis2 class
+ * org.apache.axis2.util.StreamWrapper</a>. It's used wrap a XMLStreamReader to
+ * create a XMLStreamReader representing a document and it will produce
+ * START_DOCUMENT, END_DOCUMENT events.
+ */
+public class XMLDocumentStreamReader implements XMLStreamReader {
+ private static final int STATE_COMPLETE_AT_NEXT = 2; // The wrapper
+ // will produce
+ // END_DOCUMENT
+
+ private static final int STATE_COMPLETED = 3; // Done
+
+ private static final int STATE_INIT = 0; // The wrapper will produce
+ // START_DOCUMENT
+
+ private static final int STATE_SWITCHED = 1; // The real reader will
+ // produce events
+
+ private XMLStreamReader realReader;
+
+ private int state = STATE_INIT;
+
+ public XMLDocumentStreamReader(XMLStreamReader realReader) {
+ if (realReader == null) {
+ throw new UnsupportedOperationException("Reader cannot be null");
+ }
+
+ this.realReader = realReader;
+
+ if (realReader instanceof XMLFragmentStreamReader) {
+ ((XMLFragmentStreamReader)realReader).init();
+ }
+
+ // If the real reader is positioned at START_DOCUMENT, always use
+ // the real reader
+ if (realReader.getEventType() == START_DOCUMENT) {
+ state = STATE_SWITCHED;
+ }
+ }
+
+ public void close() throws XMLStreamException {
+ realReader.close();
+ }
+
+ public int getAttributeCount() {
+ if (isDelegating()) {
+ return realReader.getAttributeCount();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeLocalName(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeLocalName(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public QName getAttributeName(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeName(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeNamespace(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeNamespace(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributePrefix(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributePrefix(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeType(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeType(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeValue(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(String s, String s1) {
+ if (isDelegating()) {
+ return realReader.getAttributeValue(s, s1);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getCharacterEncodingScheme() {
+ return realReader.getCharacterEncodingScheme();
+ }
+
+ public String getElementText() throws XMLStreamException {
+ if (isDelegating()) {
+ return realReader.getElementText();
+ } else {
+ throw new XMLStreamException();
+ }
+ }
+
+ public String getEncoding() {
+ return realReader.getEncoding();
+ }
+
+ public int getEventType() {
+ int event = -1;
+ switch (state) {
+ case STATE_SWITCHED:
+ case STATE_COMPLETE_AT_NEXT:
+ event = realReader.getEventType();
+ break;
+ case STATE_INIT:
+ event = START_DOCUMENT;
+ break;
+ case STATE_COMPLETED:
+ event = END_DOCUMENT;
+ break;
+ }
+ return event;
+ }
+
+ public String getLocalName() {
+ if (isDelegating()) {
+ return realReader.getLocalName();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Location getLocation() {
+ if (isDelegating()) {
+ return realReader.getLocation();
+ } else {
+ return null;
+ }
+ }
+
+ public QName getName() {
+ if (isDelegating()) {
+ return realReader.getName();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return realReader.getNamespaceContext();
+ }
+
+ public int getNamespaceCount() {
+ if (isDelegating()) {
+ return realReader.getNamespaceCount();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespacePrefix(int i) {
+ if (isDelegating()) {
+ return realReader.getNamespacePrefix(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI() {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI(int i) {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI(String s) {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI(s);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPIData() {
+ if (isDelegating()) {
+ return realReader.getPIData();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPITarget() {
+ if (isDelegating()) {
+ return realReader.getPITarget();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPrefix() {
+ if (isDelegating()) {
+ return realReader.getPrefix();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Object getProperty(String s) throws IllegalArgumentException {
+ if (isDelegating()) {
+ return realReader.getProperty(s);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public String getText() {
+ if (isDelegating()) {
+ return realReader.getText();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (isDelegating()) {
+ return realReader.getTextCharacters();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ if (isDelegating()) {
+ return realReader.getTextCharacters(i, chars, i1, i2);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextLength() {
+ if (isDelegating()) {
+ return realReader.getTextLength();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextStart() {
+ if (isDelegating()) {
+ return realReader.getTextStart();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getVersion() {
+ if (isDelegating()) {
+ return realReader.getVersion();
+ } else {
+ return null;
+ }
+ }
+
+ public boolean hasName() {
+ if (isDelegating()) {
+ return realReader.hasName();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ if (state == STATE_COMPLETE_AT_NEXT) {
+ return true;
+ } else if (state == STATE_COMPLETED) {
+ return false;
+ } else if (state == STATE_SWITCHED) {
+ return realReader.hasNext();
+ } else {
+ return true;
+ }
+ }
+
+ public boolean hasText() {
+ if (isDelegating()) {
+ return realReader.hasText();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ if (isDelegating()) {
+ return realReader.isAttributeSpecified(i);
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isCharacters() {
+ if (isDelegating()) {
+ return realReader.isCharacters();
+ } else {
+ return false;
+ }
+ }
+
+ private boolean isDelegating() {
+ return state == STATE_SWITCHED || state == STATE_COMPLETE_AT_NEXT;
+ }
+
+ public boolean isEndElement() {
+ if (isDelegating()) {
+ return realReader.isEndElement();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isStandalone() {
+ if (isDelegating()) {
+ return realReader.isStandalone();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isStartElement() {
+ if (isDelegating()) {
+ return realReader.isStartElement();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isWhiteSpace() {
+ if (isDelegating()) {
+ return realReader.isWhiteSpace();
+ } else {
+ return false;
+ }
+ }
+
+ public int next() throws XMLStreamException {
+ int returnEvent;
+
+ switch (state) {
+ case STATE_SWITCHED:
+ returnEvent = realReader.next();
+ if (returnEvent == END_DOCUMENT) {
+ state = STATE_COMPLETED;
+ } else if (!realReader.hasNext()) {
+ state = STATE_COMPLETE_AT_NEXT;
+ }
+ break;
+ case STATE_INIT:
+ state = STATE_SWITCHED;
+ returnEvent = realReader.getEventType();
+ break;
+ case STATE_COMPLETE_AT_NEXT:
+ state = STATE_COMPLETED;
+ returnEvent = END_DOCUMENT;
+ break;
+ case STATE_COMPLETED:
+ // oops - no way we can go beyond this
+ throw new NoSuchElementException("End of stream has reached.");
+ default:
+ throw new UnsupportedOperationException();
+ }
+
+ return returnEvent;
+ }
+
+ public int nextTag() throws XMLStreamException {
+ if (isDelegating()) {
+ return realReader.nextTag();
+ } else {
+ throw new XMLStreamException();
+ }
+ }
+
+ public void require(int i, String s, String s1) throws XMLStreamException {
+ if (isDelegating()) {
+ realReader.require(i, s, s1);
+ }
+ }
+
+ public boolean standaloneSet() {
+ if (isDelegating()) {
+ return realReader.standaloneSet();
+ } else {
+ return false;
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLDocumentStreamReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLDocumentStreamReader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReader.java?view=auto&rev=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReader.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReader.java Fri Mar 16 22:56:48 2007
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+public interface XMLFragmentStreamReader extends XMLStreamReader {
+ QName NIL_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi");
+ String NIL_VALUE_TRUE = "true";
+
+ /**
+ * this will help to handle Text within the current element. user should
+ * pass the element text to the property list as this ELEMENT_TEXT as the
+ * key. This key deliberately has a space in it so that it is not a valid
+ * XML name
+ */
+ String ELEMENT_TEXT = "Element Text";
+
+ /**
+ * Extra method to query the state of the pullparser
+ */
+ boolean isDone();
+
+ /**
+ * add the parent namespace context to this parser
+ */
+ void setParentNamespaceContext(NamespaceContext nsContext);
+
+ /**
+ * Initiate the parser - this will do whatever the needed tasks to initiate
+ * the parser and must be called before attempting any specific parsing
+ * using this parser
+ */
+ void init();
+}
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReaderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReaderImpl.java?view=auto&rev=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReaderImpl.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReaderImpl.java Fri Mar 16 22:56:48 2007
@@ -0,0 +1,857 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.databinding.xml;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * This is the new implementation of the XMLFramentStreamReader. The approach
+ * here is simple When the pull parser needs to generate events for a particular
+ * name-value(s) pair it always handes over (delegates) the task to another pull
+ * parser which knows how to deal with it The common types of name value pairs
+ * we'll come across are
+ * <ul>
+ * <li> String name/QName name - String value
+ * <li> String name/QName name - String[] value
+ * <li> QName name/String name - XMLStreamReader value
+ * <li> QName name/String name - XMLStreamable value
+ * <li> QName name/String name - Java bean
+ * <li> QName name/String name - Datahandler
+ *
+ * </ul>
+ * <p/> As for the attributes, these are the possible combinations in the array
+ * <ul>
+ * <li> String name/QName name - String value
+ * </ul>
+ * Note that certain array methods have been deliberately removed to avoid
+ * complications. The generated code will take the trouble to lay the elements
+ * of the array in the correct order <p/> <p/> Hence there will be a parser impl
+ * that knows how to handle these types, and this parent parser will always
+ * delegate these tasks to the child pullparasers in effect this is one huge
+ * state machine that has only a few states and delegates things down to the
+ * child parsers whenever possible <p/>
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLFragmentStreamReaderImpl implements XMLFragmentStreamReader {
+
+ private static final int DELEGATED_STATE = 2;
+ private static final int END_ELEMENT_STATE = 1;
+ // states for this pullparser - it can only have four states
+ private static final int START_ELEMENT_STATE = 0;
+ private static final int TEXT_STATE = 3;
+
+ protected NamedProperty[] attributes;
+
+ // reference to the child reader
+ protected XMLFragmentStreamReader childReader;
+ // current property index
+ // initialized at zero
+ protected int index;
+ protected Map<String, String> declaredNamespaceMap = new HashMap<String, String>();
+ protected QName elementQName;
+
+ // we always create a new namespace context
+ protected DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext();
+
+ protected NamedProperty[] elements;
+
+ // integer field that keeps the state of this
+ // parser.
+ protected int state = START_ELEMENT_STATE;
+
+ /*
+ * we need to pass in a namespace context since when delegated, we've no
+ * idea of the current namespace context. So it needs to be passed on here!
+ */
+ public XMLFragmentStreamReaderImpl(QName elementQName, NamedProperty[] elements, NamedProperty[] attributes) {
+ // validate the lengths, since both the arrays are supposed
+ // to have
+ this.elements = elements == null ? new NamedProperty[0] : elements;
+ this.elementQName = elementQName;
+ this.attributes = attributes == null ? new NamedProperty[0] : attributes;
+ }
+
+ protected XMLFragmentStreamReaderImpl(QName elementQName) {
+ this.elementQName = elementQName;
+ }
+
+ /**
+ * add the namespace context
+ */
+
+ public void setParentNamespaceContext(NamespaceContext nsContext) {
+ // register the namespace context passed in to this
+ this.namespaceContext.setParentNsContext(nsContext);
+
+ }
+
+ protected NamedProperty[] getElements() {
+ return elements;
+ }
+
+ protected NamedProperty[] getAttributes() {
+ return attributes;
+ }
+
+ protected QName[] getNamespaces() {
+ return new QName[0];
+ }
+
+ /**
+ * @param prefix
+ * @param uri
+ */
+ protected void addToNsMap(String prefix, String uri) {
+ if (!uri.equals(namespaceContext.getNamespaceURI(prefix))) {
+ namespaceContext.pushNamespace(prefix, uri);
+ declaredNamespaceMap.put(prefix, uri);
+ }
+ }
+
+ public void close() throws XMLStreamException {
+ // do nothing here - we have no resources to free
+ }
+
+ public int getAttributeCount() {
+ return (state == DELEGATED_STATE) ? childReader.getAttributeCount() : (state == START_ELEMENT_STATE
+ ? getAttributes().length : 0);
+ }
+
+ public String getAttributeLocalName(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeLocalName(i);
+ } else if (state == START_ELEMENT_STATE) {
+ QName name = getAttributeName(i);
+ if (name == null) {
+ return null;
+ } else {
+ return name.getLocalPart();
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * @param i
+ */
+ public QName getAttributeName(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeName(i);
+ } else if (state == START_ELEMENT_STATE) {
+ if ((i >= (getAttributes().length)) || i < 0) { // out of range
+ return null;
+ } else {
+ // get the attribute pointer
+ QName attribPointer = getAttributes()[i].getKey();
+ // case one - attrib name is null
+ // this should be the pointer to the OMAttribute then
+ if (attribPointer == null) {
+ throw new UnsupportedOperationException();
+ } else if (attribPointer instanceof QName) {
+ return (QName)attribPointer;
+ } else {
+ return null;
+ }
+ }
+ } else {
+ throw new IllegalStateException(); // as per the api contract
+ }
+
+ }
+
+ public String getAttributeNamespace(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeNamespace(i);
+ } else if (state == START_ELEMENT_STATE) {
+ QName name = getAttributeName(i);
+ if (name == null) {
+ return null;
+ } else {
+ return name.getNamespaceURI();
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributePrefix(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributePrefix(i);
+ } else if (state == START_ELEMENT_STATE) {
+ QName name = getAttributeName(i);
+ if (name == null) {
+ return null;
+ } else {
+ return name.getPrefix();
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeType(int i) {
+ return null; // not supported
+ }
+
+ public String getAttributeValue(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeValue(i);
+ } else if (state == START_ELEMENT_STATE) {
+ if ((i >= (getAttributes().length)) || i < 0) { // out of range
+ return null;
+ } else {
+ // get the attribute pointer
+ QName attribPointer = getAttributes()[i].getKey();
+ Object omAttribObj = getAttributes()[i].getValue();
+ // case one - attrib name is null
+ // this should be the pointer to the OMAttribute then
+ if (attribPointer == null) {
+ throw new UnsupportedOperationException();
+ } else if (attribPointer instanceof QName) {
+ return (String)omAttribObj;
+ } else {
+ return null;
+ }
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public String getAttributeValue(String nsUri, String localName) {
+
+ int attribCount = getAttributeCount();
+ String returnValue = null;
+ QName attribQualifiedName;
+ for (int i = 0; i < attribCount; i++) {
+ attribQualifiedName = getAttributeName(i);
+ if (nsUri == null) {
+ if (localName.equals(attribQualifiedName.getLocalPart())) {
+ returnValue = getAttributeValue(i);
+ break;
+ }
+ } else {
+ if (localName.equals(attribQualifiedName.getLocalPart()) && nsUri.equals(attribQualifiedName
+ .getNamespaceURI())) {
+ returnValue = getAttributeValue(i);
+ break;
+ }
+ }
+
+ }
+
+ return returnValue;
+ }
+
+ public String getCharacterEncodingScheme() {
+ return null; // todo - should we return something for this ?
+ }
+
+ /**
+ * todo implement the right contract for this
+ *
+ * @throws XMLStreamException
+ */
+ public String getElementText() throws XMLStreamException {
+ if (state == DELEGATED_STATE) {
+ return childReader.getElementText();
+ } else {
+ return null;
+ }
+
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // / attribute handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ public String getEncoding() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getEncoding();
+ } else {
+ // we've no idea what the encoding is going to be in this case
+ // perhaps we ought to return some constant here, which the user
+ // might
+ // have access to change!
+ return null;
+ }
+ }
+
+ public int getEventType() {
+ if (state == START_ELEMENT_STATE) {
+ return START_ELEMENT;
+ } else if (state == END_ELEMENT_STATE) {
+ return END_ELEMENT;
+ } else if (state == TEXT_STATE) {
+ return CHARACTERS;
+ } else { // this is the delegated state
+ return childReader.getEventType();
+ }
+ }
+
+ public String getLocalName() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getLocalName();
+ } else if (state != TEXT_STATE) {
+ return elementQName.getLocalPart();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ */
+ public Location getLocation() {
+ // return a default location
+ return new Location() {
+ public int getCharacterOffset() {
+ return 0;
+ }
+
+ public int getColumnNumber() {
+ return 0;
+ }
+
+ public int getLineNumber() {
+ return 0;
+ }
+
+ public String getPublicId() {
+ return null;
+ }
+
+ public String getSystemId() {
+ return null;
+ }
+ };
+ }
+
+ public QName getName() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getName();
+ } else if (state != TEXT_STATE) {
+ return elementQName;
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespaceContext();
+ } else {
+ return namespaceContext;
+ }
+
+ }
+
+ public int getNamespaceCount() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespaceCount();
+ } else {
+ return declaredNamespaceMap.size();
+ }
+ }
+
+ /**
+ * @param i
+ */
+ public String getNamespacePrefix(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespacePrefix(i);
+ } else if (state != TEXT_STATE) {
+ // order the prefixes
+ String[] prefixes = makePrefixArray();
+ if ((i >= prefixes.length) || (i < 0)) {
+ return null;
+ } else {
+ return prefixes[i];
+ }
+
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public String getNamespaceURI() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespaceURI();
+ } else if (state == TEXT_STATE) {
+ return null;
+ } else {
+ return elementQName.getNamespaceURI();
+ }
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // //////////// end of attribute handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ // //////////////////////////////////////////////////////////////////////////
+ // //////////// namespace handling
+ // //////////////////////////////////////////////////////////////////////////
+
+ public String getNamespaceURI(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespaceURI(i);
+ } else if (state != TEXT_STATE) {
+ String namespacePrefix = getNamespacePrefix(i);
+ return namespacePrefix == null ? null : (String)declaredNamespaceMap.get(namespacePrefix);
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return namespaceContext.getNamespaceURI(prefix);
+ }
+
+ public String getPIData() {
+ throw new UnsupportedOperationException("Yet to be implemented !!");
+ }
+
+ public String getPITarget() {
+ throw new UnsupportedOperationException("Yet to be implemented !!");
+ }
+
+ public String getPrefix() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getPrefix();
+ } else if (state == TEXT_STATE) {
+ return null;
+ } else {
+ String prefix = elementQName.getPrefix();
+ return "".equals(prefix) ? null : prefix;
+ }
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // /////// end of namespace handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param key
+ * @throws IllegalArgumentException
+ */
+ public Object getProperty(String key) throws IllegalArgumentException {
+ if (state == START_ELEMENT_STATE || state == END_ELEMENT_STATE) {
+ return null;
+ } else if (state == TEXT_STATE) {
+ return null;
+ } else if (state == DELEGATED_STATE) {
+ return childReader.getProperty(key);
+ } else {
+ return null;
+ }
+
+ }
+
+ public String getText() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getText();
+ } else if (state == TEXT_STATE) {
+ return (String)getElements()[index - 1].getValue();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextCharacters();
+ } else if (state == TEXT_STATE) {
+ return getElements()[index - 1].getValue() == null ? new char[0] : ((String)getElements()[index - 1]
+ .getValue()).toCharArray();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ private int copy(int sourceStart, char[] target, int targetStart, int length) {
+ char[] source = getTextCharacters();
+ if (sourceStart > source.length) {
+ throw new IndexOutOfBoundsException("source start > source length");
+ }
+ int sourceLen = source.length - sourceStart;
+ if (length > sourceLen) {
+ length = sourceLen;
+ }
+ System.arraycopy(source, sourceStart, target, targetStart, length);
+ return sourceLen;
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextCharacters(i, chars, i1, i2);
+ } else if (state == TEXT_STATE) {
+ return copy(i, chars, i1, i2);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextLength() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextLength();
+ } else if (state == TEXT_STATE) {
+ return getTextCharacters().length;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextStart() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextStart();
+ } else if (state == TEXT_STATE) {
+ return 0; // assume text always starts at 0
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getVersion() {
+ return null;
+ }
+
+ public boolean hasName() {
+ // since this parser always has a name, the hasname
+ // has to return true if we are still navigating this element
+ // if not we should ask the child reader for it.
+ if (state == DELEGATED_STATE) {
+ return childReader.hasName();
+ } else {
+ return state != TEXT_STATE;
+ }
+ }
+
+ /**
+ * @throws XMLStreamException
+ */
+ public boolean hasNext() throws XMLStreamException {
+ if (state == DELEGATED_STATE) {
+ if (childReader.isDone()) {
+ // the child reader is done. We shouldn't be getting the
+ // hasnext result from the child pullparser then
+ return true;
+ } else {
+ return childReader.hasNext();
+ }
+ } else {
+ return state == START_ELEMENT_STATE || state == TEXT_STATE;
+
+ }
+ }
+
+ /**
+ * check the validity of this implementation
+ */
+ public boolean hasText() {
+ if (state == DELEGATED_STATE) {
+ return childReader.hasText();
+ } else {
+ return state == TEXT_STATE;
+ }
+
+ }
+
+ /**
+ * we need to split out the calling to the populate namespaces seperately
+ * since this needs to be done *after* setting the parent namespace context.
+ * We cannot assume it will happen at construction!
+ */
+ public void init() {
+ // here we have an extra issue to attend to. we need to look at the
+ // prefixes and uris (the combination) and populate a hashmap of
+ // namespaces. The hashmap of namespaces will be used to serve the
+ // namespace context
+
+ populateNamespaceContext();
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ return false; // not supported
+ }
+
+ public boolean isCharacters() {
+ if (state == START_ELEMENT_STATE || state == END_ELEMENT_STATE) {
+ return false;
+ }
+ return childReader.isCharacters();
+ }
+
+ /**
+ * are we done ?
+ */
+ public boolean isDone() {
+ return state == END_ELEMENT_STATE;
+ }
+
+ public boolean isEndElement() {
+ if (state == START_ELEMENT_STATE) {
+ return false;
+ } else if (state == END_ELEMENT_STATE) {
+ return true;
+ }
+ return childReader.isEndElement();
+ }
+
+ public boolean isStandalone() {
+ return true;
+ }
+
+ public boolean isStartElement() {
+ if (state == START_ELEMENT_STATE) {
+ return true;
+ } else if (state == END_ELEMENT_STATE) {
+ return false;
+ }
+ return childReader.isStartElement();
+ }
+
+ public boolean isWhiteSpace() {
+ if (state == START_ELEMENT_STATE || state == END_ELEMENT_STATE) {
+ return false;
+ }
+ return childReader.isWhiteSpace();
+ }
+
+ /**
+ * Get the prefix list from the hastable and take that into an array
+ */
+ private String[] makePrefixArray() {
+ String[] prefixes = (String[])declaredNamespaceMap.keySet().toArray(new String[declaredNamespaceMap.size()]);
+ Arrays.sort(prefixes);
+ return prefixes;
+ }
+
+ /**
+ * By far this should be the most important method in this class this method
+ * changes the state of the parser
+ */
+ public int next() throws XMLStreamException {
+ int returnEvent = -1; // invalid state is the default state
+ switch (state) {
+ case START_ELEMENT_STATE:
+ // current element is start element. We should be looking at the
+ // property list and making a pullparser for the property value
+ if (getElements() == null || getElements().length == 0) {
+ // no properties - move to the end element state
+ // straightaway
+ state = END_ELEMENT_STATE;
+ returnEvent = END_ELEMENT;
+ } else {
+ // there are properties. now we should delegate this task to
+ // a
+ // child reader depending on the property type
+ returnEvent = processProperties();
+
+ }
+ break;
+ case END_ELEMENT_STATE:
+ // we've reached the end element already. If the user tries to
+ // push
+ // further ahead then it is an exception
+ throw new XMLStreamException("Trying to go beyond the end of the pullparser");
+
+ case DELEGATED_STATE:
+ if (childReader.isDone()) {
+ // we've reached the end!
+ if (index > (getElements().length - 1)) {
+ state = END_ELEMENT_STATE;
+ returnEvent = END_ELEMENT;
+ } else {
+ returnEvent = processProperties();
+ }
+ } else {
+ returnEvent = childReader.next();
+ }
+ break;
+
+ case TEXT_STATE:
+ // if there are any more event we should be delegating to
+ // processProperties. if not we just return an end element
+ if (index > (getElements().length - 1)) {
+ state = END_ELEMENT_STATE;
+ returnEvent = END_ELEMENT;
+ } else {
+ returnEvent = processProperties();
+ }
+ break;
+ }
+ return returnEvent;
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // / Other utility methods
+ // ////////////////////////////////////////////////////////////////////////
+
+ /**
+ * todo implement this
+ *
+ * @throws XMLStreamException
+ */
+ public int nextTag() throws XMLStreamException {
+ return 0;
+ }
+
+ /**
+ * Populates a namespace context
+ */
+ private void populateNamespaceContext() {
+
+ // first add the current element namespace to the namespace context
+ // declare it if not found
+ addToNsMap(elementQName.getPrefix(), elementQName.getNamespaceURI());
+
+ for (QName n : getNamespaces()) {
+ addToNsMap(n.getPrefix(), n.getNamespaceURI());
+ }
+
+ // traverse through the attributes and populate the namespace context
+ // the attrib list can be of many combinations
+ // the valid combinations are
+ // String - String
+ // QName - QName
+ // null - OMAttribute
+
+ for (int i = 0; i < getAttributes().length; i++) { // jump in two
+ QName attrQName = getAttributes()[i].getKey();
+ if (!"".equals(attrQName.getNamespaceURI())) {
+ addToNsMap(attrQName.getPrefix(), attrQName.getNamespaceURI());
+ }
+ }
+ }
+
+ /**
+ * A convenient method to reuse the properties
+ *
+ * @return event to be thrown
+ * @throws XMLStreamException
+ */
+ private int processProperties() throws XMLStreamException {
+ // move to the next property depending on the current property
+ // index
+ QName propertyQName = getElements()[index].getKey();
+ boolean textFound = false;
+ if (propertyQName == null) {
+ throw new XMLStreamException("property key cannot be null!");
+ } else if (ELEMENT_TEXT.equals(propertyQName.getLocalPart())) {
+ // propPointer being a String has a special case
+ // that is it can be a the special constant ELEMENT_TEXT that
+ // says this text event
+ textFound = true;
+ }
+
+ // ok! we got the key. Now look at the value
+ Object propertyValue = getElements()[index].getValue();
+ // cater for the special case now
+ if (textFound) {
+ // no delegation here - make the parser null and immediately
+ // return with the event characters
+ childReader = null;
+ state = TEXT_STATE;
+ ++index;
+ return CHARACTERS;
+ } else if (propertyValue == null) {
+ // if the value is null we delegate the work to a nullable
+ // parser
+ childReader = new NilElementStreamReader(propertyQName);
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else if (propertyValue instanceof String) {
+ // strings are handled by the NameValuePairStreamReader
+ childReader = new NameValuePairStreamReader(propertyQName, (String)propertyValue);
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else if (propertyValue instanceof String[]) {
+ // string[] are handled by the NameValueArrayStreamReader
+ // if the array is empty - skip it
+ if (((String[])propertyValue).length == 0) {
+ // advance the index
+ ++index;
+ return processProperties();
+ } else {
+ childReader = new NameValueArrayStreamReader(propertyQName, (String[])propertyValue);
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ }
+
+ } else if (propertyValue instanceof XMLStreamable) {
+ // ADBbean has it's own method to get a reader
+ XMLStreamReader reader = ((XMLStreamable)propertyValue).getXMLStreamReader(propertyQName);
+ // we know for sure that this is an ADB XMLStreamreader.
+ // However we need to make sure that it is compatible
+ if (reader instanceof XMLFragmentStreamReader) {
+ childReader = (XMLFragmentStreamReader)reader;
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else {
+ // wrap it to make compatible
+ childReader = new WrappingXMLStreamReader(reader);
+ }
+ } else if (propertyValue instanceof XMLStreamReader) {
+ XMLStreamReader reader = (XMLStreamReader)propertyValue;
+ if (reader instanceof XMLFragmentStreamReader) {
+ childReader = (XMLFragmentStreamReader)reader;
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else {
+ // wrap it to make compatible
+ childReader = new WrappingXMLStreamReader(reader);
+ }
+
+ } else {
+ // all special possiblilities has been tried! Let's treat
+ // the thing as a bean and try generating events from it
+ childReader = new WrappingXMLStreamReader(BeanUtil.getXMLStreamReader(propertyValue, propertyQName));
+ // we cannot register the namespace context here
+ }
+
+ // set the state here
+ state = DELEGATED_STATE;
+ // we are done with the delegation
+ // increment the property index
+ ++index;
+ return childReader.getEventType();
+ }
+
+ public void require(int i, String string, String string1) throws XMLStreamException {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean standaloneSet() {
+ return true;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReaderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLFragmentStreamReaderImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLGroupDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLGroupDataBinding.java?view=auto&rev=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLGroupDataBinding.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLGroupDataBinding.java Fri Mar 16 22:56:48 2007
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.databinding.xml;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+
+import org.apache.tuscany.databinding.impl.GroupDataBinding;
+import org.apache.tuscany.spi.model.XMLType;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+
+/**
+ * A Group DataBinding
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLGroupDataBinding extends GroupDataBinding {
+
+ public XMLGroupDataBinding() {
+ super(new Class[] {InputStream.class, OutputStream.class, Reader.class, Writer.class, Source.class,
+ Result.class, InputSource.class, ContentHandler.class, XMLStreamReader.class,
+ XMLStreamWriter.class, XMLEventReader.class, XMLEventWriter.class});
+ }
+
+ @Override
+ protected Object getLogical(Class<?> markerType, Annotation[] annotations) {
+ return XMLType.UNKNOWN;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLGroupDataBinding.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLGroupDataBinding.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2Node.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2Node.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2Node.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2Node.java Fri Mar 16 22:56:48 2007
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.databinding.xml;
+package org.apache.tuscany.databinding.xml;
import javax.xml.stream.XMLStreamReader;
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2SAX.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2SAX.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2SAX.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2SAX.java Fri Mar 16 22:56:48 2007
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.databinding.xml;
+package org.apache.tuscany.databinding.xml;
import javax.xml.stream.XMLStreamReader;
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2String.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2String.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2String.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReader2String.java Fri Mar 16 22:56:48 2007
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.databinding.xml;
+package org.apache.tuscany.databinding.xml;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
Added: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamSerializer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamSerializer.java?view=auto&rev=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamSerializer.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamSerializer.java Fri Mar 16 22:56:48 2007
@@ -0,0 +1,266 @@
+package org.apache.tuscany.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * The XMLStreamSerializer pulls events from the XMLStreamReader and dumps into the XMLStreamWriter
+ */
+public class XMLStreamSerializer implements XMLStreamConstants {
+ public static final String NAMESPACE_PREFIX = "ns";
+ private static int namespaceSuffix;
+
+ /*
+ * The behavior of the serializer is such that it returns when it encounters the starting element for the second
+ * time. The depth variable tracks the depth of the serilizer and tells it when to return. Note that it is assumed
+ * that this serialization starts on an Element.
+ */
+
+ /**
+ * Field depth
+ */
+ private int depth;
+
+ /**
+ * Generates a unique namespace prefix that is not in the scope of the NamespaceContext
+ *
+ * @param nsCtxt
+ * @return string
+ */
+ private String generateUniquePrefix(NamespaceContext nsCtxt) {
+ String prefix = NAMESPACE_PREFIX + namespaceSuffix++;
+ // null should be returned if the prefix is not bound!
+ while (nsCtxt.getNamespaceURI(prefix) != null) {
+ prefix = NAMESPACE_PREFIX + namespaceSuffix++;
+ }
+
+ return prefix;
+ }
+
+ /**
+ * Method serialize.
+ *
+ * @param node
+ * @param writer
+ * @throws XMLStreamException
+ */
+ public void serialize(XMLStreamReader node, XMLStreamWriter writer) throws XMLStreamException {
+ serializeNode(node, writer);
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeAttributes(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ int count = reader.getAttributeCount();
+ String prefix;
+ String namespaceName;
+ String writerPrefix;
+ for (int i = 0; i < count; i++) {
+ prefix = reader.getAttributePrefix(i);
+ namespaceName = reader.getAttributeNamespace(i);
+ /*
+ * Due to parser implementations returning null as the namespace URI (for the empty namespace) we need to
+ * make sure that we deal with a namespace name that is not null. The best way to work around this issue is
+ * to set the namespace uri to "" if it is null
+ */
+ if (namespaceName == null) {
+ namespaceName = "";
+ }
+
+ writerPrefix = writer.getNamespaceContext().getPrefix(namespaceName);
+
+ if (!"".equals(namespaceName)) {
+ // prefix has already being declared but this particular
+ // attrib has a
+ // no prefix attached. So use the prefix provided by the
+ // writer
+ if (writerPrefix != null && (prefix == null || prefix.equals(""))) {
+ writer.writeAttribute(writerPrefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+
+ // writer prefix is available but different from the
+ // current
+ // prefix of the attrib. We should be decalring the new
+ // prefix
+ // as a namespace declaration
+ } else if (prefix != null && !"".equals(prefix) && !prefix.equals(writerPrefix)) {
+ writer.writeNamespace(prefix, namespaceName);
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+
+ // prefix is null (or empty), but the namespace name is
+ // valid! it has not
+ // being written previously also. So we need to generate
+ // a prefix
+ // here
+ } else if (prefix == null || prefix.equals("")) {
+ prefix = generateUniquePrefix(writer.getNamespaceContext());
+ writer.writeNamespace(prefix, namespaceName);
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+ } else {
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+ }
+ } else {
+ // empty namespace is equal to no namespace!
+ writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
+ }
+
+ }
+ }
+
+ /**
+ * Method serializeCData.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeCData(reader.getText());
+ }
+
+ /**
+ * Method serializeComment.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeComment(reader.getText());
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ String prefix = reader.getPrefix();
+ String nameSpaceName = reader.getNamespaceURI();
+ if (nameSpaceName != null) {
+ String writerPrefix = writer.getPrefix(nameSpaceName);
+ if (writerPrefix != null) {
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ } else {
+ if (prefix != null) {
+ writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName);
+ writer.writeNamespace(prefix, nameSpaceName);
+ writer.setPrefix(prefix, nameSpaceName);
+ } else {
+ // [rfeng] We need to set default NS 1st before calling writeStateElement
+ writer.setDefaultNamespace(nameSpaceName);
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ writer.writeDefaultNamespace(nameSpaceName);
+ }
+ }
+ } else {
+ writer.writeStartElement(reader.getLocalName());
+ }
+
+ // add the namespaces
+ int count = reader.getNamespaceCount();
+ String namespacePrefix;
+ for (int i = 0; i < count; i++) {
+ namespacePrefix = reader.getNamespacePrefix(i);
+ // [rfeng] The following is commented out to allow to default ns
+ // if (namespacePrefix != null && namespacePrefix.length() == 0) {
+ // continue;
+ // }
+
+ serializeNamespace(namespacePrefix, reader.getNamespaceURI(i), writer);
+ }
+
+ // add attributes
+ serializeAttributes(reader, writer);
+
+ }
+
+ /**
+ * Method serializeEndElement.
+ *
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeEndElement();
+ }
+
+ /**
+ * Method serializeNamespace.
+ *
+ * @param prefix
+ * @param uri
+ * @param writer
+ * @throws XMLStreamException
+ */
+ private void serializeNamespace(String prefix, String uri, XMLStreamWriter writer) throws XMLStreamException {
+ String prefix1 = writer.getPrefix(uri);
+ if (prefix1 == null) {
+ writer.writeNamespace(prefix, uri);
+ writer.setPrefix(prefix, uri);
+ }
+ }
+
+ /**
+ * Method serializeNode.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ while (true) {
+ int event = reader.getEventType();
+ if (event == START_ELEMENT) {
+ serializeElement(reader, writer);
+ depth++;
+ } else if (event == ATTRIBUTE) {
+ serializeAttributes(reader, writer);
+ } else if (event == CHARACTERS) {
+ serializeText(reader, writer);
+ } else if (event == COMMENT) {
+ serializeComment(reader, writer);
+ } else if (event == CDATA) {
+ serializeCData(reader, writer);
+ } else if (event == END_ELEMENT) {
+ serializeEndElement(writer);
+ depth--;
+ } else if (event == START_DOCUMENT) {
+ depth++; // if a start document is found then increment
+ writer.writeStartDocument();
+ // the depth
+ } else if (event == END_DOCUMENT) {
+ if (depth != 0) {
+ depth--; // for the end document - reduce the depth
+ }
+ writer.writeEndDocument();
+ }
+ if (depth == 0) {
+ break;
+ }
+ if (reader.hasNext()) {
+ reader.next();
+ } else {
+ break;
+ }
+ }
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeCharacters(reader.getText());
+ }
+}
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamSerializer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamable.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamable.java?view=auto&rev=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamable.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamable.java Fri Mar 16 22:56:48 2007
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.databinding.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * An interface represents data that can be read using StAX streaming
+ *
+ * @version $Rev$ $Date$
+ */
+public interface XMLStreamable {
+ /**
+ * Get the XMLStreamReader for StAX processing
+ *
+ * @param rootElementName the name of the element to be generated
+ * @return Returns a pull parser.
+ */
+ XMLStreamReader getXMLStreamReader(QName rootElementName);
+}
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamable.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStringDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStringDataBinding.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStringDataBinding.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStringDataBinding.java Fri Mar 16 22:56:48 2007
@@ -17,17 +17,35 @@
* under the License.
*/
-package org.apache.tuscany.core.databinding.xml;
+package org.apache.tuscany.databinding.xml;
+
+import java.lang.annotation.Annotation;
import org.apache.tuscany.spi.databinding.extension.DataBindingExtension;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.XMLType;
/**
* A DataBinding for the XML string
+ *
+ * @version $Rev$ $Date$
*/
public class XMLStringDataBinding extends DataBindingExtension {
public static final String NAME = String.class.getName();
-
+ public static final String[] ALIASES = new String[] {"xml.string"};
+
public XMLStringDataBinding() {
- super(NAME, String.class);
+ super(NAME, ALIASES, String.class);
+ }
+
+ @Override
+ public boolean introspect(DataType type, Annotation[] annotations) {
+ if (registry.getDataBinding(type.getDataBinding()) == this) {
+ type.setDataBinding(getName());
+ type.setLogical(XMLType.UNKNOWN);
+ return true;
+ } else {
+ return false;
+ }
}
}
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java Fri Mar 16 22:56:48 2007
@@ -19,6 +19,8 @@
package org.apache.tuscany.spi.databinding;
+import java.lang.annotation.Annotation;
+
import org.apache.tuscany.spi.model.DataType;
/**
@@ -26,23 +28,43 @@
*/
public interface DataBinding {
/**
+ * A special databinding for input message of an operation
+ */
+ String IDL_INPUT = "idl:input";
+ /**
+ * A special databinding for output message of an operation
+ */
+ String IDL_OUTPUT = "idl:output";
+ /**
+ * A special databinding for fault message of an operation
+ */
+ String IDL_FAULT = "idl:fault";
+ /**
* The name of a databinding should be case-insensitive and unique
- *
+ *
* @return The name of the databinding
*/
String getName();
+
+ /**
+ * Get the aliases for the databinding
+ *
+ * @return An array of aliases
+ */
+ String[] getAliases();
/**
- * Introspect a java class or interface to create a DataType model
- *
+ * Introspect and populate information to a DataType model
+ *
* @param javaType The java class or interface to be introspected
- * @return The DataType or null if the java type is not supported by this databinding
+ * @param annotations The java annotations
+ * @return true if the databinding has recognized the given data type
*/
- DataType introspect(Class<?> javaType);
+ boolean introspect(DataType dataType, Annotation[] annotations);
/**
* Introspect the data to figure out the corresponding data type
- *
+ *
* @param value The object to be checked
* @return The DataType or null if the java type is not supported by this databinding
*/
@@ -50,23 +72,28 @@
/**
* Provide a WrapperHandler for this databinding
- *
* @return A wrapper handler which can handle wrapping/wrapping for this databinding
*/
WrapperHandler getWrapperHandler();
/**
* Make a copy of the object for "pass-by-value" semantics
- *
- * @param object object to copy
+ * @param source object to copy
* @return copy of the object passed in as argument
*/
Object copy(Object object);
-
+
/**
* Get the type mapper for simple types
- *
* @return The databinding-specific simple type mapper
*/
SimpleTypeMapper getSimpleTypeMapper();
+
+ /**
+ * Get the handler that can handle exceptions/faults in the
+ * databinding-specific way
+ *
+ * @return An instance of the exception handler
+ */
+ ExceptionHandler getExceptionHandler();
}
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java Fri Mar 16 22:56:48 2007
@@ -18,6 +18,8 @@
*/
package org.apache.tuscany.spi.databinding;
+import java.lang.annotation.Annotation;
+
import org.apache.tuscany.spi.model.DataType;
/**
@@ -50,11 +52,12 @@
/**
* Introspect the java class to figure out what DataType supports it
*
- * @param javaType The java class or interface
+ * @param DataType The initial data type
+ * @param annotations The java annotations
* @return A DataType representing the java type or null if no databinding
* recognizes the java type
*/
- DataType introspectType(Class<?> javaType);
+ boolean introspectType(DataType dataType, Annotation[] annotations);
/**
* Introspect the value to figure out the corresponding DataType
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java Fri Mar 16 22:56:48 2007
@@ -20,7 +20,7 @@
/**
* Data pipe allows a data source pushes data into its sink and pipe the data into its result
- *
+ *
* @param <S> The data binding type of the sink
* @param <R> The data binding type of the result
*/
@@ -29,15 +29,15 @@
/**
* Returns a sink (for example, java.io.OutputStream, java.io.Writer or org.xml.sax.ContentHandler) to receive data
* pushed by the source
- *
+ *
* @return The sink to consume data
*/
S getSink();
/**
* Returns the data populated by the sink
- *
- * @return R the result
+ *
+ * @return
*/
R getResult();
Added: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/ExceptionHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/ExceptionHandler.java?view=auto&rev=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/ExceptionHandler.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/ExceptionHandler.java Fri Mar 16 22:56:48 2007
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.databinding;
+
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * ExceptionHandler provides databinding-specific logic for exception handling
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ExceptionHandler {
+ /**
+ * Create an exception to wrap the fault data
+ *
+ * @param exceptionType The DataType for the exception
+ * @param message The error message
+ * @param faultInfo The databinding-specific fault data
+ * @param cause The protocol-specific error
+ * @return An instance of java exception to represent the fault
+ */
+ Exception createException(DataType<DataType> exceptionType, String message, Object faultInfo, Throwable cause);
+
+ /**
+ * Retrieve the fault info from a java exception
+ *
+ * @param exception The databinding-specific java exception that represents
+ * the fault data
+ * @return The databinding-specific fault data
+ */
+ Object getFaultInfo(Exception exception);
+
+ /**
+ * Introspect an exception class to figure out the fault data type
+ *
+ * @param exceptionDataType The exception class
+ * @return The data type for the fault
+ */
+ DataType<?> getFaultType(DataType exceptionDataType);
+}
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/ExceptionHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/ExceptionHandler.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java Fri Mar 16 22:56:48 2007
@@ -24,35 +24,44 @@
/**
* This interface will be used as a Tuscany system service to perform data mediations
- * <p/>
+ *
* Mediate the data from one type to the other one
+ *
*/
public interface Mediator {
/**
* Mediate the data from the source type to the target type
- *
- * @param source The data to be mediated
+ * @param source The data to be mediated
* @param sourceDataType Data type for the source data
* @param targetDataType Data type for the target data
- * @param context the context for the mediation
- * @return the result of the mediation
+ * @param context
+ * @return
*/
Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map<Class<?>, Object> context);
-
/**
* Mediate the source data into the target which is a sink to receive the data
- *
- * @param source The data to be mediated
- * @param target The sink to receive data
+ * @param source The data to be mediated
+ * @param target The sink to receive data
* @param sourceDataType Data type for the source data
* @param targetDataType Data type for the target data
- * @param context the context for the mediation
*/
- void mediate(Object source,
- Object target,
- DataType sourceDataType,
- DataType targetDataType,
- Map<Class<?>, Object> context);
-
+ void mediate(
+ Object source,
+ Object target,
+ DataType sourceDataType,
+ DataType targetDataType,
+ Map<Class<?>, Object> context);
+
+ /**
+ * Get the DataBinding registry
+ * @return
+ */
+ DataBindingRegistry getDataBindingRegistry();
+
+ /**
+ * Get the Transformer registry
+ * @return
+ */
+ TransformerRegistry getTransformerRegistry();
}
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java Fri Mar 16 22:56:48 2007
@@ -19,7 +19,7 @@
package org.apache.tuscany.spi.databinding;
-import org.apache.tuscany.spi.model.TypeInfo;
+import javax.xml.namespace.QName;
/**
* Type Mapper between XML schema simple data types and java objects
@@ -32,7 +32,7 @@
* @param context The context of the transformation
* @return A java object for the XML value
*/
- Object toJavaObject(TypeInfo simpleType, String value, TransformationContext context);
+ Object toJavaObject(QName simpleType, String value, TransformationContext context);
/**
* Create the XML lexical representation for a java object
* @param simpleType The XSD simple type
@@ -40,5 +40,5 @@
* @param context The context of the transformation
* @return The XML lexical representation
*/
- String toXMLLiteral(TypeInfo simpleType, Object obj, TransformationContext context);
+ String toXMLLiteral(QName simpleType, Object obj, TransformationContext context);
}
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java Fri Mar 16 22:56:48 2007
@@ -24,47 +24,48 @@
/**
* Context for data transformation
+ *
*/
public interface TransformationContext {
/**
* Get the source data type
- *
- * @return the source data type
+ *
+ * @return
*/
DataType getSourceDataType();
/**
* Get the target data type
- *
- * @return the target datatype
+ *
+ * @return
*/
DataType getTargetDataType();
/**
* Set the source data type
- *
- * @param sourceDataType the source data type
+ *
+ * @param sourceDataType
*/
void setSourceDataType(DataType sourceDataType);
/**
* Set the target data type
- *
- * @param targetDataType the target data type
+ *
+ * @param targetDataType
*/
void setTargetDataType(DataType targetDataType);
/**
* Get the classloader
- *
- * @return the classloader
+ *
+ * @return
*/
ClassLoader getClassLoader();
/**
* Get a map of metadata
- *
- * @return the map of metadata
+ *
+ * @return
*/
Map<Class<?>, Object> getMetadata();
Modified: incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java?view=diff&rev=519244&r1=519083&r2=519244
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java (original)
+++ incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java Fri Mar 16 22:56:48 2007
@@ -26,6 +26,8 @@
public class TransformationException extends TuscanyRuntimeException {
private static final long serialVersionUID = 7662385613693006428L;
+ private String sourceDataBinding;
+ private String targetDataBinding;
public TransformationException() {
super();
@@ -41,6 +43,22 @@
public TransformationException(Throwable cause) {
super(cause);
+ }
+
+ public String getSourceDataBinding() {
+ return sourceDataBinding;
+ }
+
+ public void setSourceDataBinding(String sourceDataBinding) {
+ this.sourceDataBinding = sourceDataBinding;
+ }
+
+ public String getTargetDataBinding() {
+ return targetDataBinding;
+ }
+
+ public void setTargetDataBinding(String targetDataBinding) {
+ this.targetDataBinding = targetDataBinding;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org