You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by am...@apache.org on 2007/02/14 13:31:30 UTC

svn commit: r507511 - in /webservices/axis2/trunk/java/modules: adb-codegen/src/org/apache/axis2/schema/ adb-codegen/src/org/apache/axis2/schema/template/ adb-codegen/test-resources/testsuite/ adb-codegen/test/org/apache/axis2/schema/union/ codegen/src...

Author: amilas
Date: Wed Feb 14 04:31:29 2007
New Revision: 507511

URL: http://svn.apache.org/viewvc?view=rev&rev=507511
Log:
Applied the patch for AXIS2-2167
Add support for inner simple types in union (fixed the AXIS2-2144 for adb)

Added:
    webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/XSDConfig.java
Modified:
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/choice.xsd
    webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/union.xsd
    webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/union/UnionTest.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOptionConstants.java
    webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java Wed Feb 14 04:31:29 2007
@@ -1,54 +1,14 @@
 package org.apache.axis2.schema;
 
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
 import org.apache.axis2.namespace.Constants;
 import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
 import org.apache.axis2.schema.util.SchemaPropertyLoader;
 import org.apache.axis2.schema.writer.BeanWriter;
-import org.apache.axis2.schema.typemap.JavaTypeMap;
 import org.apache.axis2.util.URLProcessor;
 import org.apache.axis2.util.SchemaUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaAll;
-import org.apache.ws.commons.schema.XmlSchemaAny;
-import org.apache.ws.commons.schema.XmlSchemaAnyAttribute;
-import org.apache.ws.commons.schema.XmlSchemaAttribute;
-import org.apache.ws.commons.schema.XmlSchemaChoice;
-import org.apache.ws.commons.schema.XmlSchemaComplexContent;
-import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
-import org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaContent;
-import org.apache.ws.commons.schema.XmlSchemaContentModel;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
-import org.apache.ws.commons.schema.XmlSchemaImport;
-import org.apache.ws.commons.schema.XmlSchemaInclude;
-import org.apache.ws.commons.schema.XmlSchemaLengthFacet;
-import org.apache.ws.commons.schema.XmlSchemaMaxExclusiveFacet;
-import org.apache.ws.commons.schema.XmlSchemaMaxInclusiveFacet;
-import org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet;
-import org.apache.ws.commons.schema.XmlSchemaMinExclusiveFacet;
-import org.apache.ws.commons.schema.XmlSchemaMinInclusiveFacet;
-import org.apache.ws.commons.schema.XmlSchemaMinLengthFacet;
-import org.apache.ws.commons.schema.XmlSchemaObject;
-import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
-import org.apache.ws.commons.schema.XmlSchemaObjectTable;
-import org.apache.ws.commons.schema.XmlSchemaParticle;
-import org.apache.ws.commons.schema.XmlSchemaPatternFacet;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
-import org.apache.ws.commons.schema.XmlSchemaSimpleContent;
-import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
-import org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction;
-import org.apache.ws.commons.schema.XmlSchemaSimpleType;
-import org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent;
-import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
-import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
-import org.apache.ws.commons.schema.XmlSchemaSimpleTypeUnion;
-import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.*;
 
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
@@ -365,7 +325,7 @@
                     //process simple type
                     processSimpleSchemaType((XmlSchemaSimpleType) schemaType,
                             null,
-                            schema);
+                            schema,null);
                 }
             }
         }
@@ -886,7 +846,7 @@
             //process simple type
             processSimpleSchemaType((XmlSchemaSimpleType) schemaType,
                     xsElt,
-                    parentSchema);
+                    parentSchema, null);
         }
     }
 
@@ -1043,7 +1003,7 @@
                     }
                 } else if (type instanceof XmlSchemaSimpleType) {
                     //process simple type
-                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema);
+                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema,null);
                 }
             }
 
@@ -1262,7 +1222,7 @@
                     }
                 } else if (type instanceof XmlSchemaSimpleType) {
                     //process simple type
-                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema);
+                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema,null);
                 }
             }
 
@@ -1304,7 +1264,7 @@
                     }
                 } else if (type instanceof XmlSchemaSimpleType) {
                     //process simple type
-                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema);
+                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema,null);
                 }
             }
             //process restriction base type
@@ -1549,7 +1509,7 @@
                         if (simpleType.getContent() instanceof XmlSchemaSimpleTypeRestriction) {
                             if (!isAlreadyProcessed(schemaTypeName)) {
                                 //process simple type
-                                processSimpleSchemaType(simpleType, null, parentSchema);
+                                processSimpleSchemaType(simpleType, null, parentSchema,null);
                             }
                             metainf.registerMapping(att.getQName(),
                                     schemaTypeName,
@@ -1810,33 +1770,38 @@
     }
 
     private XmlSchemaType getType(XmlSchema schema, QName schemaTypeName) throws SchemaCompilationException {
-        schema = resolveParentSchema(schemaTypeName, schema);
+        // first check with the current parent schema
         XmlSchemaType typeByName = schema.getTypeByName(schemaTypeName);
-        if (typeByName == null) {
-            // The referenced element seems to come from an imported
-            // schema.
-            XmlSchemaObjectCollection includes = schema.getIncludes();
-            if (includes != null) {
-                Iterator tempIterator = includes.getIterator();
-                while (tempIterator.hasNext()) {
-                    Object o = tempIterator.next();
-                    XmlSchema inclSchema = null;
-                    if (o instanceof XmlSchemaImport) {
-                        inclSchema = ((XmlSchemaImport) o).getSchema();
-                        if (inclSchema == null) {
-                            inclSchema = (XmlSchema) loadedSchemaMap.get(((XmlSchemaImport) o).getNamespace());
+        if (typeByName == null){
+            // try to resolve schema using the target names space
+            schema = resolveParentSchema(schemaTypeName, schema);
+            typeByName = schema.getTypeByName(schemaTypeName);
+            if (typeByName == null) {
+                // The referenced element seems to come from an imported
+                // schema.
+                XmlSchemaObjectCollection includes = schema.getIncludes();
+                if (includes != null) {
+                    Iterator tempIterator = includes.getIterator();
+                    while (tempIterator.hasNext()) {
+                        Object o = tempIterator.next();
+                        XmlSchema inclSchema = null;
+                        if (o instanceof XmlSchemaImport) {
+                            inclSchema = ((XmlSchemaImport) o).getSchema();
+                            if (inclSchema == null) {
+                                inclSchema = (XmlSchema) loadedSchemaMap.get(((XmlSchemaImport) o).getNamespace());
+                            }
+                        }
+                        if (o instanceof XmlSchemaInclude) {
+                            inclSchema = ((XmlSchemaInclude) o).getSchema();
+                        }
+                        // get the element from the included schema
+                        if (inclSchema != null) {
+                            typeByName = inclSchema.getTypeByName(schemaTypeName);
+                        }
+                        if (typeByName != null) {
+                            // we found the referenced element an can break the loop
+                            break;
                         }
-                    }
-                    if (o instanceof XmlSchemaInclude) {
-                        inclSchema = ((XmlSchemaInclude) o).getSchema();
-                    }
-                    // get the element from the included schema
-                    if (inclSchema != null) {
-                        typeByName = inclSchema.getTypeByName(schemaTypeName);
-                    }
-                    if (typeByName != null) {
-                        // we found the referenced element an can break the loop
-                        break;
                     }
                 }
             }
@@ -1899,13 +1864,17 @@
     }
 
     /**
-     * Handle the simple content
      *
      * @param simpleType
+     * @param xsElt
+     * @param parentSchema
+     * @param qname  - fake Qname to use if the xsElt is null.
+     * @throws SchemaCompilationException
      */
     private void processSimpleSchemaType(XmlSchemaSimpleType simpleType,
                                          XmlSchemaElement xsElt,
-                                         XmlSchema parentSchema) throws SchemaCompilationException {
+                                         XmlSchema parentSchema,
+                                         QName qname) throws SchemaCompilationException {
 
         String fullyQualifiedClassName = null;
         if (simpleType.getQName() != null) {
@@ -1920,16 +1889,23 @@
             // otherwise we have to any way process that element.
             processedTypemap.put(simpleType.getQName(), fullyQualifiedClassName);
         } else {
-            QName fakeQname = new QName(xsElt.getQName().getNamespaceURI(), xsElt.getQName().getLocalPart());
+
+            QName fakeQname;
+            if (xsElt != null){
+                fakeQname = new QName(xsElt.getQName().getNamespaceURI(), xsElt.getQName().getLocalPart());
+                // we have to set this otherwise the ours attribute would not set properly if refered to this simple
+                // type from any other element
+                xsElt.setSchemaTypeName(fakeQname);
+            } else {
+                fakeQname = qname;
+            }
             if (processedTypemap.containsKey(fakeQname)
                     || baseSchemaTypeMap.containsKey(fakeQname)) {
                 return;
             }
             fullyQualifiedClassName = writer.makeFullyQualifiedClassName(fakeQname);
             simpleType.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.FAKE_QNAME, fakeQname);
-            // we have to set this otherwise the ours attribute would not set properly if refered to this simple
-            // type from any other element
-            xsElt.setSchemaTypeName(fakeQname);
+
             // should put this to the processedTypemap to generate the code correctly
             processedTypemap.put(fakeQname, fullyQualifiedClassName);
         }
@@ -1943,7 +1919,15 @@
 
         if (simpleType.getQName() == null) {
             this.processedAnonymousComplexTypesMap.put(xsElt, metaInfHolder);
-            simpleTypesMap.put(new QName(xsElt.getQName().getNamespaceURI(), xsElt.getQName().getLocalPart()), fullyQualifiedClassName);
+            QName fakeQname;
+            if (xsElt != null){
+                fakeQname = new QName(xsElt.getQName().getNamespaceURI(), xsElt.getQName().getLocalPart());
+            } else {
+                fakeQname = qname;
+                simpleType.setName(fakeQname.getLocalPart());
+                simpleType.setSourceURI(fakeQname.getNamespaceURI());
+            }
+            simpleTypesMap.put(fakeQname, fullyQualifiedClassName);
         }
         //add this information to the metainfo holder
         metaInfHolder.setOwnQname(simpleType.getQName());
@@ -1960,20 +1944,21 @@
 
         // handle the restriction
         XmlSchemaSimpleTypeContent content = simpleType.getContent();
+        QName parentSimpleTypeQname = simpleType.getQName();
+        if (parentSimpleTypeQname == null) {
+            parentSimpleTypeQname = (QName) simpleType.getMetaInfoMap().get(SchemaConstants.SchemaCompilerInfoHolder.FAKE_QNAME);
+        }
         if (content != null) {
             if (content instanceof XmlSchemaSimpleTypeRestriction) {
                 XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
 
                 QName baseTypeName = restriction.getBaseTypeName();
                 //check whether the base type is one of the base schema types
-                QName qName = simpleType.getQName();
-                if (qName == null) {
-                    qName = (QName) simpleType.getMetaInfoMap().get(SchemaConstants.SchemaCompilerInfoHolder.FAKE_QNAME);
-                }
+
                 if (baseSchemaTypeMap.containsKey(baseTypeName)) {
                     //process restriction base type
 
-                    processSimpleRestrictionBaseType(qName, restriction.getBaseTypeName(), metaInfHolder, parentSchema);
+                    processSimpleRestrictionBaseType(parentSimpleTypeQname, restriction.getBaseTypeName(), metaInfHolder, parentSchema);
                     //process facets
                     processFacets(restriction, metaInfHolder, parentSchema);
                 } else {
@@ -1983,10 +1968,10 @@
                     XmlSchemaType restrictionBaseType = getType(parentSchema, baseTypeName);
                     if (restrictionBaseType instanceof XmlSchemaSimpleType) {
                         if ((restrictionBaseType != null) && (!isAlreadyProcessed(baseTypeName))) {
-                            processSimpleSchemaType((XmlSchemaSimpleType) restrictionBaseType, null, parentSchema);
+                            processSimpleSchemaType((XmlSchemaSimpleType) restrictionBaseType, null, parentSchema,null);
                         }
                         // process restriction
-                        processSimpleRestrictionBaseType(qName, restriction.getBaseTypeName(), metaInfHolder, parentSchema);
+                        processSimpleRestrictionBaseType(parentSimpleTypeQname, restriction.getBaseTypeName(), metaInfHolder, parentSchema);
                     }
 
 
@@ -2005,7 +1990,7 @@
                             if (type instanceof XmlSchemaSimpleType) {
                                 XmlSchemaSimpleType memberSimpleType = (XmlSchemaSimpleType) type;
                                 if (!isAlreadyProcessed(qname)) {
-                                    processSimpleSchemaType(memberSimpleType, null, parentSchema);
+                                    processSimpleSchemaType(memberSimpleType, null, parentSchema,null);
                                 }
                                 metaInfHolder.addMemberType(qname, (String) processedTypemap.get(qname));
                             } else {
@@ -2014,7 +1999,27 @@
                         }
                     }
                 } else {
-                    // TODO : handle inline simple types
+                    XmlSchemaObjectCollection xmlSchemaObjectCollection = simpleTypeUnion.getBaseTypes();
+                    XmlSchemaObject xmlSchemaObject;
+                    QName childQname;
+                    int i = 1;
+                    for (Iterator iter = xmlSchemaObjectCollection.getIterator();iter.hasNext();){
+                        xmlSchemaObject = (XmlSchemaObject) iter.next();
+                        i++;
+                        if (xmlSchemaObject instanceof XmlSchemaSimpleType){
+                            XmlSchemaSimpleType unionSimpleType = (XmlSchemaSimpleType) xmlSchemaObject;
+                            childQname = unionSimpleType.getQName();
+                            if (childQname == null){
+                                // we create a fake Qname for all these simple types since most propably they don't have one
+                                childQname = new QName(parentSimpleTypeQname.getNamespaceURI(),parentSimpleTypeQname.getLocalPart() + "_type" + i);
+                            }
+                            // this is an inner simple type of the union so it shold not have
+                            // processed
+                            processSimpleSchemaType(unionSimpleType,null,parentSchema,childQname);
+                            metaInfHolder.addMemberType(childQname, (String) processedTypemap.get(childQname));
+                        }
+
+                    }
                 }
 
                 metaInfHolder.setUnion(true);
@@ -2026,7 +2031,7 @@
                 if (!isAlreadyProcessed(itemTypeQName)){
                     XmlSchemaType simpleSchemaType = getType(parentSchema,itemTypeQName);
                     if (simpleSchemaType instanceof XmlSchemaSimpleType){
-                        processSimpleSchemaType((XmlSchemaSimpleType)simpleSchemaType,null,parentSchema);
+                        processSimpleSchemaType((XmlSchemaSimpleType)simpleSchemaType,null,parentSchema,null);
                     }
                 }
 

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl Wed Feb 14 04:31:29 2007
@@ -1912,6 +1912,7 @@
                             object = new <xsl:value-of select="$name"/>();
                             object.setObject(xmlStreamReader, namespaceURI, type);
                         } else {
+                            object = new <xsl:value-of select="$name"/>();
                             object.setObject(<xsl:value-of select="$mapperClass"/>.getTypeObject(namespaceURI, type, xmlStreamReader));
                         }
                         return object;

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/choice.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/choice.xsd?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/choice.xsd (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/choice.xsd Wed Feb 14 04:31:29 2007
@@ -6,7 +6,7 @@
         xmlns:test1="org.apache.axis2.test"
         targetNamespace="org.apache.axis2.test">
 
-    <xs:element name="TestChoise">
+    <xs:element name="TestChoise" >
         <xs:complexType>
             <xs:choice>
                 <xs:element name="choice1" type="xs:string"/>
@@ -18,7 +18,7 @@
     <xsd:element name="myRootElem">
         <xsd:complexType>
             <xsd:sequence>
-                <xsd:element name="Child1" type="xsd:int">
+                <xsd:element name="Child1" type="xsd:int" >
                 </xsd:element>
                 <xsd:choice>
                     <xsd:element name="SomeChoice1" type="test1:SomeChoice1_Type" nillable="true" maxOccurs="unbounded"/>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/union.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/union.xsd?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/union.xsd (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/union.xsd Wed Feb 14 04:31:29 2007
@@ -1,7 +1,8 @@
 <s:schema elementFormDefault="qualified"
           xmlns:s="http://www.w3.org/2001/XMLSchema"
-          xmlns:s0="http://tempuri.org/"
-          targetNamespace="http://tempuri.org/">
+          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+          xmlns:s0="http://tempuri.org/union"
+          targetNamespace="http://tempuri.org/union">
     <s:import namespace="http://www.w3.org/2001/XMLSchema"/>
 
     <s:simpleType name="FooEnum">
@@ -11,15 +12,12 @@
             <s:enumeration value="http://C"/>
         </s:restriction>
     </s:simpleType>
-
     <s:simpleType name="FooOpenEnum">
         <s:union memberTypes="s0:FooEnum s:anyURI"/>
     </s:simpleType>
-
     <s:simpleType name="DateOrDateTimeType">
         <s:union memberTypes="s:boolean s:int s:date s:dateTime"/>
     </s:simpleType>
-
     <s:element name="Record1">
         <s:complexType>
             <s:sequence>
@@ -27,7 +25,6 @@
             </s:sequence>
         </s:complexType>
     </s:element>
-
     <s:element name="Record2">
         <s:complexType>
             <s:sequence>
@@ -35,11 +32,34 @@
             </s:sequence>
         </s:complexType>
     </s:element>
-
     <s:simpleType name="UnionQNameTest">
         <s:union memberTypes="s:QName s:string"/>
     </s:simpleType>
-
     <s:element name="UnionQNameTestElement" type="s0:UnionQNameTest"/>
-    
+
+    <xsd:simpleType name="PackingType_T">
+        <xsd:union>
+            <xsd:simpleType>
+                <xsd:restriction base="xsd:string">
+                    <xsd:pattern value="MINOR_([a-z]|[A-Z]|[0-9]|(_|-))*"/>
+                </xsd:restriction>
+            </xsd:simpleType>
+            <xsd:simpleType>
+                <xsd:restriction base="xsd:string">
+                    <xsd:pattern value="PROP_([a-z]|[A-Z]|[0-9]|(_|-))*"/>
+                </xsd:restriction>
+            </xsd:simpleType>
+            <xsd:simpleType>
+                <xsd:restriction base="xsd:string">
+                    <xsd:enumeration value="NO_PACKING"/>
+                    <xsd:enumeration value="ZIP"/>
+                    <xsd:enumeration value="TAR"/>
+                </xsd:restriction>
+            </xsd:simpleType>
+        </xsd:union>
+    </xsd:simpleType>
+
+    <s:element name="TestInnerUnionType" type="s0:PackingType_T"/>
+
+
 </s:schema>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/union/UnionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/union/UnionTest.java?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/union/UnionTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/union/UnionTest.java Wed Feb 14 04:31:29 2007
@@ -16,7 +16,7 @@
 package org.apache.axis2.schema.union;
 
 import junit.framework.TestCase;
-import org.tempuri.*;
+import org.tempuri.union.*;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.util.StAXUtils;
@@ -103,5 +103,61 @@
         } catch (Exception e) {
             assertTrue(false);
         }
+    }
+
+    public void testInnerSimpleTypes(){
+        TestInnerUnionType testInnerUnionType = new TestInnerUnionType();
+        PackingType_T packingType_t = new PackingType_T();
+        testInnerUnionType.setTestInnerUnionType(packingType_t);
+        PackingType_T_type2 packingType_t_type2 = new PackingType_T_type2();
+        packingType_t_type2.setPackingType_T_type2("MINOR_a");
+        packingType_t.setObject(packingType_t_type2);
+
+        OMElement omElement = testInnerUnionType.getOMElement(TestInnerUnionType.MY_QNAME,OMAbstractFactory.getOMFactory());
+        try {
+            String omElementString = omElement.toStringWithConsume();
+            System.out.println("OM Element ==> " + omElementString);
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+            TestInnerUnionType result = TestInnerUnionType.Factory.parse(xmlReader);
+            assertEquals(packingType_t_type2.toString(),result.getTestInnerUnionType().getObject().toString());
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+
+        testInnerUnionType = new TestInnerUnionType();
+        packingType_t = new PackingType_T();
+        testInnerUnionType.setTestInnerUnionType(packingType_t);
+        PackingType_T_type3 packingType_t_type3 = new PackingType_T_type3();
+        packingType_t_type3.setPackingType_T_type3("PROP_a");
+        packingType_t.setObject(packingType_t_type3);
+
+        omElement = testInnerUnionType.getOMElement(TestInnerUnionType.MY_QNAME,OMAbstractFactory.getOMFactory());
+        try {
+            String omElementString = omElement.toStringWithConsume();
+            System.out.println("OM Element ==> " + omElementString);
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+            TestInnerUnionType result = TestInnerUnionType.Factory.parse(xmlReader);
+            assertEquals(packingType_t_type3.toString(),result.getTestInnerUnionType().getObject().toString());
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+
+        testInnerUnionType = new TestInnerUnionType();
+        packingType_t = new PackingType_T();
+        testInnerUnionType.setTestInnerUnionType(packingType_t);
+        packingType_t.setObject(PackingType_T_type4.TAR);
+
+        omElement = testInnerUnionType.getOMElement(TestInnerUnionType.MY_QNAME,OMAbstractFactory.getOMFactory());
+        try {
+            String omElementString = omElement.toStringWithConsume();
+            System.out.println("OM Element ==> " + omElementString);
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+            TestInnerUnionType result = TestInnerUnionType.Factory.parse(xmlReader);
+            assertEquals(PackingType_T_type4.TAR,result.getTestInnerUnionType().getObject());
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+
+
     }
 }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java Wed Feb 14 04:31:29 2007
@@ -73,6 +73,27 @@
             this.uri2PackageNameMap.putAll(uri2PackageNameMap);
         }
     }
+  
+    /** Full path and name of XMLBeans xsdconfig file to use */
+    private String xsdConfigFile = null;
+
+    /**
+     * Returns the xsdconfig file to use for XMLBeans data binding.
+     *
+     * @return Full path and name of XMLBeans xsdconfig file to use
+     */
+    public String getXsdConfigFile() {
+      return xsdConfigFile;
+    }
+
+    /**
+     * Sets the xsdconfig file to use for XMLBeans data binding.
+     *
+     * @param xsdConfigFile Full path and name of XMLBeans xsdconfig file to use
+     */
+    public void setXsdConfigFile(String xsdConfigFile) {
+      this.xsdConfigFile = xsdConfigFile;
+    }
 
     /**
      * Says whether to flatten the files or put them in specific folders

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java Wed Feb 14 04:31:29 2007
@@ -213,6 +213,13 @@
             config.setSuppressPrefixesMode(true);
         }
 
+        commandLineOption = loadOption(WSDL2JavaConstants.XSDCONFIG_OPTION,
+                       WSDL2JavaConstants.XSDCONFIG_OPTION_LONG,
+                       optionMap);
+         if (commandLineOption != null) {
+           config.setXsdConfigFile(commandLineOption.getOptionValue());
+         }
+
         // loop through the map and find parameters having the extra prefix.
         //put them in the property map
         Iterator keyIterator = optionMap.keySet().iterator();

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java Wed Feb 14 04:31:29 2007
@@ -56,6 +56,7 @@
                     (WSDL2JavaConstants.SUPPRESS_PREFIXES_OPTION).equalsIgnoreCase(optionType) ||
                     (WSDL2JavaConstants.SOURCE_FOLDER_NAME_OPTION).equalsIgnoreCase(optionType) ||
                     (WSDL2JavaConstants.RESOURCE_FOLDER_OPTION).equalsIgnoreCase(optionType) ||
+                    (WSDL2JavaConstants.XSDCONFIG_OPTION).equalsIgnoreCase(optionType) ||
 
                     (WSDL2JavaConstants.OUTPUT_LOCATION_OPTION_LONG).equalsIgnoreCase(optionType) ||
                     (WSDL2JavaConstants.SERVER_SIDE_CODE_OPTION_LONG).equalsIgnoreCase(optionType) ||
@@ -80,7 +81,8 @@
                     (WSDL2JavaConstants.SOURCE_FOLDER_NAME_OPTION_LONG).equalsIgnoreCase(optionType)||
                     (WSDL2JavaConstants.RESOURCE_FOLDER_OPTION_LONG).equalsIgnoreCase(optionType)||
                     (WSDL2JavaConstants.BACKWORD_COMPATIBILITY_OPTION_LONG).equalsIgnoreCase(optionType) ||
-                    (WSDL2JavaConstants.SUPPRESS_PREFIXES_OPTION_LONG).equalsIgnoreCase(optionType)
+                    (WSDL2JavaConstants.SUPPRESS_PREFIXES_OPTION_LONG).equalsIgnoreCase(optionType) ||
+                    (WSDL2JavaConstants.XSDCONFIG_OPTION_LONG).equalsIgnoreCase(optionType)
             );
 
         }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOptionConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOptionConstants.java?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOptionConstants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOptionConstants.java Wed Feb 14 04:31:29 2007
@@ -46,7 +46,7 @@
         String SUPPRESS_PREFIXES_OPTION = "sp";
         String SOURCE_FOLDER_NAME_OPTION = "S";
         String RESOURCE_FOLDER_OPTION = "R";
-
+        String XSDCONFIG_OPTION = "xc";
 
         //long option constants
         String OUTPUT_LOCATION_OPTION_LONG = "output";
@@ -75,6 +75,7 @@
         String SUPPRESS_PREFIXES_OPTION_LONG = "suppress-prefixes";
         String SOURCE_FOLDER_NAME_OPTION_LONG = "source-folder";
         String RESOURCE_FOLDER_OPTION_LONG = "resource-folder";
+        String XSDCONFIG_OPTION_LONG = "xsdconfig";
 
         String WSDL_VERSION_2 = "2.0";
         String WSDL_VERSION_2_OPTIONAL = "2";

Modified: webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java?view=diff&rev=507511&r1=507510&r2=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java (original)
+++ webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java Wed Feb 14 04:31:29 2007
@@ -163,12 +163,11 @@
                     null,
                     null,
                     convertToSchemaArray(topLevelSchemaList),
-                    new Axis2BindingConfig(cgconfig.getUri2PackageNameMap()),
+                    new Axis2BindingConfig(cgconfig.getUri2PackageNameMap(), cgconfig.getXsdConfigFile()),
                     XmlBeans.getContextTypeLoader(),
                     new Axis2Filer(cgconfig),
                     new XmlOptions().setEntityResolver(er));
 
-
             // prune the generated schema type system and add the list of base64 types
             cgconfig.putProperty(Constants.BASE_64_PROPERTY_KEY,
                     findBase64Types(sts));
@@ -414,20 +413,55 @@
     private static class Axis2BindingConfig extends BindingConfig {
 
         private Map uri2packageMappings = null;
+        private XSDConfig xsdConfig = null;
 
-        public Axis2BindingConfig(Map uri2packageMappings) {
+        public Axis2BindingConfig(Map uri2packageMappings, String xsdConfigfile) {
             this.uri2packageMappings = uri2packageMappings;
             if (this.uri2packageMappings == null) {
                 //make an empty one to avoid nasty surprises
                 this.uri2packageMappings = new HashMap();
             }
+
+            // Do we have an xsdconfig file?
+            if (xsdConfigfile != null) {
+                xsdConfig = new XSDConfig(xsdConfigfile);
+            }
         }
 
         public String lookupPackageForNamespace(String uri) {
+            /* If the xsdconfig file has mappings, we'll use them instead of the -p option.
+             * If we have an xsdconfig file but no namespace to package mappings, then we'll
+             * defer to the -p option.
+             */
+            if (xsdConfig != null) {
+                if (xsdConfig.hasNamespaceToJavaPackageMappings) {
+                    log.debug("RETURNING " + uri + " = " + xsdConfig.getNamespacesToJavaPackages().get(uri));
+                    return (String) xsdConfig.getNamespacesToJavaPackages().get(uri);
+                }
+            }
+
             if (uri2packageMappings.containsKey(uri)) {
                 return (String) uri2packageMappings.get(uri);
             } else {
                 return URLProcessor.makePackageName(uri);
+            }
+        }
+
+        public String lookupJavanameForQName(QName qname) {
+            /* The mappings are stored in the format:
+            * NAMESPACE:LOCAL_NAME, i.e.
+            * urn:weegietech:minerva:moduleType
+            */
+            if (xsdConfig != null) {
+                String key = qname.getNamespaceURI() + ":" + qname.getLocalPart();
+                if (xsdConfig.getSchemaTypesToJavaNames().containsKey(key)) {
+                    log.debug("RETURNING " + qname.getLocalPart() + " = " + xsdConfig.getSchemaTypesToJavaNames().get(key));
+                    return (String) xsdConfig.getSchemaTypesToJavaNames().get(key);
+                } else {
+                    return null;
+                }
+            } else {
+                return super.lookupJavanameForQName(qname);
             }
 
         }

Added: webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/XSDConfig.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/XSDConfig.java?view=auto&rev=507511
==============================================================================
--- webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/XSDConfig.java (added)
+++ webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/XSDConfig.java Wed Feb 14 04:31:29 2007
@@ -0,0 +1,224 @@
+/* CVS Header
+   $Id$
+   $Log$
+*/
+
+package org.apache.axis2.xmlbeans;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.ErrorHandler;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.NamedNodeMap;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+
+public class XSDConfig {
+    private static final String XMLBEANS_NS = "http://xml.apache.org/xmlbeans/2004/02/xbean/config";
+    private static final String XMLBEANS_QNAME_NODE = "qname";
+    private static final String XMLBEANS_NS_NODE = "namespace";
+
+    /**
+     * The parsed xsdconfig file
+     */
+    private Document xsdConfigDoc = null;
+    /**
+     * The list of prefixes on the document root
+     */
+    private HashMap prefixesToURIMappings = null;
+    /**
+     * The list of schema tyes to Java class names
+     */
+    private HashMap qnamesToJavaNamesMappings = null;
+    /**
+     * The list of namespaces to Java package names
+     */
+    private HashMap nsToJavaPackagesMap = null;
+    /**
+     * Indicates whether we have any QName to Java class name mappings
+     */
+    public boolean hasQNameToJavaNameMappings = false;
+    /**
+     * Indicates whether we have any namespace to Java package mappings
+     */
+    public boolean hasNamespaceToJavaPackageMappings = false;
+
+    public XSDConfig(String xsdConfigFile) {
+        try {
+            DocumentBuilder builder = null;
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+            factory.setNamespaceAware(true);
+            factory.setValidating(false);
+
+            builder = factory.newDocumentBuilder();
+            builder.setErrorHandler(new ParseErrorHandler());
+
+            xsdConfigDoc = builder.parse(new File(xsdConfigFile));
+
+            // Create a mapping for all the namespaces in the document
+            prefixesToURIMappings = new HashMap();
+            NamedNodeMap attributes = xsdConfigDoc.getDocumentElement().getAttributes();
+            for (int c = 0; c < attributes.getLength(); c++) {
+                /* Do we have a namespace declaration?
+                * xmlns:mv="urn:weegietech:minerva"
+                */
+                if (attributes.item(c).getNodeName().indexOf("xmlns:") != -1) {
+                    String[] parts = attributes.item(c).getNodeName().split(":");
+
+                    // Add the prefix to uri mapping to our list
+                    prefixesToURIMappings.put(parts[1], attributes.item(c).getNodeValue());
+                }
+            }
+
+            // Load up the list of QName to Java class name mappings
+            qnamesToJavaNamesMappings = getQNamesToJavaNames();
+            if (qnamesToJavaNamesMappings.size() > 0)
+                hasQNameToJavaNameMappings = true;
+
+            // Load up the list of namespaces to Java packages mappings
+            nsToJavaPackagesMap = getNamespacesToPackages();
+            if (nsToJavaPackagesMap.size() > 0)
+                hasNamespaceToJavaPackageMappings = true;
+        } catch (IOException ioe) {
+            throw new RuntimeException(ioe);
+        } catch (SAXException se) {
+            throw new RuntimeException(se);
+        } catch (IllegalArgumentException iae) {
+            throw new RuntimeException(iae);
+        } catch (ParserConfigurationException pce) {
+            throw new RuntimeException(pce);
+        }
+    }
+
+    /**
+     * Returns the pre loaded schema types to Java class names mappings.
+     *
+     * @return HashMap of schema types to Java class names mappings as
+     *         as specified in the xsdconfig file.
+     */
+    public HashMap getSchemaTypesToJavaNames() {
+        return qnamesToJavaNamesMappings;
+    }
+
+    /**
+     * Returns the pre loaded namespace to Java package mappings.
+     *
+     * @return HashMap of namespace to Java package mappings as
+     *         as specified in the xsdconfig file.
+     */
+    public HashMap getNamespacesToJavaPackages() {
+        return nsToJavaPackagesMap;
+    }
+
+    /**
+     * Loads the schema types to Java class name mappings
+     *
+     * @return HashMap containing the schema types to Java class name mappings
+     *         as specified in the xsdconfig file. If there are no mappings, the
+     *         returned HashMap will be empty.
+     */
+    private HashMap getQNamesToJavaNames() {
+        HashMap qnamesToJavaNamesMap = new HashMap();
+
+        /* Look for all the <xb:qname ... /> nodes as these specify
+        * xml schema types to Java class mappings.
+        * <xb:qname name="mv:moduleType" javaname="Module"/>
+        */
+        NodeList qnameNodes = xsdConfigDoc.getElementsByTagNameNS(XMLBEANS_NS, XMLBEANS_QNAME_NODE);
+
+        for (int c = 0; c < qnameNodes.getLength(); c++) {
+            Node qnameNode = qnameNodes.item(c);
+
+            /* In the xsdconfig file we'll get schema types with a prefix and not a uri.
+            * <xb:qname name="mv:moduleType" javaname="Module"/>
+            * but XMLBeans will call BindingConfig::lookupJavanameForQName with a QName
+            * which has a namespace uri and no prefix.
+            * So we'll store the fully qualifed schema type name in the mapping list.
+            * i.e. we pick it up from the xsdconfig file as:
+            * mv:moduleType
+            * but we'll store it as urn:weegietech:minerva:moduleType
+            */
+            String schemaType = qnameNode.getAttributes().getNamedItem("name").getNodeValue();
+            if (schemaType.indexOf(":") != -1) {
+                // mv:moduleType
+                String prefix = schemaType.split(":")[0];
+                String localName = schemaType.split(":")[1];
+
+                if (prefixesToURIMappings.containsKey(prefix)) {
+                    // Store as urn:weegietech:minerva:moduleType
+                    String key = (String) prefixesToURIMappings.get(prefix) + ":" + localName;
+
+                    // Direct mapping now from schema types to Java class names
+                    qnamesToJavaNamesMap.put(key, qnameNode.getAttributes().getNamedItem("javaname").getNodeValue());
+                }
+            }
+        }
+
+        return qnamesToJavaNamesMap;
+    }
+
+    /**
+     * Loads the namespace to Java package mappings
+     *
+     * @return HashMap containing the namespace to Java package mappings
+     *         as specified in the xsdconfig file. If there are no mappings, the
+     *         returned HashMap will be empty.
+     */
+    private HashMap getNamespacesToPackages() {
+        HashMap nsToJavaPackagesMap = new HashMap();
+
+        /* Look for all the <xb:namespace ... /> nodes as these specify
+        * xml namespace to Java package mappings.
+        * <xb:qname name="mv:moduleType" javaname="Module"/>
+        */
+        NodeList nsNodes = xsdConfigDoc.getElementsByTagNameNS(XMLBEANS_NS, XMLBEANS_NS_NODE);
+
+        for (int nsNodesCount = 0; nsNodesCount < nsNodes.getLength(); nsNodesCount++) {
+            Node nsNode = nsNodes.item(nsNodesCount);
+
+            // What's the current namespace?
+            String uri = nsNode.getAttributes().getNamedItem("uri").getNodeValue();
+
+            // Get the package name for the current namespace uri
+            String packageName = null;
+            NodeList childNodes = nsNode.getChildNodes();
+            for (int childNodesCount = 0; childNodesCount < childNodes.getLength(); childNodesCount++) {
+                Node childNode = childNodes.item(childNodesCount);
+                if (childNode.getLocalName() != null) {
+                    if (childNode.getLocalName().equals("package")) {
+                        packageName = childNode.getFirstChild().getNodeValue();
+                    }
+                }
+            }
+
+            // Store the namespace uri to Java package mapping
+            if (packageName != null) {
+                nsToJavaPackagesMap.put(uri, packageName);
+            }
+        }
+
+        return nsToJavaPackagesMap;
+    }
+
+    class ParseErrorHandler implements ErrorHandler {
+        public void error(SAXParseException exception) throws SAXException {
+            throw new SAXException(exception);
+        }
+
+        public void fatalError(SAXParseException exception) throws SAXException {
+            throw new SAXException(exception);
+        }
+
+        public void warning(SAXParseException exception) throws SAXException {
+            throw new SAXException(exception);
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org