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/21 05:52:04 UTC
svn commit: r540010 - in /webservices/axis2/trunk/java/modules/adb-codegen:
./ src/org/apache/axis2/schema/ test-resources/testsuite/
test/org/apache/axis2/schema/base64binary/
test/org/apache/axis2/schema/group/
Author: amilas
Date: Sun May 20 20:52:03 2007
New Revision: 540010
URL: http://svn.apache.org/viewvc?view=rev&rev=540010
Log:
fixed an attribute processing bug. and put attribute group support
Added:
webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/base64binary.xsd
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.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
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/GroupTest.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=540010&r1=540009&r2=540010
==============================================================================
--- 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 May 20 20:52:03 2007
@@ -968,15 +968,7 @@
}
//process attributes - first look for the explicit attributes
- XmlSchemaObjectCollection attribs = complexType.getAttributes();
- Iterator attribIterator = attribs.getIterator();
- while (attribIterator.hasNext()) {
- Object o = attribIterator.next();
- if (o instanceof XmlSchemaAttribute) {
- processAttribute((XmlSchemaAttribute) o, metaInfHolder, parentSchema);
-
- }
- }
+ processAttributes(complexType.getAttributes(),metaInfHolder,parentSchema);
//process any attribute
//somehow the xml schema parser does not seem to pickup the any attribute!!
@@ -985,6 +977,7 @@
processAnyAttribute(metaInfHolder, anyAtt);
}
+
//process content ,either complex or simple
if (complexType.getContentModel() != null) {
processContentModel(complexType.getContentModel(),
@@ -994,6 +987,47 @@
return metaInfHolder;
}
+ private void processAttributes(XmlSchemaObjectCollection attributes,
+ BeanWriterMetaInfoHolder metaInfHolder,
+ XmlSchema parentSchema) throws SchemaCompilationException {
+ Iterator attribIterator = attributes.getIterator();
+ while (attribIterator.hasNext()) {
+ Object o = attribIterator.next();
+ if (o instanceof XmlSchemaAttribute) {
+ processAttribute((XmlSchemaAttribute) o, metaInfHolder, parentSchema);
+ } else if (o instanceof XmlSchemaAttributeGroupRef){
+ processAttributeGroupReference((XmlSchemaAttributeGroupRef)o,metaInfHolder,parentSchema);
+ }
+ }
+ }
+
+ private void processAttributeGroupReference(XmlSchemaAttributeGroupRef attributeGroupRef,
+ BeanWriterMetaInfoHolder metaInfHolder,
+ XmlSchema parentSchema) throws SchemaCompilationException {
+
+ QName attributeGroupRefName = attributeGroupRef.getRefName();
+ if (attributeGroupRefName != null){
+ XmlSchemaObjectTable xmlSchemaObjectTable = parentSchema.getAttributeGroups();
+ XmlSchemaAttributeGroup xmlSchemaAttributeGroup = null;
+ for (Iterator iter = xmlSchemaObjectTable.getValues(); iter.hasNext();){
+ xmlSchemaAttributeGroup = (XmlSchemaAttributeGroup) iter.next();
+ if (xmlSchemaAttributeGroup.getName().equals(attributeGroupRefName.getLocalPart())){
+ break;
+ }
+ }
+
+ if (xmlSchemaAttributeGroup != null){
+ processAttributes(xmlSchemaAttributeGroup.getAttributes(),metaInfHolder,parentSchema);
+ } else {
+ throw new SchemaCompilationException("Can not find an attribute group for group reference"
+ + attributeGroupRefName.getLocalPart());
+ }
+ } else {
+ throw new SchemaCompilationException("No group refernce has given");
+ }
+
+ }
+
/**
* Process the content models. A content model is either simple type or a complex type
* and included inside a complex content
@@ -1597,7 +1631,8 @@
}
} else {
- // this attribute refers to a custom type, probably one of the extended simple types.\
+ // this attribute refers to a custom type, probably one of the extended simple types.
+ // with the inline scheam definition
QName attributeQName = att.getQName();
if (attributeQName != null) {
XmlSchemaSimpleType attributeSimpleType = att.getSchemaType();
@@ -1613,9 +1648,18 @@
QName schemaTypeQName = att.getSchemaTypeName();
if (schemaTypeQName == null) {
// set the parent schema target name space since attribute Qname uri is ""
- schemaTypeQName = new QName(parentSchema.getTargetNamespace(), attributeQName.getLocalPart() + getNextTypeSuffix());
+ if (attributeSimpleType.getQName() != null) {
+ schemaTypeQName = attributeSimpleType.getQName();
+ } else {
+ schemaTypeQName = new QName(parentSchema.getTargetNamespace(),
+ attributeQName.getLocalPart() + getNextTypeSuffix());
+
+ }
+ }
+ if (!isAlreadyProcessed(schemaTypeQName)){
+ // we have to process only if it has not processed
+ processSimpleSchemaType(attributeSimpleType, null, parentSchema, schemaTypeQName);
}
- processSimpleSchemaType(attributeSimpleType, null, parentSchema, schemaTypeQName);
metainf.registerMapping(att.getQName(),
schemaTypeQName,
processedTypemap.get(schemaTypeQName).toString(),
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=540010&r1=540009&r2=540010
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/sub-build.xml Sun May 20 20:52:03 2007
@@ -301,6 +301,17 @@
<arg file="${testsuite.source.dir}/groups.xsd"/>
<arg file="${schema.generated.src.dir}"/>
</java>
+
+ <!-- ################################################################### -->
+ <!-- All simple derived types xsd -->
+ <echo>Compiling base64binary.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}/base64binary.xsd"/>
+ <arg file="${schema.generated.src.dir}"/>
+ </java>
</target>
</project>
Added: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/base64binary.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/base64binary.xsd?view=auto&rev=540010
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/base64binary.xsd (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/base64binary.xsd Sun May 20 20:52:03 2007
@@ -0,0 +1,29 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
+ targetNamespace="http://www.w3.org/2005/05/xmlmime">
+ <xs:attribute name="contentType">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="3" />
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ <xs:attribute name="expectedContentTypes" type="xs:string" />
+ <xs:complexType name="base64Binary">
+ <xs:simpleContent>
+ <xs:extension base="xs:base64Binary">
+ <xs:attribute ref="xmime:contentType" />
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ <xs:complexType name="hexBinary">
+ <xs:simpleContent>
+ <xs:extension base="xs:hexBinary">
+ <xs:attribute ref="xmime:contentType" />
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ <xs:element name="TestBase64Binary" type="xmime:base64Binary"></xs:element>
+ <xs:element name="TestHexBinary" type="xmime:hexBinary"></xs:element>
+
+</xs:schema>
Modified: 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=diff&rev=540010&r1=540009&r2=540010
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/groups.xsd (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/groups.xsd Sun May 20 20:52:03 2007
@@ -60,4 +60,32 @@
<xs:group ref="tns:TestChoiceGroup"/>
</xs:choice>
</xs:group>
+
+ <xs:element name="TestAttributeGroupElement">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="param1" type="xs:string"/>
+ </xs:sequence>
+ <xs:attributeGroup ref="tns:TestAttributeGroup" />
+ </xs:complexType>
+ </xs:element>
+
+ <xs:attributeGroup name="TestAttributeGroup">
+ <xs:attribute name="attribute1" type="xs:string"/>
+ </xs:attributeGroup>
+
+ <xs:element name="TestNestedAttributeGroupElement">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="param1" type="xs:string"/>
+ </xs:sequence>
+ <xs:attributeGroup ref="tns:TestNestedAttributeGroup" />
+ </xs:complexType>
+ </xs:element>
+
+ <xs:attributeGroup name="TestNestedAttributeGroup">
+ <xs:attribute name="attribute2" type="xs:string"/>
+ <xs:attributeGroup ref="tns:TestAttributeGroup" />
+ </xs:attributeGroup>
+
</schema>
Added: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java?view=auto&rev=540010
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java Sun May 20 20:52:03 2007
@@ -0,0 +1,106 @@
+/*
+ * 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.base64binary;
+
+import org.w3.www._2005._05.xmlmime.*;
+import org.w3.www._2005._05.xmlmime.HexBinary;
+import org.apache.axiom.attachments.ByteArrayDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axis2.databinding.types.*;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+
+
+/**
+ * Author: amila
+ * Date: May 19, 2007
+ */
+public class Base64BinaryTest extends TestCase {
+
+ public void testBase64Binary(){
+ TestBase64Binary testBase64Binary = new TestBase64Binary();
+ Base64Binary base64Binary = new Base64Binary();
+ testBase64Binary.setTestBase64Binary(base64Binary);
+
+ String testString = "new test string";
+
+ DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(testString.getBytes()));
+ base64Binary.setBase64Binary(dataHandler);
+ ContentType_type0 contentType_type0 = new ContentType_type0();
+ contentType_type0.setContentType_type0("test content type");
+ base64Binary.setContentType(contentType_type0);
+
+ OMElement omElement = testBase64Binary.getOMElement(TestBase64Binary.MY_QNAME, OMAbstractFactory.getOMFactory());
+
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM String ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestBase64Binary result = TestBase64Binary.Factory.parse(xmlReader);
+ DataHandler resultDataHandler = result.getTestBase64Binary().getBase64Binary();
+ byte[] bytes = new byte[128];
+ int length = resultDataHandler.getInputStream().read(bytes);
+ String resultString = new String(bytes,0,length);
+ assertEquals(resultString,testString);
+ assertEquals(result.getTestBase64Binary().getContentType().getContentType_type0(),"test content type");
+ } catch (XMLStreamException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testHexBinary(){
+ TestHexBinary testHexBinary = new TestHexBinary();
+ HexBinary hexBinary = new HexBinary();
+ testHexBinary.setTestHexBinary(hexBinary);
+
+ String testString = "ab";
+
+ org.apache.axis2.databinding.types.HexBinary adbHexBinary =
+ new org.apache.axis2.databinding.types.HexBinary(testString);
+
+ hexBinary.setHexBinary(adbHexBinary);
+ ContentType_type0 contentType_type0 = new ContentType_type0();
+ contentType_type0.setContentType_type0("test content type");
+ hexBinary.setContentType(contentType_type0);
+
+ OMElement omElement = testHexBinary.getOMElement(TestBase64Binary.MY_QNAME, OMAbstractFactory.getOMFactory());
+
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM String ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestHexBinary result = TestHexBinary.Factory.parse(xmlReader);
+ assertEquals(result.getTestHexBinary().getHexBinary().toString(),testString);
+ assertEquals(result.getTestHexBinary().getContentType().getContentType_type0(),"test content type");
+ } catch (XMLStreamException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+
+}
Modified: 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=diff&rev=540010&r1=540009&r2=540010
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/group/GroupTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/group/GroupTest.java Sun May 20 20:52:03 2007
@@ -25,6 +25,9 @@
import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
+import group.test.axis2.apache.org.TestAttributeGroupElement;
+import group.test.axis2.apache.org.TestNestedAttributeGroupElement;
+
public class GroupTest extends TestCase {
@@ -144,5 +147,53 @@
fail();
}
}
+
+ public void testAttributeGroup(){
+ TestAttributeGroupElement testAttributeGroup = new TestAttributeGroupElement();
+ testAttributeGroup.setAttribute1("Attribute1");
+ testAttributeGroup.setParam1("Param1");
+
+ OMElement omElement =
+ testAttributeGroup.getOMElement(TestAttributeGroupElement.MY_QNAME,OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM Element ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestAttributeGroupElement result = TestAttributeGroupElement.Factory.parse(xmlReader);
+ assertEquals(result.getParam1(),"Param1");
+ assertEquals(result.getAttribute1(),"Attribute1");
+ } catch (XMLStreamException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+
+ }
+
+ public void testNestedAttributeGroup(){
+ TestNestedAttributeGroupElement testNestedAttributeGroupElement = new TestNestedAttributeGroupElement();
+ testNestedAttributeGroupElement.setAttribute1("Attribute1");
+ testNestedAttributeGroupElement.setAttribute2("Attribute2");
+ testNestedAttributeGroupElement.setParam1("Param1");
+
+ OMElement omElement =
+ testNestedAttributeGroupElement.getOMElement(TestNestedAttributeGroupElement.MY_QNAME,OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM Element ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestNestedAttributeGroupElement result = TestNestedAttributeGroupElement.Factory.parse(xmlReader);
+ assertEquals(result.getParam1(),"Param1");
+ assertEquals(result.getAttribute1(),"Attribute1");
+ assertEquals(result.getAttribute2(),"Attribute2");
+ } 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