You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by am...@apache.org on 2007/05/14 14:39:11 UTC
svn commit: r537802 - in /webservices/axis2/trunk/java/modules/adb-codegen:
./ src/org/apache/axis2/schema/ test-resources/testsuite/
test/org/apache/axis2/schema/group/
Author: amilas
Date: Mon May 14 05:39:10 2007
New Revision: 537802
URL: http://svn.apache.org/viewvc?view=rev&rev=537802
Log:
Added the group support to ADB
Added:
webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/groups.xsd
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/group/
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/group/GroupTest.java
Modified:
webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml
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=537802&r1=537801&r2=537802
==============================================================================
--- 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 Mon May 14 05:39:10 2007
@@ -1839,6 +1839,37 @@
}
}
+ } else if (item instanceof XmlSchemaGroupRef) {
+
+ XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) item;
+ QName groupQName = xmlSchemaGroupRef.getRefName();
+ if (groupQName != null){
+ if (!processedTypemap.containsKey(groupQName)){
+ // processe the schema here
+ //TODO: get the xmlSchemaGroup correctly when it is in another schema.
+ XmlSchemaObjectTable xmlSchemaObjectTable = parentSchema.getGroups();
+ XmlSchemaGroup xmlSchemaGroup = null;
+ for (Iterator groupsIter = xmlSchemaObjectTable.getValues(); groupsIter.hasNext();){
+ xmlSchemaGroup = (XmlSchemaGroup) groupsIter.next();
+ if (xmlSchemaGroup.getName().equals(groupQName.getLocalPart())){
+ break;
+ }
+ }
+ processGroup(xmlSchemaGroup, groupQName, parentSchema);
+ }
+
+ Boolean isArray = xmlSchemaGroupRef.getMaxOccurs() > 1 ? Boolean.TRUE : Boolean.FALSE;
+ processedElementArrayStatusMap.put(item,isArray);
+ particleQNameMap.put(item,groupQName);
+
+ if (order){
+ elementOrderMap.put(item, new Integer(sequenceCounter));
+ }
+
+ } else {
+ throw new SchemaCompilationException("Referenced name is null");
+ }
+
} else if (order && (item instanceof XmlSchemaChoice)) {
// this is a tempory patch for process only inner sequence choices
@@ -2032,11 +2063,74 @@
metainfHolder.registerQNameIndex(choiceQName,
startingItemNumberOrder + integer.intValue());
}
+ } else if (child instanceof XmlSchemaGroupRef) {
+ XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) child;
+ QName groupQName = (QName) particleQNameMap.get(child);
+ boolean isArray = xmlSchemaGroupRef.getMaxOccurs() > 1;
+
+ // add this as an array to the original class
+ metainfHolder.registerMapping(groupQName,
+ groupQName,
+ findClassName(groupQName, isArray));
+ if (isArray) {
+ metainfHolder.addtStatus(groupQName, SchemaConstants.ARRAY_TYPE);
+ }
+ metainfHolder.addtStatus(groupQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
+ metainfHolder.addMaxOccurs(groupQName, xmlSchemaGroupRef.getMaxOccurs());
+ metainfHolder.addMinOccurs(groupQName, xmlSchemaGroupRef.getMinOccurs());
+ metainfHolder.setHasParticleType(true);
+
+ if (order) {
+ //record the order in the metainf holder for the any
+ Integer integer = (Integer) elementOrderMap.get(child);
+ metainfHolder.registerQNameIndex(groupQName,
+ startingItemNumberOrder + integer.intValue());
+ }
}
}
//set the ordered flag in the metainf holder
metainfHolder.setOrdered(order);
+ }
+
+ /**
+ *
+ * @param xmlSchemaGroup
+ * @param schemaGroupQName- we have to pass this since xml schema does not provide
+ * this properly
+ * @param parentSchema
+ * @throws SchemaCompilationException
+ */
+
+ private void processGroup(XmlSchemaGroup xmlSchemaGroup,
+ QName schemaGroupQName,
+ XmlSchema parentSchema) throws SchemaCompilationException {
+
+ // find the group base item
+ XmlSchemaGroupBase xmlSchemaGroupBase = xmlSchemaGroup.getParticle();
+ if (xmlSchemaGroupBase != null){
+ if (xmlSchemaGroupBase instanceof XmlSchemaSequence){
+ XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) xmlSchemaGroupBase;
+ if (xmlSchemaSequence.getItems().getCount() > 0) {
+ BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
+ process(schemaGroupQName, xmlSchemaSequence.getItems(), beanWriterMetaInfoHolder, true, parentSchema);
+ beanWriterMetaInfoHolder.setParticleClass(true);
+ String javaClassName = writeComplexParticle(schemaGroupQName, beanWriterMetaInfoHolder);
+ processedTypemap.put(schemaGroupQName, javaClassName);
+ }
+
+ } else if (xmlSchemaGroupBase instanceof XmlSchemaChoice){
+ XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice) xmlSchemaGroupBase;
+ if (xmlSchemaChoice.getItems().getCount() > 0) {
+ BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
+ beanWriterMetaInfoHolder.setChoice(true);
+ process(schemaGroupQName, xmlSchemaChoice.getItems(), beanWriterMetaInfoHolder, false, parentSchema);
+ beanWriterMetaInfoHolder.setParticleClass(true);
+ String javaClassName = writeComplexParticle(schemaGroupQName, beanWriterMetaInfoHolder);
+ processedTypemap.put(schemaGroupQName, javaClassName);
+ }
+ }
+ }
}
private XmlSchemaType getType(XmlSchema schema, QName schemaTypeName) throws SchemaCompilationException {
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?view=diff&rev=537802&r1=537801&r2=537802
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml Mon May 14 05:39:10 2007
@@ -290,6 +290,17 @@
<arg file="${testsuite.source.dir}/default_namespaces.xsd"/>
<arg file="${schema.generated.src.dir}"/>
</java>
- </target>
+
+ <!-- ################################################################### -->
+ <!-- All simple derived types xsd -->
+ <echo>Compiling groups.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}/groups.xsd"/>
+ <arg file="${schema.generated.src.dir}"/>
+ </java>
+ </target>
</project>
Added: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/groups.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/groups.xsd?view=auto&rev=537802
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/groups.xsd (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/groups.xsd Mon May 14 05:39:10 2007
@@ -0,0 +1,63 @@
+<schema elementFormDefault="qualified"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="org.apache.axis2.test.group"
+ targetNamespace="org.apache.axis2.test.group">
+
+ <xs:element name="TestSequenceGroupElement">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="param1" type="xs:string"/>
+ <xs:group ref="tns:TestSequenceGroup"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:group name="TestSequenceGroup">
+ <xs:sequence>
+ <xs:element name="sequenceParam1" type="xs:string"/>
+ <xs:element name="sequenceParam2" type="xs:string"/>
+ </xs:sequence>
+ </xs:group>
+ <xs:element name="TestChoiceGroupElement">
+ <xs:complexType>
+ <xs:choice>
+ <xs:element name="param1" type="xs:string"/>
+ <xs:group ref="tns:TestChoiceGroup"/>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+ <xs:group name="TestChoiceGroup">
+ <xs:choice>
+ <xs:element name="choiceParam1" type="xs:string"/>
+ <xs:element name="choiceParam2" type="xs:string"/>
+ </xs:choice>
+ </xs:group>
+ <xs:element name="TestSequenceNestedGroupElement">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="param1" type="xs:string"/>
+ <xs:group ref="tns:TestSequenceNestedGroup"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:group name="TestSequenceNestedGroup">
+ <xs:sequence>
+ <xs:element name="nestedSequenceParam1" type="xs:string"/>
+ <xs:group ref="tns:TestSequenceGroup"/>
+ </xs:sequence>
+ </xs:group>
+ <xs:element name="TestChoiceNestedGroupElement">
+ <xs:complexType>
+ <xs:choice>
+ <xs:element name="param1" type="xs:string"/>
+ <xs:group ref="tns:TestChoiceNestedGroup"/>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+ <xs:group name="TestChoiceNestedGroup">
+ <xs:choice>
+ <xs:element name="nestedChoiceParam1" type="xs:string"/>
+ <xs:group ref="tns:TestChoiceGroup"/>
+ </xs:choice>
+ </xs:group>
+</schema>
\ No newline at end of file
Added: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/group/GroupTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/group/GroupTest.java?view=auto&rev=537802
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/group/GroupTest.java (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/group/GroupTest.java Mon May 14 05:39:10 2007
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2004,2005 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.axis2.schema.group;
+
+import junit.framework.TestCase;
+import group.test.axis2.apache.org.*;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.util.StAXUtils;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.ByteArrayInputStream;
+
+
+public class GroupTest extends TestCase {
+
+ public void testSequenceGroupElement(){
+
+ TestSequenceGroupElement testGroupSequenceElement = new TestSequenceGroupElement();
+ testGroupSequenceElement.setParam1("param1");
+ TestSequenceGroup testSequenceGroup = new TestSequenceGroup();
+ testSequenceGroup.setSequenceParam1("sequenceParam1");
+ testSequenceGroup.setSequenceParam2("sequenceParam2");
+ testGroupSequenceElement.setTestSequenceGroup(testSequenceGroup);
+
+ OMElement omElement =
+ testGroupSequenceElement.getOMElement(TestSequenceGroupElement.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM String ==> " + omElementString);
+ XMLStreamReader xmlReader =
+ StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestSequenceGroupElement result = TestSequenceGroupElement.Factory.parse(xmlReader);
+ assertEquals(result.getParam1(),"param1");
+ assertEquals(result.getTestSequenceGroup().getSequenceParam1(),"sequenceParam1");
+ assertEquals(result.getTestSequenceGroup().getSequenceParam2(),"sequenceParam2");
+ } catch (XMLStreamException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testNestedSequenceGroupElement(){
+
+ TestSequenceNestedGroupElement testSequenceNestedGroupElement = new TestSequenceNestedGroupElement();
+ testSequenceNestedGroupElement.setParam1("param1");
+
+ TestSequenceNestedGroup testSequenceNestedGroup = new TestSequenceNestedGroup();
+ testSequenceNestedGroup.setNestedSequenceParam1("nestedSequenceParam1");
+
+ TestSequenceGroup testSequenceGroup = new TestSequenceGroup();
+ testSequenceGroup.setSequenceParam1("sequenceParam1");
+ testSequenceGroup.setSequenceParam2("sequenceParam2");
+
+ testSequenceNestedGroup.setTestSequenceGroup(testSequenceGroup);
+
+ testSequenceNestedGroupElement.setTestSequenceNestedGroup(testSequenceNestedGroup);
+
+ OMElement omElement =
+ testSequenceNestedGroupElement.getOMElement(TestSequenceNestedGroupElement.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM String ==> " + omElementString);
+ XMLStreamReader xmlReader =
+ StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestSequenceNestedGroupElement result = TestSequenceNestedGroupElement.Factory.parse(xmlReader);
+ assertEquals(result.getParam1(),"param1");
+ assertEquals(result.getTestSequenceNestedGroup().getNestedSequenceParam1(),"nestedSequenceParam1");
+ assertEquals(result.getTestSequenceNestedGroup().getTestSequenceGroup().getSequenceParam1(),"sequenceParam1");
+ assertEquals(result.getTestSequenceNestedGroup().getTestSequenceGroup().getSequenceParam2(),"sequenceParam2");
+ } catch (XMLStreamException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testChoiceGroupElement(){
+
+ TestChoiceGroupElement testGroupChoiceElement = new TestChoiceGroupElement();
+ testGroupChoiceElement.setParam1("param1");
+ TestChoiceGroup testChoiceGroup = new TestChoiceGroup();
+ testChoiceGroup.setChoiceParam1("choiceParam1");
+ testGroupChoiceElement.setTestChoiceGroup(testChoiceGroup);
+
+ OMElement omElement =
+ testGroupChoiceElement.getOMElement(TestChoiceGroupElement.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM String ==> " + omElementString);
+ XMLStreamReader xmlReader =
+ StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestChoiceGroupElement result = TestChoiceGroupElement.Factory.parse(xmlReader);
+ assertEquals(result.getTestChoiceGroup().getChoiceParam1(),"choiceParam1");
+ } catch (XMLStreamException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testNestedChoiceGroupElement(){
+
+ TestChoiceNestedGroupElement testChoiceNestedGroupElement = new TestChoiceNestedGroupElement();
+ testChoiceNestedGroupElement.setParam1("param1");
+
+ TestChoiceNestedGroup testChoiceNestedGroup = new TestChoiceNestedGroup();
+ testChoiceNestedGroup.setNestedChoiceParam1("nestedChoiceParam1");
+
+ TestChoiceGroup testChoiceGroup = new TestChoiceGroup();
+ testChoiceGroup.setChoiceParam1("choiceParam1");
+
+ testChoiceNestedGroup.setTestChoiceGroup(testChoiceGroup);
+
+ testChoiceNestedGroupElement.setTestChoiceNestedGroup(testChoiceNestedGroup);
+
+ OMElement omElement =
+ testChoiceNestedGroupElement.getOMElement(testChoiceNestedGroupElement.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM String ==> " + omElementString);
+ XMLStreamReader xmlReader =
+ StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestChoiceNestedGroupElement result = TestChoiceNestedGroupElement.Factory.parse(xmlReader);
+ assertEquals(result.getTestChoiceNestedGroup().getTestChoiceGroup().getChoiceParam1(),"choiceParam1");
+ } 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