axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ami...@apache.org
Subject svn commit: r594026 - in /webservices/axis2/trunk/java/modules/adb-codegen: ./ src/org/apache/axis2/schema/ src/org/apache/axis2/schema/template/ test-resources/testsuite/ test/org/apache/axis2/schema/references/
Date Mon, 12 Nov 2007 05:26:19 GMT
Author: amilas
Date: Sun Nov 11 21:26:16 2007
New Revision: 594026

URL: http://svn.apache.org/viewvc?rev=594026&view=rev
Log:
add circular element reference support

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/sub-build.xml
    webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/element_references.xsd
    webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/extensions.xsd
    webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/references/ElementReferenceTest.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?rev=594026&r1=594025&r2=594026&view=diff
==============================================================================
--- 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
Sun Nov 11 21:26:16 2007
@@ -528,7 +528,7 @@
 
         XmlSchemaType schemaType = xsElt.getSchemaType();
         if (schemaType != null) {
-            processSchema(xsElt, schemaType, parentSchema);
+            processSchema(xsElt, schemaType, parentSchema, false);
             //at this time it is not wise to directly write the class for the element
             //so we push the complete element to an arraylist and let the process
             //pass through. We'll be iterating through the elements writing them
@@ -637,53 +637,21 @@
                         SchemaCompilerMessages.getMessage("schema.referencedElementNotFound",
xsElt.getRefName().toString()));
             }
 
-            //if the element is referenced, then it should be one of the outer (global) ones
-            processElement(referencedElement, resolvedSchema);
-
-            //no outer check required here. If the element is having a ref, then it is definitely
-            //not an outer element since the top level elements are not supposed to have
refs
-            //Also we are sure that it should have a type reference
-            QName referenceEltQName = referencedElement.getQName();
-            if (referencedElement.getSchemaTypeName() != null) {
-                // we have to only find the class name without arrary part
-                String javaClassName = findClassName(referencedElement.getSchemaTypeName(),
false);
-                //if this element is referenced, there's no QName for this element
-                this.processedElementRefMap.put(referenceEltQName, javaClassName);
+            // here what we want is to set the schema type name for the element
+            if (referencedElement.getSchemaType() != null) {
+                if (!this.processedElementRefMap.containsKey(referencedElement.getQName())){
+                    processSchema(referencedElement, referencedElement.getSchemaType(), resolvedSchema,
true);
+                    // if this is an anonomous complex type we have to set this
+                    this.processedElementRefMap.put(referencedElement.getQName(),
+                            this.processedTypemap.get(referencedElement.getSchemaTypeName()));
+                }
+                String javaClassName = (String) this.processedTypemap.get(referencedElement.getSchemaTypeName());
                 referencedElement.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY,
                         javaClassName);
-                // set the element class name to be used in unwrapping
                 xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY,
-                                javaClassName);
-            } else {
-                //this referenced element has an anon type and that anon type has been already
-                //processed. But in this case we need it to be a seperate class since this
-                //complextype has to be added as an attribute in a class.
-                //generate a name for this type
-                QName generatedTypeName = generateTypeQName(referenceEltQName, resolvedSchema);
-                XmlSchemaType referenceSchemaType = referencedElement.getSchemaType();
-
-
-                if (referenceSchemaType instanceof XmlSchemaComplexType) {
-
-                    if (referencedElement.getSchemaTypeName() == null) {
-                        referencedElement.setSchemaTypeName(generatedTypeName);
-                    }
-
-                    //set a name
-                    referenceSchemaType.setName(generatedTypeName.getLocalPart());
-
-                    String javaclassName = writeComplexType((XmlSchemaComplexType) referenceSchemaType,
-                            (BeanWriterMetaInfoHolder) processedAnonymousComplexTypesMap.get(referencedElement));
-
-
-                    processedTypemap.put(generatedTypeName, javaclassName);
-                    this.processedElementRefMap.put(referenceEltQName, javaclassName);
-                    // set the class name to be used in unwrapping
-                    xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY,
-                                javaclassName);
-
-                }
+                        javaClassName);
             }
+
             // schema type name is present but not the schema type object
         } else if (xsElt.getSchemaTypeName() != null) {
             //There can be instances where the SchemaType is null but the schemaTypeName
is not!
@@ -698,7 +666,7 @@
 
             if (typeByName != null) {
                 //this type is found in the schema so we can process it
-                processSchema(xsElt, typeByName, resolvedSchema);
+                processSchema(xsElt, typeByName, resolvedSchema, false);
                 if (!isOuter) {
                     String className = findClassName(schemaTypeName, isArray(xsElt));
                     //since this is a inner element we should add it to the inner element
map
@@ -847,11 +815,13 @@
      */
     private void processSchema(XmlSchemaElement xsElt,
                                XmlSchemaType schemaType,
-                               XmlSchema parentSchema) throws SchemaCompilationException
{
+                               XmlSchema parentSchema,
+                               boolean isWriteAnonComplexType) throws SchemaCompilationException
{
         if (schemaType instanceof XmlSchemaComplexType) {
             //write classes for complex types
             XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaType;
-            if (complexType.getName() != null) {
+            // complex type name may not be null if we have set it
+            if (complexType.getName() != null && !this.changedComplexTypeSet.contains(schemaType))
{
                 // here complex type may be in another shcema so we have to find the
                 // correct parent schema.
                 XmlSchema resolvedSchema = getParentSchema(parentSchema,complexType.getQName(),COMPONENT_TYPE);
@@ -863,7 +833,7 @@
                    processNamedComplexSchemaType(complexType, resolvedSchema);
                 }
             } else {
-                processAnonymousComplexSchemaType(xsElt, complexType, parentSchema);
+                processAnonymousComplexSchemaType(xsElt, complexType, parentSchema, isWriteAnonComplexType);
             }
         } else if (schemaType instanceof XmlSchemaSimpleType) {
             //process simple type
@@ -880,13 +850,49 @@
      */
     private void processAnonymousComplexSchemaType(XmlSchemaElement elt,
                                                    XmlSchemaComplexType complexType,
-                                                   XmlSchema parentSchema)
+                                                   XmlSchema parentSchema,
+                                                   boolean isWriteAnonComplexType)
             throws SchemaCompilationException {
+
+        //here we have a problem when processing the circulare element
+        // references if we differ this processing
+        // generate a name to the complex type and register it here
+        QName generatedTypeName = null;
+        String javaClassName = null;
+        if (isWriteAnonComplexType) {
+
+            generatedTypeName = generateTypeQName(elt.getQName(), parentSchema);
+
+            if (elt.getSchemaTypeName() == null) {
+                elt.setSchemaTypeName(generatedTypeName);
+                this.changedElementSet.add(elt);
+            }
+
+            //set a name
+            complexType.setName(generatedTypeName.getLocalPart());
+            this.changedComplexTypeSet.add(complexType);
+
+            javaClassName = writer.makeFullyQualifiedClassName(generatedTypeName);
+            processedTypemap.put(generatedTypeName, javaClassName);
+            this.processedElementRefMap.put(elt.getQName(), javaClassName);
+            complexType.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY,
javaClassName);
+        }
+
+
         BeanWriterMetaInfoHolder metaInfHolder = processComplexType(elt.getQName(),complexType,
parentSchema);
 
+        // here the only difference is that we generate the class
+        // irrespective of where we need it or not
+        if (isWriteAnonComplexType) {
+            metaInfHolder.setOwnClassName(javaClassName);
+            metaInfHolder.setOwnQname(generatedTypeName);
+            writeComplexType(complexType, metaInfHolder);
+        }
+
         //since this is a special case (an unnamed complex type) we'll put the already processed
         //metainf holder in a special map to be used later
         this.processedAnonymousComplexTypesMap.put(elt, metaInfHolder);
+
     }
 
     /**

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?rev=594026&r1=594025&r2=594026&view=diff
==============================================================================
--- 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
Sun Nov 11 21:26:16 2007
@@ -118,7 +118,7 @@
              */
             private void clearAllSettingTrackers() {
             <xsl:for-each select="property">
-                <xsl:if test="$choice">
+                <xsl:if test="not(@attribute)">
                    local<xsl:value-of select="@javaname"/>Tracker = false;
                 </xsl:if>
            </xsl:for-each>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml?rev=594026&r1=594025&r2=594026&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml Sun Nov 11 21:26:16 2007
@@ -386,6 +386,14 @@
 			<arg file="${testsuite.source.dir}/default_value.xsd"/>
 			<arg file="${schema.generated.src.dir}"/>
 		</java>
+        <echo>Compiling complexExtension.xsd</echo>
+		<java classname="org.apache.axis2.schema.XSD2Java" fork="true">
+			<jvmarg line="${maven.junit.jvmargs}"/>
+			<classpath refid="maven.dependency.classpath"/>
+			<classpath location="${compiled.classes.dir}"/>
+			<arg file="${testsuite.source.dir}/complexExtension.xsd"/>
+			<arg file="${schema.generated.src.dir}"/>
+		</java>
     </target>
 
 </project>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/element_references.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/element_references.xsd?rev=594026&r1=594025&r2=594026&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/element_references.xsd
(original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/element_references.xsd
Sun Nov 11 21:26:16 2007
@@ -29,7 +29,6 @@
             </sequence>
         </complexType>
     </element>
-
     <element name="checkEligibility2">
         <complexType>
             <sequence>
@@ -45,6 +44,22 @@
                 <element minOccurs="0" name="expirationDate" type="string"/>
                 <element minOccurs="0" name="yearOfRedemption" type="int"/>
                 <element minOccurs="0" name="clientId" type="string"/>
+            </sequence>
+        </complexType>
+    </element>
+
+    <!-- circular element references -->
+    <element name="Element1" type="tns:ComplexType1"/>
+    <complexType name="ComplexType1">
+        <sequence>
+            <element ref="tns:Element1" minOccurs="0"/>
+        </sequence>
+    </complexType>
+    <element name="Element2">
+        <complexType>
+            <sequence>
+                <element name="param1" type="string"/>
+                <element ref="tns:Element2" minOccurs="0"/>
             </sequence>
         </complexType>
     </element>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/extensions.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/extensions.xsd?rev=594026&r1=594025&r2=594026&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/extensions.xsd
(original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/extensions.xsd
Sun Nov 11 21:26:16 2007
@@ -84,5 +84,6 @@
             <xs:element minOccurs="0" name="SORT_DESCENDING" type="xs:int"/>
         </xs:sequence>
     </xs:complexType>
+    
 
 </schema>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/references/ElementReferenceTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/references/ElementReferenceTest.java?rev=594026&r1=594025&r2=594026&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/references/ElementReferenceTest.java
(original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/references/ElementReferenceTest.java
Sun Nov 11 21:26:16 2007
@@ -18,15 +18,15 @@
  */
 package org.apache.axis2.schema.references;
 
-import com.americanexpress.www.wsdl.ctn.utilities.atb.AtbRequestCheckEligibility_type0;
-import com.americanexpress.www.wsdl.ctn.utilities.atb.CheckEligibility1;
-import com.americanexpress.www.wsdl.ctn.utilities.atb.CheckEligibility2;
+import com.americanexpress.www.wsdl.ctn.utilities.atb.*;
 import junit.framework.TestCase;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axis2.databinding.ADBException;
 
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
 import java.io.ByteArrayInputStream;
 
 
@@ -98,4 +98,84 @@
             fail();
         }
     }
+
+    public void testElement11(){
+
+        Element1 element1 = new Element1();
+        ComplexType1 complexType1 = new ComplexType1();
+        element1.setElement1(complexType1);
+
+        try {
+            OMElement omElement = element1.getOMElement(Element1.MY_QNAME,OMAbstractFactory.getOMFactory());
+            String omElementString = omElement.toStringWithConsume();
+            System.out.println("OM String ==> " + omElementString);
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+            Element1 result = Element1.Factory.parse(xmlReader);
+            assertNotNull(result);
+        } catch (ADBException e) {
+            fail();
+        } catch (XMLStreamException e) {
+            fail();
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    public void testElement12(){
+
+        Element1 element1 = new Element1();
+        ComplexType1 complexType1 = new ComplexType1();
+        element1.setElement1(complexType1);
+        ComplexType1 complexType2 = new ComplexType1();
+        complexType1.setElement1(complexType2);
+        ComplexType1 complexType3 = new ComplexType1();
+        complexType2.setElement1(complexType3);
+
+
+        try {
+            OMElement omElement = element1.getOMElement(Element1.MY_QNAME,OMAbstractFactory.getOMFactory());
+            String omElementString = omElement.toStringWithConsume();
+            System.out.println("OM String ==> " + omElementString);
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+            Element1 result = Element1.Factory.parse(xmlReader);
+            assertNotNull(result);
+            assertNotNull(result.getElement1());
+            assertNotNull(result.getElement1().getElement1());
+        } catch (ADBException e) {
+            fail();
+        } catch (XMLStreamException e) {
+            fail();
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    public void testElement21(){
+        Element2 element2 = new Element2();
+        Element2_type0 element2_type0 = new Element2_type0();
+        element2.setElement2(element2_type0);
+        element2_type0.setParam1("test string1");
+
+        Element2_type0 element2_type1 = new Element2_type0();
+        element2_type1.setParam1("test string2");
+        element2_type0.setElement2(element2_type1);
+
+        try {
+            OMElement omElement = element2.getOMElement(Element2.MY_QNAME,OMAbstractFactory.getOMFactory());
+            String omElmentString = omElement.toStringWithConsume();
+            System.out.println("OM element ==>" + omElmentString);
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElmentString.getBytes()));
+            Element2 result = Element2.Factory.parse(xmlReader);
+            assertEquals(result.getElement2().getParam1(),"test string1");
+            assertEquals(result.getElement2().getElement2().getParam1(), "test string2");
+        } catch (ADBException e) {
+            fail();
+        } catch (XMLStreamException e) {
+            fail();
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+
 }



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


Mime
View raw message