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 2008/12/10 20:37:27 UTC

svn commit: r725398 [1/4] - in /tuscany/java/sca/modules/common-xml: ./ META-INF/ 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/sca/ src/main/java/org/apach...

Author: rfeng
Date: Wed Dec 10 11:37:25 2008
New Revision: 725398

URL: http://svn.apache.org/viewvc?rev=725398&view=rev
Log:
Add common-xml module to contain xml utilities

Added:
    tuscany/java/sca/modules/common-xml/   (with props)
    tuscany/java/sca/modules/common-xml/META-INF/
    tuscany/java/sca/modules/common-xml/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/common-xml/pom.xml   (with props)
    tuscany/java/sca/modules/common-xml/src/
    tuscany/java/sca/modules/common-xml/src/main/
    tuscany/java/sca/modules/common-xml/src/main/java/
    tuscany/java/sca/modules/common-xml/src/main/java/org/
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/SimpleTypeMapper.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/XSDDataTypeConverter.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/SAX2DOMAdapter.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXMLStreamReader.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXmlNodeImpl.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DelegatingNamespaceContext.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/NameValueArrayStreamReader.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/NameValuePairStreamReader.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/NamedProperty.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/NilElementStreamReader.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/SimpleXmlNodeImpl.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAX2SAXAdapter.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/WrappingXMLStreamReader.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/XMLDocumentStreamReader.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/XMLFragmentStreamReader.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/XMLFragmentStreamReaderImpl.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/XMLStreamSerializer.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/XMLStreamable.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/XmlNode.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/XmlNodeIterator.java   (with props)
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/XmlTreeStreamReaderImpl.java   (with props)
    tuscany/java/sca/modules/common-xml/src/test/
    tuscany/java/sca/modules/common-xml/src/test/java/
    tuscany/java/sca/modules/common-xml/src/test/java/org/
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/stax/
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/stax/StAXHelperTestCase.java   (with props)
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/stax/XmlTreeStreamReaderTestCase.java   (with props)

Propchange: tuscany/java/sca/modules/common-xml/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Dec 10 11:37:25 2008
@@ -0,0 +1,13 @@
+target
+*.iws
+*.ipr
+*.iml
+*.log*
+.project
+.classpath
+junit*.properties
+.settings
+.deployables
+.wtpmodules
+.externalToolBuilders
+maven-eclipse.xml

Added: tuscany/java/sca/modules/common-xml/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/META-INF/MANIFEST.MF?rev=725398&view=auto
==============================================================================
--- tuscany/java/sca/modules/common-xml/META-INF/MANIFEST.MF (added)
+++ tuscany/java/sca/modules/common-xml/META-INF/MANIFEST.MF Wed Dec 10 11:37:25 2008
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Tool: Bnd-0.0.255
+Bundle-Name: Apache Tuscany SCA Common XML
+Created-By: 1.6.0_07 (Sun Microsystems Inc.)
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 1.4
+Bnd-LastModified: 1225397108125
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Core SPI
+Import-Package: javax.xml.namespace,
+ javax.xml.parsers,
+ javax.xml.stream,
+ javax.xml.transform,
+ javax.xml.xpath,
+ org.apache.tuscany.sca.core;version="1.4.0",
+ org.apache.tuscany.sca.extensibility;version="1.4.0"
+Bundle-SymbolicName: org.apache.tuscany.sca.common.xml
+Bundle-DocURL: http://www.apache.org/
+

Added: tuscany/java/sca/modules/common-xml/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/pom.xml?rev=725398&view=auto
==============================================================================
--- tuscany/java/sca/modules/common-xml/pom.xml (added)
+++ tuscany/java/sca/modules/common-xml/pom.xml Wed Dec 10 11:37:25 2008
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * 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.    
+-->
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.tuscany.sca</groupId>
+        <artifactId>tuscany-modules</artifactId>
+        <version>2.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>tuscany-common-xml</artifactId>
+    <name>Apache Tuscany SCA Common XML</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-extensibility</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-stax-api_1.0_spec</artifactId>
+            <version>1.0.1</version>
+        </dependency>
+                
+        <dependency>
+            <groupId>org.codehaus.woodstox</groupId>
+            <artifactId>wstx-asl</artifactId>
+            <version>3.2.4</version>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>stax</groupId>
+                    <artifactId>stax-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>xmlunit</groupId>
+            <artifactId>xmlunit</artifactId>
+            <version>1.2</version>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+</project>

Propchange: tuscany/java/sca/modules/common-xml/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/common-xml/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/SimpleTypeMapper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/SimpleTypeMapper.java?rev=725398&view=auto
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/SimpleTypeMapper.java (added)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/SimpleTypeMapper.java Wed Dec 10 11:37:25 2008
@@ -0,0 +1,210 @@
+/*
+ * 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.sca.common.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Simple type mapper that maps from XSD types to Java Classes and Java Classes to XSD types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimpleTypeMapper extends XSDDataTypeConverter {
+
+    public static final Map<Class<?>, String> JAVA2XML = new HashMap<Class<?>, String>();
+
+    public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
+
+    public static final Map<QName, Class<?>> XML2JAVA = new HashMap<QName, Class<?>>();
+
+    public static final QName XSD_ANY = new QName(URI_2001_SCHEMA_XSD, "any");
+
+    public static final QName XSD_ANYSIMPLETYPE = new QName(URI_2001_SCHEMA_XSD, "anySimpleType");
+
+    public static final QName XSD_ANYTYPE = new QName(URI_2001_SCHEMA_XSD, "anyType");
+
+    public static final QName XSD_ANYURI = new QName(URI_2001_SCHEMA_XSD, "anyURI");
+
+    public static final QName XSD_BASE64 = new QName(URI_2001_SCHEMA_XSD, "base64Binary");
+
+    public static final QName XSD_BOOLEAN = new QName(URI_2001_SCHEMA_XSD, "boolean");
+
+    public static final QName XSD_BYTE = new QName(URI_2001_SCHEMA_XSD, "byte");
+
+    public static final QName XSD_DATE = new QName(URI_2001_SCHEMA_XSD, "date");
+
+    public static final QName XSD_DATETIME = new QName(URI_2001_SCHEMA_XSD, "dateTime");
+
+    public static final QName XSD_DAY = new QName(URI_2001_SCHEMA_XSD, "gDay");
+
+    public static final QName XSD_DECIMAL = new QName(URI_2001_SCHEMA_XSD, "decimal");
+
+    public static final QName XSD_DOUBLE = new QName(URI_2001_SCHEMA_XSD, "double");
+
+    public static final QName XSD_DURATION = new QName(URI_2001_SCHEMA_XSD, "duration");
+
+    public static final QName XSD_ENTITIES = new QName(URI_2001_SCHEMA_XSD, "ENTITIES");
+
+    public static final QName XSD_ENTITY = new QName(URI_2001_SCHEMA_XSD, "ENTITY");
+
+    public static final QName XSD_FLOAT = new QName(URI_2001_SCHEMA_XSD, "float");
+
+    public static final QName XSD_HEXBIN = new QName(URI_2001_SCHEMA_XSD, "hexBinary");
+
+    public static final QName XSD_IDREF = new QName(URI_2001_SCHEMA_XSD, "IDREF");
+
+    public static final QName XSD_IDREFS = new QName(URI_2001_SCHEMA_XSD, "IDREFS");
+
+    public static final QName XSD_INT = new QName(URI_2001_SCHEMA_XSD, "int");
+
+    public static final QName XSD_INTEGER = new QName(URI_2001_SCHEMA_XSD, "integer");
+
+    public static final QName XSD_LONG = new QName(URI_2001_SCHEMA_XSD, "long");
+
+    public static final QName XSD_MONTH = new QName(URI_2001_SCHEMA_XSD, "gMonth");
+
+    public static final QName XSD_MONTHDAY = new QName(URI_2001_SCHEMA_XSD, "gMonthDay");
+
+    public static final QName XSD_NAME = new QName(URI_2001_SCHEMA_XSD, "Name");
+
+    public static final QName XSD_NCNAME = new QName(URI_2001_SCHEMA_XSD, "NCName");
+
+    public static final QName XSD_NEGATIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "negativeInteger");
+
+    public static final QName XSD_NMTOKEN = new QName(URI_2001_SCHEMA_XSD, "NMTOKEN");
+
+    public static final QName XSD_NMTOKENS = new QName(URI_2001_SCHEMA_XSD, "NMTOKENS");
+
+    public static final QName XSD_NONNEGATIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "nonNegativeInteger");
+
+    public static final QName XSD_NONPOSITIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "nonPositiveInteger");
+
+    public static final QName XSD_NORMALIZEDSTRING = new QName(URI_2001_SCHEMA_XSD, "normalizedString");
+
+    public static final QName XSD_NOTATION = new QName(URI_2001_SCHEMA_XSD, "NOTATION");
+
+    public static final QName XSD_POSITIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "positiveInteger");
+
+    public static final QName XSD_QNAME = new QName(URI_2001_SCHEMA_XSD, "QName");
+
+    public static final QName XSD_SHORT = new QName(URI_2001_SCHEMA_XSD, "short");
+
+    public static final QName XSD_STRING = new QName(URI_2001_SCHEMA_XSD, "string");
+
+    public static final QName XSD_TIME = new QName(URI_2001_SCHEMA_XSD, "time");
+
+    public static final QName XSD_TOKEN = new QName(URI_2001_SCHEMA_XSD, "token");
+
+    public static final QName XSD_UNSIGNEDBYTE = new QName(URI_2001_SCHEMA_XSD, "unsignedByte");
+
+    public static final QName XSD_UNSIGNEDINT = new QName(URI_2001_SCHEMA_XSD, "unsignedInt");
+
+    public static final QName XSD_UNSIGNEDLONG = new QName(URI_2001_SCHEMA_XSD, "unsignedLong");
+
+    public static final QName XSD_UNSIGNEDSHORT = new QName(URI_2001_SCHEMA_XSD, "unsignedShort");
+
+    public static final QName XSD_YEAR = new QName(URI_2001_SCHEMA_XSD, "gYear");
+
+    public static final QName XSD_YEARMONTH = new QName(URI_2001_SCHEMA_XSD, "gYearMonth");
+
+    static {
+        JAVA2XML.put(boolean.class, "boolean");
+        JAVA2XML.put(byte.class, "byte");
+        JAVA2XML.put(short.class, "short");
+        JAVA2XML.put(int.class, "int");
+        JAVA2XML.put(long.class, "long");
+        JAVA2XML.put(float.class, "float");
+        JAVA2XML.put(double.class, "double");
+        JAVA2XML.put(Boolean.class, "boolean");
+        JAVA2XML.put(Byte.class, "byte");
+        JAVA2XML.put(Short.class, "short");
+        JAVA2XML.put(Integer.class, "int");
+        JAVA2XML.put(Long.class, "long");
+        JAVA2XML.put(Float.class, "float");
+        JAVA2XML.put(Double.class, "double");
+        JAVA2XML.put(java.lang.String.class, "string");
+        JAVA2XML.put(java.math.BigInteger.class, "integer");
+        JAVA2XML.put(java.math.BigDecimal.class, "decimal");
+        JAVA2XML.put(java.util.Calendar.class, "dateTime");
+        JAVA2XML.put(java.util.Date.class, "dateTime");
+        JAVA2XML.put(javax.xml.namespace.QName.class, "QName");
+        JAVA2XML.put(java.net.URI.class, "string");
+        JAVA2XML.put(javax.xml.datatype.XMLGregorianCalendar.class, "anySimpleType");
+        JAVA2XML.put(javax.xml.datatype.Duration.class, "duration");
+        JAVA2XML.put(java.lang.Object.class, "anyType");
+        JAVA2XML.put(java.awt.Image.class, "base64Binary");
+        JAVA2XML.put(byte[].class, "base64Binary");
+        // java2XSD.put(javax.activation.DataHandler.class, "base64Binary");
+        JAVA2XML.put(javax.xml.transform.Source.class, "base64Binary");
+        JAVA2XML.put(java.util.UUID.class, "string");
+    }
+
+    static {
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "string"), java.lang.String.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "integer"), java.math.BigInteger.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "int"), int.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "long"), long.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "short"), short.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "decimal"), java.math.BigDecimal.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "float"), float.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "double"), double.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "boolean"), boolean.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "byte"), byte.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "QName"), javax.xml.namespace.QName.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "dateTime"), javax.xml.datatype.XMLGregorianCalendar.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "base64Binary"), byte[].class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "hexBinary"), byte[].class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "unsignedInt"), long.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "unsignedShort"), int.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "unsignedByte"), short.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "time"), javax.xml.datatype.XMLGregorianCalendar.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "date"), javax.xml.datatype.XMLGregorianCalendar.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "gDay"), javax.xml.datatype.XMLGregorianCalendar.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "gMonth"), javax.xml.datatype.XMLGregorianCalendar.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "gYear"), javax.xml.datatype.XMLGregorianCalendar.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "gYearMonth"), javax.xml.datatype.XMLGregorianCalendar.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "gMonthDay"), javax.xml.datatype.XMLGregorianCalendar.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "anySimpleType"), java.lang.Object.class); // For elements
+        // XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "anySimpleType"), java.lang.String.class); // For
+        // attributes
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "duration"), javax.xml.datatype.Duration.class);
+        XML2JAVA.put(new QName(URI_2001_SCHEMA_XSD, "NOTATION"), javax.xml.namespace.QName.class);
+    }
+
+    public SimpleTypeMapper() {
+        super();
+    }
+
+    public static Class<?> getJavaType(QName xmlType) {
+        if (xmlType != null && URI_2001_SCHEMA_XSD.equals(xmlType.getNamespaceURI())) {
+            return XML2JAVA.get(xmlType.getLocalPart());
+        } else {
+            return null;
+        }
+    }
+
+    public static QName getXMLType(Class<?> javaType) {
+        return new QName(URI_2001_SCHEMA_XSD, JAVA2XML.get(javaType));
+    }
+
+}

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/SimpleTypeMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/SimpleTypeMapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/XSDDataTypeConverter.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/XSDDataTypeConverter.java?rev=725398&view=auto
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/XSDDataTypeConverter.java (added)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/XSDDataTypeConverter.java Wed Dec 10 11:37:25 2008
@@ -0,0 +1,945 @@
+/*
+ * 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.sca.common.xml;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.ParsePosition;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import javax.xml.XMLConstants;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+/**
+ * Utility class for XSD data type conversions
+ *
+ * @version $Rev$ $Date$
+ */
+public class XSDDataTypeConverter {
+    public static final class Base64Binary {
+        private static final char[] S_BASE64CHAR =
+        {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
+            'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+            'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4',
+            '5', '6', '7', '8', '9', '+', '/'};
+
+        private static final char S_BASE64PAD = '=';
+
+        private static final byte[] S_DECODETABLE = new byte[128];
+
+        static {
+            for (int i = 0; i < S_DECODETABLE.length; i++) {
+                S_DECODETABLE[i] = Byte.MAX_VALUE; // 127
+            }
+            for (int i = 0; i < S_BASE64CHAR.length; i++) {
+                // 0 to 63
+                S_DECODETABLE[S_BASE64CHAR[i]] = (byte) i;
+            }
+        }
+
+        private Base64Binary() {
+        }
+
+        /**
+         * 
+         */
+        public static byte[] decode(char[] data, int off, int len) {
+            char[] ibuf = new char[4];
+            int ibufcount = 0;
+            byte[] obuf = new byte[len / 4 * 3 + 3];
+            int obufcount = 0;
+            for (int i = off; i < off + len; i++) {
+                char ch = data[i];
+                if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+                    ibuf[ibufcount++] = ch;
+                    if (ibufcount == ibuf.length) {
+                        ibufcount = 0;
+                        obufcount += decode0(ibuf, obuf, obufcount);
+                    }
+                }
+            }
+            if (obufcount == obuf.length) {
+                return obuf;
+            }
+            byte[] ret = new byte[obufcount];
+            System.arraycopy(obuf, 0, ret, 0, obufcount);
+            return ret;
+        }
+
+        /**
+         * 
+         */
+        public static void decode(char[] data, int off, int len, OutputStream ostream) throws IOException {
+            char[] ibuf = new char[4];
+            int ibufcount = 0;
+            byte[] obuf = new byte[3];
+            for (int i = off; i < off + len; i++) {
+                char ch = data[i];
+                if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+                    ibuf[ibufcount++] = ch;
+                    if (ibufcount == ibuf.length) {
+                        ibufcount = 0;
+                        int obufcount = decode0(ibuf, obuf, 0);
+                        ostream.write(obuf, 0, obufcount);
+                    }
+                }
+            }
+        }
+
+        /**
+         * 
+         */
+        public static byte[] decode(String data) {
+            char[] ibuf = new char[4];
+            int ibufcount = 0;
+            byte[] obuf = new byte[data.length() / 4 * 3 + 3];
+            int obufcount = 0;
+            for (int i = 0; i < data.length(); i++) {
+                char ch = data.charAt(i);
+                if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+                    ibuf[ibufcount++] = ch;
+                    if (ibufcount == ibuf.length) {
+                        ibufcount = 0;
+                        obufcount += decode0(ibuf, obuf, obufcount);
+                    }
+                }
+            }
+            if (obufcount == obuf.length) {
+                return obuf;
+            }
+            byte[] ret = new byte[obufcount];
+            System.arraycopy(obuf, 0, ret, 0, obufcount);
+            return ret;
+        }
+
+        /**
+         * 
+         */
+        public static void decode(String data, OutputStream ostream) throws IOException {
+            char[] ibuf = new char[4];
+            int ibufcount = 0;
+            byte[] obuf = new byte[3];
+            for (int i = 0; i < data.length(); i++) {
+                char ch = data.charAt(i);
+                if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+                    ibuf[ibufcount++] = ch;
+                    if (ibufcount == ibuf.length) {
+                        ibufcount = 0;
+                        int obufcount = decode0(ibuf, obuf, 0);
+                        ostream.write(obuf, 0, obufcount);
+                    }
+                }
+            }
+        }
+
+        private static int decode0(char[] ibuf, byte[] obuf, int index) {
+            int wp = index;
+            int outlen = 3;
+            if (ibuf[3] == S_BASE64PAD) {
+                outlen = 2;
+            }
+            if (ibuf[2] == S_BASE64PAD) {
+                outlen = 1;
+            }
+            int b0 = S_DECODETABLE[ibuf[0]];
+            int b1 = S_DECODETABLE[ibuf[1]];
+            int b2 = S_DECODETABLE[ibuf[2]];
+            int b3 = S_DECODETABLE[ibuf[3]];
+            switch (outlen) {
+                case 1:
+                    obuf[wp] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+                    return 1;
+                case 2:
+                    obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+                    obuf[wp] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
+                    return 2;
+                case 3:
+                    obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+                    obuf[wp++] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
+                    obuf[wp] = (byte) (b2 << 6 & 0xc0 | b3 & 0x3f);
+                    return 3;
+                default:
+                    throw new IllegalArgumentException("The character sequence is not base64 encoded.");
+            }
+        }
+
+        /**
+         * Returns base64 representation of specified byte array.
+         */
+        public static String encode(byte[] data) {
+            return encode(data, 0, data.length);
+        }
+
+        /**
+         * Returns base64 representation of specified byte array.
+         */
+        public static String encode(byte[] data, int off, int len) {
+            if (len <= 0) {
+                return "";
+            }
+            char[] out = new char[len / 3 * 4 + 4];
+            int rindex = off;
+            int windex = 0;
+            int rest = len - off;
+            while (rest >= 3) {
+                int i =
+                    ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+                        + (data[rindex + 2] & 0xff);
+                out[windex++] = S_BASE64CHAR[i >> 18];
+                out[windex++] = S_BASE64CHAR[(i >> 12) & 0x3f];
+                out[windex++] = S_BASE64CHAR[(i >> 6) & 0x3f];
+                out[windex++] = S_BASE64CHAR[i & 0x3f];
+                rindex += 3;
+                rest -= 3;
+            }
+            if (rest == 1) {
+                int i = data[rindex] & 0xff;
+                out[windex++] = S_BASE64CHAR[i >> 2];
+                out[windex++] = S_BASE64CHAR[(i << 4) & 0x3f];
+                out[windex++] = S_BASE64PAD;
+                out[windex++] = S_BASE64PAD;
+            } else if (rest == 2) {
+                int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+                out[windex++] = S_BASE64CHAR[i >> 10];
+                out[windex++] = S_BASE64CHAR[(i >> 4) & 0x3f];
+                out[windex++] = S_BASE64CHAR[(i << 2) & 0x3f];
+                out[windex++] = S_BASE64PAD;
+            }
+            return new String(out, 0, windex);
+        }
+
+        /**
+         * Outputs base64 representation of the specified byte array to a byte stream.
+         */
+        public static void encode(byte[] data, int off, int len, OutputStream ostream) throws IOException {
+            if (len <= 0) {
+                return;
+            }
+            byte[] out = new byte[4];
+            int rindex = off;
+            int rest = len - off;
+            while (rest >= 3) {
+                int i =
+                    ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+                        + (data[rindex + 2] & 0xff);
+                out[0] = (byte) S_BASE64CHAR[i >> 18];
+                out[1] = (byte) S_BASE64CHAR[(i >> 12) & 0x3f];
+                out[2] = (byte) S_BASE64CHAR[(i >> 6) & 0x3f];
+                out[3] = (byte) S_BASE64CHAR[i & 0x3f];
+                ostream.write(out, 0, 4);
+                rindex += 3;
+                rest -= 3;
+            }
+            if (rest == 1) {
+                int i = data[rindex] & 0xff;
+                out[0] = (byte) S_BASE64CHAR[i >> 2];
+                out[1] = (byte) S_BASE64CHAR[(i << 4) & 0x3f];
+                out[2] = (byte) S_BASE64PAD;
+                out[3] = (byte) S_BASE64PAD;
+                ostream.write(out, 0, 4);
+            } else if (rest == 2) {
+                int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+                out[0] = (byte) S_BASE64CHAR[i >> 10];
+                out[1] = (byte) S_BASE64CHAR[(i >> 4) & 0x3f];
+                out[2] = (byte) S_BASE64CHAR[(i << 2) & 0x3f];
+                out[3] = (byte) S_BASE64PAD;
+                ostream.write(out, 0, 4);
+            }
+        }
+
+        /**
+         * Outputs base64 representation of the specified byte array to a character stream.
+         */
+        public static void encode(byte[] data, int off, int len, Writer writer) throws IOException {
+            if (len <= 0) {
+                return;
+            }
+            char[] out = new char[4];
+            int rindex = off;
+            int rest = len - off;
+            int output = 0;
+            while (rest >= 3) {
+                int i =
+                    ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+                        + (data[rindex + 2] & 0xff);
+                out[0] = S_BASE64CHAR[i >> 18];
+                out[1] = S_BASE64CHAR[(i >> 12) & 0x3f];
+                out[2] = S_BASE64CHAR[(i >> 6) & 0x3f];
+                out[3] = S_BASE64CHAR[i & 0x3f];
+                writer.write(out, 0, 4);
+                rindex += 3;
+                rest -= 3;
+                output += 4;
+                if (output % 76 == 0) {
+                    writer.write("\n");
+                }
+            }
+            if (rest == 1) {
+                int i = data[rindex] & 0xff;
+                out[0] = S_BASE64CHAR[i >> 2];
+                out[1] = S_BASE64CHAR[(i << 4) & 0x3f];
+                out[2] = S_BASE64PAD;
+                out[3] = S_BASE64PAD;
+                writer.write(out, 0, 4);
+            } else if (rest == 2) {
+                int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+                out[0] = S_BASE64CHAR[i >> 10];
+                out[1] = S_BASE64CHAR[(i >> 4) & 0x3f];
+                out[2] = S_BASE64CHAR[(i << 2) & 0x3f];
+                out[3] = S_BASE64PAD;
+                writer.write(out, 0, 4);
+            }
+        }
+    }
+
+    /**
+     * <p/>
+     * Utility class for xs:hexbinary. </p>
+     */
+    public static final class HexBinary {
+        private HexBinary() {
+        }
+
+        /**
+         * Converts the string <code>pValue</code> into an array of hex bytes.
+         */
+        public static byte[] decode(String pValue) {
+            if ((pValue.length() % 2) != 0) {
+                throw new IllegalArgumentException("A HexBinary string must have even length.");
+            }
+            byte[] result = new byte[pValue.length() / 2];
+            int j = 0;
+            int i = 0;
+            while (i < pValue.length()) {
+                byte b;
+                char c = pValue.charAt(i++);
+                char d = pValue.charAt(i++);
+                if (c >= '0' && c <= '9') {
+                    b = (byte) ((c - '0') << 4);
+                } else if (c >= 'A' && c <= 'F') {
+                    b = (byte) ((c - 'A' + 10) << 4);
+                } else if (c >= 'a' && c <= 'f') {
+                    b = (byte) ((c - 'a' + 10) << 4);
+                } else {
+                    throw new IllegalArgumentException("Invalid hex digit: " + c);
+                }
+                if (d >= '0' && d <= '9') {
+                    b += (byte) (d - '0');
+                } else if (d >= 'A' && d <= 'F') {
+                    b += (byte) (d - 'A' + 10);
+                } else if (d >= 'a' && d <= 'f') {
+                    b += (byte) (d - 'a' + 10);
+                } else {
+                    throw new IllegalArgumentException("Invalid hex digit: " + d);
+                }
+                result[j++] = b;
+            }
+            return result;
+        }
+
+        /**
+         * Converts the byte array <code>pHexBinary</code> into a string.
+         */
+        public static String encode(byte[] pHexBinary) {
+            StringBuffer result = new StringBuffer();
+            for (int i = 0; i < pHexBinary.length; i++) {
+                byte b = pHexBinary[i];
+                byte c = (byte) ((b & 0xf0) >> 4);
+                if (c <= 9) {
+                    result.append((char) ('0' + c));
+                } else {
+                    result.append((char) ('A' + c - 10));
+                }
+                c = (byte) (b & 0x0f);
+                if (c <= 9) {
+                    result.append((char) ('0' + c));
+                } else {
+                    result.append((char) ('A' + c - 10));
+                }
+            }
+            return result.toString();
+        }
+
+        /**
+         * Creates a clone of the given byte array.
+         */
+        public static byte[] getClone(byte[] pHexBinary) {
+            byte[] result = new byte[pHexBinary.length];
+            System.arraycopy(pHexBinary, 0, result, 0, pHexBinary.length);
+            return result;
+        }
+    }
+
+    public class XSDDateFormat extends XSDDateTimeFormat {
+        private static final long serialVersionUID = -1629412916827246627L;
+
+        /**
+         * Creates a new instance.
+         */
+        public XSDDateFormat() {
+            super(true, false);
+        }
+    }
+
+    /**
+     * <p/>
+     * An instance of {@link java.text.Format}, which may be used to parse and format <code>xs:dateTime</code> values.
+     * </p>
+     */
+    public static class XSDDateTimeFormat extends Format {
+        private static final long serialVersionUID = -1148332471737068969L;
+
+        final boolean parseDate;
+
+        final boolean parseTime;
+
+        /**
+         * Creates a new instance.
+         */
+        public XSDDateTimeFormat() {
+            this(true, true);
+        }
+
+        XSDDateTimeFormat(boolean pParseDate, boolean pParseTime) {
+            parseDate = pParseDate;
+            parseTime = pParseTime;
+        }
+
+        private void append(StringBuffer pBuffer, int pNum, int pMinLen) {
+            String s = Integer.toString(pNum);
+            for (int i = s.length(); i < pMinLen; i++) {
+                pBuffer.append('0');
+            }
+            pBuffer.append(s);
+        }
+
+        @Override
+        public StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos) {
+            assert pCalendar != null : "The Calendar argument must not be null.";
+            assert pBuffer != null : "The StringBuffer argument must not be null.";
+            assert pPos != null : "The FieldPosition argument must not be null.";
+
+            Calendar cal = (Calendar) pCalendar;
+            if (parseDate) {
+                int year = cal.get(Calendar.YEAR);
+                if (year < 0) {
+                    pBuffer.append('-');
+                    year = -year;
+                }
+                append(pBuffer, year, 4);
+                pBuffer.append('-');
+                append(pBuffer, cal.get(Calendar.MONTH) + 1, 2);
+                pBuffer.append('-');
+                append(pBuffer, cal.get(Calendar.DAY_OF_MONTH), 2);
+                if (parseTime) {
+                    pBuffer.append('T');
+                }
+            }
+            if (parseTime) {
+                append(pBuffer, cal.get(Calendar.HOUR_OF_DAY), 2);
+                pBuffer.append(':');
+                append(pBuffer, cal.get(Calendar.MINUTE), 2);
+                pBuffer.append(':');
+                append(pBuffer, cal.get(Calendar.SECOND), 2);
+                int millis = cal.get(Calendar.MILLISECOND);
+                if (millis > 0) {
+                    pBuffer.append('.');
+                    append(pBuffer, millis, 3);
+                }
+            }
+            TimeZone tz = cal.getTimeZone();
+            // JDK 1.4: int offset = tz.getOffset(cal.getTimeInMillis());
+            int offset = cal.get(Calendar.ZONE_OFFSET);
+            if (tz.inDaylightTime(cal.getTime())) {
+                offset += cal.get(Calendar.DST_OFFSET);
+            }
+            if (offset == 0) {
+                pBuffer.append('Z');
+            } else {
+                if (offset < 0) {
+                    pBuffer.append('-');
+                    offset = -offset;
+                } else {
+                    pBuffer.append('+');
+                }
+                int minutes = offset / (60 * 1000);
+                int hours = minutes / 60;
+                minutes -= hours * 60;
+                append(pBuffer, hours, 2);
+                pBuffer.append(':');
+                append(pBuffer, minutes, 2);
+            }
+            return pBuffer;
+        }
+
+        private int parseInt(String pString, int offset, StringBuffer pDigits) {
+            int length = pString.length();
+            int pOffset = offset;
+            pDigits.setLength(0);
+            while (pOffset < length) {
+                char c = pString.charAt(pOffset);
+                if (Character.isDigit(c)) {
+                    pDigits.append(c);
+                    ++pOffset;
+                } else {
+                    break;
+                }
+            }
+            return pOffset;
+        }
+
+        @Override
+        public Object parseObject(String pString, ParsePosition pParsePosition) {
+            assert pString != null : "The String argument must not be null.";
+            assert pParsePosition != null : "The ParsePosition argument must not be null.";
+            int offset = pParsePosition.getIndex();
+            int length = pString.length();
+
+            boolean isMinus = false;
+            StringBuffer digits = new StringBuffer();
+            int year = 0;
+            int month = 0;
+            int mday = 0;
+            if (parseDate) {
+                // Sign
+                if (offset < length) {
+                    char c = pString.charAt(offset);
+                    if (c == '+') {
+                        ++offset;
+                    } else if (c == '-') {
+                        ++offset;
+                        isMinus = true;
+                    }
+                }
+
+                offset = parseInt(pString, offset, digits);
+                if (digits.length() < 4) {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+                year = Integer.parseInt(digits.toString());
+
+                if (offset < length && pString.charAt(offset) == '-') {
+                    ++offset;
+                } else {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+
+                offset = parseInt(pString, offset, digits);
+                if (digits.length() != 2) {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+                month = Integer.parseInt(digits.toString());
+
+                if (offset < length && pString.charAt(offset) == '-') {
+                    ++offset;
+                } else {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+
+                offset = parseInt(pString, offset, digits);
+                if (digits.length() != 2) {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+                mday = Integer.parseInt(digits.toString());
+
+                if (parseTime) {
+                    if (offset < length && pString.charAt(offset) == 'T') {
+                        ++offset;
+                    } else {
+                        pParsePosition.setErrorIndex(offset);
+                        return null;
+                    }
+                }
+            } else {
+                year = month = mday = 0;
+            }
+
+            int hour = 0;
+            int minute = 0;
+            int second = 0;
+            int millis = 0;
+            if (parseTime) {
+                offset = parseInt(pString, offset, digits);
+                if (digits.length() != 2) {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+                hour = Integer.parseInt(digits.toString());
+
+                if (offset < length && pString.charAt(offset) == ':') {
+                    ++offset;
+                } else {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+
+                offset = parseInt(pString, offset, digits);
+                if (digits.length() != 2) {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+                minute = Integer.parseInt(digits.toString());
+
+                if (offset < length && pString.charAt(offset) == ':') {
+                    ++offset;
+                } else {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+
+                offset = parseInt(pString, offset, digits);
+                if (digits.length() != 2) {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+                second = Integer.parseInt(digits.toString());
+
+                if (offset < length && pString.charAt(offset) == '.') {
+                    ++offset;
+                    offset = parseInt(pString, offset, digits);
+                    if (digits.length() > 0) {
+                        millis = Integer.parseInt(digits.toString());
+                    } else {
+                        millis = 0;
+                    }
+                } else {
+                    millis = 0;
+                }
+            } else {
+                hour = minute = second = millis = 0;
+            }
+
+            digits.setLength(0);
+            digits.append("GMT");
+            if (offset < length) {
+                char c = pString.charAt(offset);
+                if (c == 'Z') {
+                    // Ignore UTC, it is the default
+                    ++offset;
+                } else if (c == '+' || c == '-') {
+                    digits.append(c);
+                    ++offset;
+                    for (int i = 0; i < 5; i++) {
+                        if (offset >= length) {
+                            pParsePosition.setErrorIndex(offset);
+                            return null;
+                        }
+                        c = pString.charAt(offset);
+                        if ((i != 2 && Character.isDigit(c)) || (i == 2 && c == ':')) {
+                            digits.append(c);
+                        } else {
+                            pParsePosition.setErrorIndex(offset);
+                            return null;
+                        }
+                        ++offset;
+                    }
+                }
+            }
+
+            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(digits.toString()));
+            cal.set(isMinus ? -year : year, parseDate ? month - 1 : month, mday, hour, minute, second);
+            cal.set(Calendar.MILLISECOND, millis);
+            pParsePosition.setIndex(offset);
+            return cal;
+        }
+    }
+
+    public static class XSDTimeFormat extends XSDDateTimeFormat {
+        private static final long serialVersionUID = 1346506860724640517L;
+
+        /**
+         * Creates a new instance.
+         */
+        public XSDTimeFormat() {
+            super(false, true);
+        }
+    }
+
+    private static final long MAX_UNSIGNED_INT = (((long) Integer.MAX_VALUE) * 2) + 1;
+
+    private static final int MAX_UNSIGNED_SHORT = Short.MAX_VALUE * 2 + 1;
+
+    public String parseAnySimpleType(String value) {
+        return value;
+    }
+
+    public byte[] parseBase64Binary(String value) {
+        return Base64Binary.decode(value);
+    }
+
+    public boolean parseBoolean(String value) {
+        return Boolean.valueOf(value).booleanValue();
+    }
+
+    public byte parseByte(String value) {
+        return Byte.parseByte(value);
+    }
+
+    public Calendar parseDate(String value) {
+        XSDDateFormat format = new XSDDateFormat();
+        ParsePosition pos = new ParsePosition(0);
+        Calendar cal = (Calendar) format.parseObject(value, pos);
+        if (cal == null) {
+            throw new IllegalArgumentException("Failed to parse date " + value + " at:"
+                + value.substring(pos.getErrorIndex()));
+        }
+        return cal;
+    }
+
+    public Calendar parseDateTime(String value) {
+        XSDDateTimeFormat format = new XSDDateTimeFormat();
+        ParsePosition pos = new ParsePosition(0);
+        Calendar cal = (Calendar) format.parseObject(value, pos);
+        if (cal == null) {
+            throw new IllegalArgumentException("Failed to parse dateTime " + value + " at:"
+                + value.substring(pos.getErrorIndex()));
+        }
+        return cal;
+    }
+
+    public BigDecimal parseDecimal(String value) {
+        return new BigDecimal(value);
+    }
+
+    public double parseDouble(String value) {
+        if ("INF".equals(value)) {
+            return Double.POSITIVE_INFINITY;
+        } else if ("-INF".equals(value)) {
+            return Double.NEGATIVE_INFINITY;
+        } else if ("NaN".equals(value)) {
+            return Double.NaN;
+        } else {
+            return Double.parseDouble(value);
+        }
+    }
+
+    public Duration parseDuration(String pDuration) {
+        try {
+            return DatatypeFactory.newInstance().newDuration(pDuration);
+        } catch (DatatypeConfigurationException e) {
+            throw new IllegalArgumentException(e);
+        }
+    }
+
+    public float parseFloat(String value) {
+        if ("INF".equals(value)) {
+            return Float.POSITIVE_INFINITY;
+        } else if ("-INF".equals(value)) {
+            return Float.NEGATIVE_INFINITY;
+        } else if ("NaN".equals(value)) {
+            return Float.NaN;
+        } else {
+            return Float.parseFloat(value);
+        }
+    }
+
+    public byte[] parseHexBinary(String value) {
+        return HexBinary.decode(value);
+    }
+
+    public int parseInt(String value) {
+        return Integer.parseInt(value);
+    }
+
+    public BigInteger parseInteger(String value) {
+        return new BigInteger(value);
+    }
+
+    public long parseLong(String value) {
+        return Long.parseLong(value);
+    }
+
+    public QName parseQName(String value, NamespaceContext context) {
+        int offset = value.indexOf(':');
+        String uri;
+        String localName;
+        switch (offset) {
+            case -1:
+                localName = value;
+                uri = context.getNamespaceURI("");
+                if (uri == null) {
+                    // Should not happen, indicates an error in the
+                    // NamespaceContext
+                    // implementation
+                    throw new IllegalArgumentException("The default prefix is not bound.");
+                }
+                break;
+            case 0:
+                throw new IllegalArgumentException("Default prefix must be indicated by not using a colon: "
+                    + value);
+            default:
+                String prefix = value.substring(0, offset);
+                localName = value.substring(offset + 1);
+                uri = context.getNamespaceURI(prefix);
+                if (uri == null) {
+                    throw new IllegalArgumentException("The prefix " + prefix + " is not bound.");
+                }
+        }
+        return new QName(uri, localName);
+    }
+
+    public short parseShort(String value) {
+        return Short.parseShort(value);
+    }
+
+    public String parseString(String value) {
+        return value;
+    }
+
+    public Calendar parseTime(String value) {
+        XSDTimeFormat format = new XSDTimeFormat();
+        ParsePosition pos = new ParsePosition(0);
+        Calendar cal = (Calendar) format.parseObject(value, pos);
+        if (cal == null) {
+            throw new IllegalArgumentException("Failed to parse time " + value + " at:"
+                + value.substring(pos.getErrorIndex()));
+        }
+        return cal;
+    }
+
+    public long parseUnsignedInt(String value) {
+        long l = Long.parseLong(value);
+        if (l < 0) {
+            throw new IllegalArgumentException("Failed to parse UnsignedInt " + value
+                + ": result is negative");
+        }
+        if (l > MAX_UNSIGNED_INT) {
+            throw new IllegalArgumentException("Failed to parse UnsignedInt " + value
+                + ": result exceeds maximum value " + MAX_UNSIGNED_INT);
+        }
+        return l;
+    }
+
+    public int parseUnsignedShort(String value) {
+        int i = Integer.parseInt(value);
+        if (i < 0) {
+            throw new IllegalArgumentException("Failed to parse UnsignedShort " + value
+                + ": result is negative");
+        }
+        if (i > MAX_UNSIGNED_SHORT) {
+            throw new IllegalArgumentException("Failed to parse UnsignedShort " + value
+                + ": result exceeds maximum value " + MAX_UNSIGNED_SHORT);
+        }
+        return i;
+    }
+
+    public String printAnySimpleType(String value) {
+        return value;
+    }
+
+    public String printBase64Binary(byte[] value) {
+        return Base64Binary.encode(value);
+    }
+
+    public String printBoolean(boolean value) {
+        return (value ? Boolean.TRUE : Boolean.FALSE).toString();
+    }
+
+    public String printByte(byte value) {
+        return Byte.toString(value);
+    }
+
+    public String printDate(Calendar value) {
+        return new XSDDateFormat().format(value);
+    }
+
+    public String printDateTime(Calendar value) {
+        return new XSDDateTimeFormat().format(value);
+    }
+
+    public String printDecimal(BigDecimal value) {
+        return value.toString();
+    }
+
+    public String printDouble(double value) {
+        return Double.toString(value);
+    }
+
+    public String printDuration(Duration pDuration) {
+        return pDuration.toString();
+    }
+
+    public String printFloat(float value) {
+        return Float.toString(value);
+    }
+
+    public String printHexBinary(byte[] value) {
+        return HexBinary.encode(value);
+    }
+
+    public String printInt(int value) {
+        return Integer.toString(value);
+    }
+
+    public String printInteger(BigInteger value) {
+        return value.toString();
+    }
+
+    public String printLong(long value) {
+        return Long.toString(value);
+    }
+
+    public String printQName(QName value, NamespaceContext context) {
+        String prefix = context.getPrefix(value.getNamespaceURI());
+        if (prefix == null) {
+            throw new IllegalArgumentException("The namespace URI " + value.getNamespaceURI()
+                + " is not bound.");
+        } else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
+            return value.getLocalPart();
+        } else {
+            return prefix + ":" + value.getLocalPart();
+        }
+    }
+
+    public String printShort(short value) {
+        return Short.toString(value);
+    }
+
+    public String printString(String value) {
+        return value;
+    }
+
+    public String printTime(Calendar value) {
+        return new XSDTimeFormat().format(value);
+    }
+
+    public String printUnsignedInt(long value) {
+        return Long.toString(value);
+    }
+
+    public String printUnsignedShort(int value) {
+        return Integer.toString(value);
+    }
+}

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/XSDDataTypeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/XSDDataTypeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java?rev=725398&view=auto
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java (added)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java Wed Dec 10 11:37:25 2008
@@ -0,0 +1,115 @@
+/*
+ * 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.sca.common.xml.dom;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Helper for DOM
+ *
+ * @version $Rev$ $Date$
+ */
+public final class DOMHelper {
+    private static DocumentBuilderFactory FACTORY;
+
+    private DOMHelper() {
+    }
+
+    public static Document newDocument() throws ParserConfigurationException {
+        return newDocumentBuilder().newDocument();
+    }
+
+    public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
+        init();
+        return FACTORY.newDocumentBuilder();
+    }
+
+    /**
+     * 
+     */
+    private static synchronized void init() {
+        if (FACTORY == null) {
+            FACTORY = DocumentBuilderFactory.newInstance();
+            FACTORY.setNamespaceAware(true);
+        }
+    }
+
+    public static QName getQName(Node node) {
+        String ns = node.getNamespaceURI();
+        if (ns == null) {
+            ns = "";
+        }
+        // node.getLocalName() will return null if it is created using DOM Level
+        // 1 method
+        // such as createElement()
+        return new QName(ns, node.getNodeName());
+    }
+
+    public static Element createElement(Document document, QName name) {
+        String prefix = name.getPrefix();
+        String qname =
+            (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name.getLocalPart();
+        return document.createElementNS(name.getNamespaceURI(), qname);
+    }
+
+    /**
+     * Wrap an element as a DOM document
+     * @param node
+     * @return
+     */
+    public static Document promote(Node node) {
+        if (node instanceof Document) {
+            return (Document)node;
+        }
+        Element element = (Element)node;
+        Document doc = element.getOwnerDocument();
+        if (doc.getDocumentElement() == element) {
+            return doc;
+        }
+        doc = (Document)element.getOwnerDocument().cloneNode(false);
+        Element schema = (Element)doc.importNode(element, true);
+        doc.appendChild(schema);
+        Node parent = element.getParentNode();
+        while (parent instanceof Element) {
+            Element root = (Element)parent;
+            NamedNodeMap nodeMap = root.getAttributes();
+            for (int i = 0; i < nodeMap.getLength(); i++) {
+                Attr attr = (Attr)nodeMap.item(i);
+                String name = attr.getName();
+                if ("xmlns".equals(name) || name.startsWith("xmlns:")) {
+                    if (schema.getAttributeNode(name) == null) {
+                        schema.setAttributeNodeNS((Attr)doc.importNode(attr, true));
+                    }
+                }
+            }
+            parent = parent.getParentNode();
+        }
+        return doc;
+    }
+
+}

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/SAX2DOMAdapter.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/SAX2DOMAdapter.java?rev=725398&view=auto
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/SAX2DOMAdapter.java (added)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/SAX2DOMAdapter.java Wed Dec 10 11:37:25 2008
@@ -0,0 +1,245 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.sca.common.xml.dom;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * SAX2DOM adapter
+ *
+ * @version $Rev$ $Date$
+ */
+public class SAX2DOMAdapter implements ContentHandler, LexicalHandler {
+    public static final String EMPTYSTRING = "";
+    public static final String XML_PREFIX = "xml";
+    public static final String XMLNS_PREFIX = "xmlns";
+    public static final String XMLNS_STRING = "xmlns:";
+    public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
+
+    private Node root;
+
+    private Document document;
+
+    private Node nextSibling;
+
+    private Stack<Node> nodeStk = new Stack<Node>();
+
+    private List<String> namespaceDecls;
+
+    private Node lastSibling;
+
+    public SAX2DOMAdapter() throws ParserConfigurationException {
+        this.document = DOMHelper.newDocument();
+        this.root = document;
+    }
+
+    public SAX2DOMAdapter(Node root, Node nextSibling) throws ParserConfigurationException {
+        this.root = root;
+        if (root instanceof Document) {
+            this.document = (Document)root;
+        } else if (root != null) {
+            this.document = root.getOwnerDocument();
+        } else {
+            this.document = DOMHelper.newDocument();
+            this.root = document;
+        }
+
+        this.nextSibling = nextSibling;
+    }
+
+    public SAX2DOMAdapter(Node root) throws ParserConfigurationException {
+        this(root, null);
+    }
+
+    public Node getDOM() {
+        return root;
+    }
+
+    public void characters(char[] ch, int start, int length) {
+        final Node last = nodeStk.peek();
+
+        // No text nodes can be children of root (DOM006 exception)
+        if (last != document) {
+            final String text = new String(ch, start, length);
+            if (lastSibling != null && lastSibling.getNodeType() == Node.TEXT_NODE) {
+                ((Text)lastSibling).appendData(text);
+            } else if (last == root && nextSibling != null) {
+                lastSibling = last.insertBefore(document.createTextNode(text), nextSibling);
+            } else {
+                lastSibling = last.appendChild(document.createTextNode(text));
+            }
+
+        }
+    }
+
+    public void startDocument() {
+        nodeStk.push(root);
+    }
+
+    public void endDocument() {
+        nodeStk.pop();
+    }
+
+    public void startElement(String namespace, String localName, String qName, Attributes attrs) {
+        final Element tmp = document.createElementNS(namespace, qName);
+
+        // Add namespace declarations first
+        if (namespaceDecls != null) {
+            final int nDecls = namespaceDecls.size();
+            for (int i = 0; i < nDecls; i++) {
+                final String prefix = namespaceDecls.get(i++);
+
+                if (prefix == null || prefix.equals(EMPTYSTRING)) {
+                    tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, namespaceDecls.get(i));
+                } else {
+                    tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, namespaceDecls.get(i));
+                }
+            }
+            namespaceDecls.clear();
+        }
+
+        // Add attributes to element
+        final int nattrs = attrs.getLength();
+        for (int i = 0; i < nattrs; i++) {
+            if (attrs.getLocalName(i) == null) {
+                tmp.setAttribute(attrs.getQName(i), attrs.getValue(i));
+            } else {
+                tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i));
+            }
+        }
+
+        // Append this new node onto current stack node
+        Node last = nodeStk.peek();
+
+        // If the SAX2DOM is created with a non-null next sibling node,
+        // insert the result nodes before the next sibling under the root.
+        if (last == root && nextSibling != null) {
+            last.insertBefore(tmp, nextSibling);
+        } else {
+            last.appendChild(tmp);
+        }
+
+        // Push this node onto stack
+        nodeStk.push(tmp);
+        lastSibling = null;
+    }
+
+    public void endElement(String namespace, String localName, String qName) {
+        nodeStk.pop();
+        lastSibling = null;
+    }
+
+    public void startPrefixMapping(String prefix, String uri) {
+        if (namespaceDecls == null) {
+            namespaceDecls = new ArrayList<String>(2);
+        }
+        namespaceDecls.add(prefix);
+        namespaceDecls.add(uri);
+    }
+
+    public void endPrefixMapping(String prefix) {
+        // do nothing
+    }
+
+    /**
+     * This class is only used internally so this method should never be called.
+     */
+    public void ignorableWhitespace(char[] ch, int start, int length) {
+    }
+
+    /**
+     * adds processing instruction node to DOM.
+     */
+    public void processingInstruction(String target, String data) {
+        final Node last = nodeStk.peek();
+        ProcessingInstruction pi = document.createProcessingInstruction(target, data);
+        if (pi != null) {
+            if (last == root && nextSibling != null) {
+                last.insertBefore(pi, nextSibling);
+            } else {
+                last.appendChild(pi);
+            }
+
+            lastSibling = pi;
+        }
+    }
+
+    /**
+     * This class is only used internally so this method should never be called.
+     */
+    public void setDocumentLocator(Locator locator) {
+    }
+
+    /**
+     * This class is only used internally so this method should never be called.
+     */
+    public void skippedEntity(String name) {
+    }
+
+    /**
+     * Lexical Handler method to create comment node in DOM tree.
+     */
+    public void comment(char[] ch, int start, int length) {
+        final Node last = nodeStk.peek();
+        Comment comment = document.createComment(new String(ch, start, length));
+        if (comment != null) {
+            if (last == root && nextSibling != null) {
+                last.insertBefore(comment, nextSibling);
+            } else {
+                last.appendChild(comment);
+            }
+
+            lastSibling = comment;
+        }
+    }
+
+    // Lexical Handler methods- not implemented
+    public void startCDATA() {
+    }
+
+    public void endCDATA() {
+    }
+
+    public void startEntity(java.lang.String name) {
+    }
+
+    public void endDTD() {
+    }
+
+    public void endEntity(String name) {
+    }
+
+    public void startDTD(String name, String publicId, String systemId) throws SAXException {
+    }
+
+}

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/SAX2DOMAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/SAX2DOMAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXMLStreamReader.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXMLStreamReader.java?rev=725398&view=auto
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXMLStreamReader.java (added)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXMLStreamReader.java Wed Dec 10 11:37:25 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.sca.common.xml.stax;
+
+import org.w3c.dom.Node;
+
+public class DOMXMLStreamReader extends XmlTreeStreamReaderImpl {
+
+    public DOMXMLStreamReader(Node node) {
+        super(new DOMXmlNodeImpl(node));
+        switch (node.getNodeType()) {
+            case Node.DOCUMENT_NODE:
+                break;
+            case Node.ELEMENT_NODE:
+                break;
+            default:
+                throw new IllegalArgumentException("Illegal node type: " + node);
+        }
+    }
+}

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXMLStreamReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXMLStreamReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXmlNodeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXmlNodeImpl.java?rev=725398&view=auto
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXmlNodeImpl.java (added)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXmlNodeImpl.java Wed Dec 10 11:37:25 2008
@@ -0,0 +1,156 @@
+/*
+ * 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.sca.common.xml.stax;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DOMXmlNodeImpl implements XmlNode {
+    private Node node;
+    private Map<String, String> namespaces;
+    private Type type;
+
+    /**
+     * @param element
+     */
+    public DOMXmlNodeImpl(Node element) {
+        super();
+        if (element.getNodeType() == Node.DOCUMENT_NODE) {
+            this.node = ((Document)element).getDocumentElement();
+        } else {
+            this.node = element;
+        }
+        switch (node.getNodeType()) {
+            case Node.CDATA_SECTION_NODE:
+                this.type = Type.CHARACTERS;
+                break;
+            case Node.ELEMENT_NODE:
+                this.type = Type.ELEMENT;
+                break;
+            case Node.TEXT_NODE:
+                this.type = Type.CHARACTERS;
+                break;
+        }
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.common.xml.stax.databinding.xml.XmlNode#attributes()
+     */
+    public List<XmlNode> attributes() {
+        if (type != Type.ELEMENT) {
+            return null;
+        }
+        NamedNodeMap attrs = node.getAttributes();
+        List<XmlNode> xmlAttrs = new ArrayList<XmlNode>();
+        for (int i = 0; i < attrs.getLength(); i++) {
+            Attr attr = (Attr)attrs.item(i);
+            if (!attr.getName().equals("xmlns") && !attr.getName().startsWith("xmlns:")) {
+                xmlAttrs.add(new SimpleXmlNodeImpl(getQName(attr), attr.getValue(), XmlNode.Type.ATTRIBUTE));
+            }
+        }
+        return xmlAttrs;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.common.xml.stax.databinding.xml.XmlNode#children()
+     */
+    public Iterator<XmlNode> children() {
+        if (type != Type.ELEMENT) {
+            return null;
+        }
+        NodeList nodes = node.getChildNodes();
+        List<XmlNode> xmlNodes = new ArrayList<XmlNode>();
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Node child = (Node)nodes.item(i);
+            int nodeType = child.getNodeType();
+            if (nodeType == Node.ELEMENT_NODE || nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) {
+                xmlNodes.add(new DOMXmlNodeImpl(child));
+            }
+        }
+        return xmlNodes.iterator();
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.common.xml.stax.databinding.xml.XmlNode#getName()
+     */
+    public QName getName() {
+        return getQName(node);
+    }
+
+    private static QName getQName(Node node) {
+        int type = node.getNodeType();
+        if (type == Node.ELEMENT_NODE || type == Node.ATTRIBUTE_NODE) {
+            String ns = node.getNamespaceURI();
+            String prefix = node.getPrefix();
+            String localName = node.getLocalName();
+            return new QName(ns == null ? "" : ns, localName, prefix == null ? "" : prefix);
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.common.xml.stax.databinding.xml.XmlNode#getValue()
+     */
+    public String getValue() {
+        return node.getNodeValue();
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.common.xml.stax.databinding.xml.XmlNode#namespaces()
+     */
+    public Map<String, String> namespaces() {
+        if (type != Type.ELEMENT) {
+            return null;
+        }
+        if (namespaces == null) {
+            namespaces = new HashMap<String, String>();
+            NamedNodeMap attrs = node.getAttributes();
+            for (int i = 0; i < attrs.getLength(); i++) {
+                Attr attr = (Attr)attrs.item(i);
+                if ("xmlns".equals(attr.getPrefix())) {
+                    namespaces.put(attr.getLocalName(), attr.getValue());
+                }
+                if ("xmlns".equals(attr.getName())) {
+                    namespaces.put("", attr.getValue());
+                }
+            }
+        }
+        return namespaces;
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+}

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXmlNodeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/DOMXmlNodeImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date