Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 8119 invoked from network); 12 Nov 2007 05:26:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Nov 2007 05:26:47 -0000 Received: (qmail 2422 invoked by uid 500); 12 Nov 2007 05:26:34 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 2281 invoked by uid 500); 12 Nov 2007 05:26:34 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 2270 invoked by uid 500); 12 Nov 2007 05:26:34 -0000 Delivered-To: apmail-ws-axis2-cvs@ws.apache.org Received: (qmail 2267 invoked by uid 99); 12 Nov 2007 05:26:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Nov 2007 21:26:34 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Nov 2007 05:27:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6F8931A9832; Sun, 11 Nov 2007 21:26:21 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: axis2-cvs@ws.apache.org From: amilas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071112052621.6F8931A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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() { - + localTracker = false; 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 @@ + Compiling complexExtension.xsd + + + + + + + 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 @@ - @@ -45,6 +44,22 @@ + + + + + + + + + + + + + + + + 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 @@ + 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