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/13 11:03:09 UTC
svn commit: r537561 - in /webservices/axis2/trunk/java/modules/adb-codegen:
src/org/apache/axis2/schema/SchemaCompiler.java
test-resources/testsuite/testattribute.xsd
test/org/apache/axis2/schema/attribute/AttributeTest.java
Author: amilas
Date: Sun May 13 02:03:09 2007
New Revision: 537561
URL: http://svn.apache.org/viewvc?view=rev&rev=537561
Log:
fixed the attribute reference issue
Modified:
webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.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=537561&r1=537560&r2=537561
==============================================================================
--- 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 13 02:03:09 2007
@@ -1523,7 +1523,6 @@
public void processAttribute(XmlSchemaAttribute att, BeanWriterMetaInfoHolder metainf, XmlSchema parentSchema)
throws SchemaCompilationException {
- //for now we assume (!!!) that attributes refer to standard types only
QName schemaTypeName = att.getSchemaTypeName();
if (schemaTypeName != null) {
if (att.getQName() != null) {
@@ -1534,8 +1533,8 @@
// add optional attribute status if set
String use = att.getUse().getValue();
- if (USE_NONE.equals(use) || USE_OPTIONAL.equals(use)){
- metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
+ if (USE_NONE.equals(use) || USE_OPTIONAL.equals(use)) {
+ metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
}
String className = findClassName(schemaTypeName, false);
@@ -1569,50 +1568,34 @@
}
}
+ } else {
+ // this attribute has a type but does not have a name, seems to be invalid
}
} else if (att.getRefName() != null) {
XmlSchema currentParentSchema = resolveParentSchema(att.getRefName(), parentSchema);
- QName attrQname = generateAttributeQName(att.getRefName(), parentSchema);
-
- XmlSchemaObjectCollection items = currentParentSchema.getItems();
- Iterator itemIterator = items.getIterator();
-
- while (itemIterator.hasNext()) {
- Object attr = itemIterator.next();
+ QName attrQname = att.getRefName();
- if (attr instanceof XmlSchemaAttribute) {
- XmlSchemaAttribute attribute = (XmlSchemaAttribute) attr;
-
- if (attribute.getName().equals(att.getRefName().getLocalPart())) {
- QName attrTypeName = attribute.getSchemaTypeName();
-
- Object type = baseSchemaTypeMap.get(attrTypeName);
- if (type == null) {
- XmlSchemaSimpleType simpleType = attribute.getSchemaType();
- if (simpleType != null && simpleType.getContent() instanceof XmlSchemaSimpleTypeRestriction)
- {
- XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) simpleType.getContent();
- QName baseTypeName = restriction.getBaseTypeName();
- type = baseSchemaTypeMap.get(baseTypeName);
- attrQname = att.getRefName();
- }
- //TODO: Handle XmlSchemaSimpleTypeUnion and XmlSchemaSimpleTypeList
- }
+ XmlSchemaObjectTable xmlSchemaObjectTable = currentParentSchema.getAttributes();
- if (type != null) {
- metainf.registerMapping(attrQname, attrQname,
- type.toString(), SchemaConstants.ATTRIBUTE_TYPE);
- // add optional attribute status if set
- String use = att.getUse().getValue();
- if (USE_NONE.equals(use) || USE_OPTIONAL.equals(use)) {
- metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
- }
- }
- }
+ QName currentQName = null;
+ XmlSchemaAttribute xmlSchemaAttribute = null;
+ for (Iterator attributesIter = xmlSchemaObjectTable.getNames(); attributesIter.hasNext();) {
+ currentQName = (QName) attributesIter.next();
+ if (currentQName.getLocalPart().equals(attrQname.getLocalPart())) {
+ xmlSchemaAttribute = (XmlSchemaAttribute) xmlSchemaObjectTable.getItem(currentQName);
+ break;
}
}
+ if (xmlSchemaAttribute != null) {
+ // call recursively to process the schema
+ processAttribute(xmlSchemaAttribute, metainf, currentParentSchema);
+ } else {
+ throw new SchemaCompilationException("Attribute QName reference refer to an invalid attribute " +
+ attrQname);
+ }
+
} else {
// this attribute refers to a custom type, probably one of the extended simple types.\
QName attributeQName = att.getQName();
@@ -1644,8 +1627,12 @@
}
} else {
// TODO: handle the case when no attribute type specifed
+ log.warn("No attribute type has defined to the Attribute " + attributeQName);
}
+ } else {
+ throw new SchemaCompilationException("Attribute QName reference refer to an invalid attribute " +
+ attributeQName);
}
}
Modified: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd?view=diff&rev=537561&r1=537560&r2=537561
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd Sun May 13 02:03:09 2007
@@ -5,7 +5,7 @@
<xs:element name="TestElement1">
<xs:complexType>
- <xs:attribute name="attribute1" type="xs:int" />
+ <xs:attribute name="attribute1" type="xs:int"/>
</xs:complexType>
</xs:element>
<xs:element name="TestElement2">
@@ -20,17 +20,27 @@
</xs:element>
<xs:element name="TestElement4">
<xs:complexType>
- <xs:attribute name="attribute1" type="xs:string" use="required"/>
+ <xs:attribute name="attribute1" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="TestAttributeSimpleType">
<xs:complexType>
- <xs:attribute name="attribute1" >
+ <xs:attribute name="attribute1">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
+
+ <xs:element name="TestAttributeReferenceElement" type="tns:TestAttributeReferenceType"/>
+ <xs:attribute name="TestAttribute1" type="xs:string"/>
+ <xs:complexType name="TestAttributeReferenceType">
+ <xs:sequence>
+ <xs:element name="param1" type="xs:string"/>
+ <xs:element name="param2" type="xs:string"/>
+ </xs:sequence>
+ <xs:attribute use="optional" ref="tns:TestAttribute1"/>
+ </xs:complexType>
</xs:schema>
Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java?view=diff&rev=537561&r1=537560&r2=537561
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java Sun May 13 02:03:09 2007
@@ -162,4 +162,32 @@
fail();
}
}
+
+ public void testAttributeReferenceElement(){
+ TestAttributeReferenceElement testAttributeReferenceElement = new TestAttributeReferenceElement();
+ TestAttributeReferenceType testAttributeReferenceType = new TestAttributeReferenceType();
+ testAttributeReferenceType.setParam1("param1");
+ testAttributeReferenceType.setParam2("param2");
+ testAttributeReferenceType.setTestAttribute1("attribute1");
+
+ testAttributeReferenceElement.setTestAttributeReferenceElement(testAttributeReferenceType);
+
+ OMElement omElement = testAttributeReferenceElement.getOMElement(TestAttributeReferenceElement.MY_QNAME,
+ OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OM Element ==> " + omElementString);
+ XMLStreamReader xmlReader =
+ StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestAttributeReferenceElement result = TestAttributeReferenceElement.Factory.parse(xmlReader);
+
+ assertEquals(result.getTestAttributeReferenceElement().getParam1(),"param1");
+ assertEquals(result.getTestAttributeReferenceElement().getParam2(),"param2");
+ assertEquals(result.getTestAttributeReferenceElement().getTestAttribute1(),"attribute1");
+ } 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