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/03/22 12:02:58 UTC
svn commit: r521207 - 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/attribute/
Author: amilas
Date: Thu Mar 22 04:02:53 2007
New Revision: 521207
URL: http://svn.apache.org/viewvc?view=rev&rev=521207
Log:
Add the Attribute inline simpleType support. Fixed some minor mistakes.
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/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=521207&r1=521206&r2=521207
==============================================================================
--- 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 Thu Mar 22 04:02:53 2007
@@ -1505,20 +1505,18 @@
if (type instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
// we only support simple type restriction
- if (simpleType.getContent() instanceof XmlSchemaSimpleTypeRestriction) {
- if (!isAlreadyProcessed(schemaTypeName)) {
- //process simple type
- processSimpleSchemaType(simpleType, null, parentSchema, null);
- }
- metainf.registerMapping(att.getQName(),
- schemaTypeName,
- processedTypemap.get(schemaTypeName).toString(),
- SchemaConstants.ATTRIBUTE_TYPE);
- // add optional attribute status if set
- String use = att.getUse().getValue();
- if (use.indexOf("optional") != -1) {
- metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
- }
+ if (!isAlreadyProcessed(schemaTypeName)) {
+ //process simple type
+ processSimpleSchemaType(simpleType, null, parentSchema, null);
+ }
+ metainf.registerMapping(att.getQName(),
+ schemaTypeName,
+ processedTypemap.get(schemaTypeName).toString(),
+ SchemaConstants.ATTRIBUTE_TYPE);
+ // add optional attribute status if set
+ String use = att.getUse().getValue();
+ if (use.indexOf("optional") != -1) {
+ metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
}
}
}
@@ -1567,8 +1565,27 @@
}
} else {
- //todo his attribute refers to a custom type, probably one of the extended simple types.
- //todo handle it here
+ // this attribute refers to a custom type, probably one of the extended simple types.\
+ QName attributeQName = att.getQName();
+ if (attributeQName != null) {
+ XmlSchemaSimpleType attributeSimpleType = att.getSchemaType();
+ 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());
+ }
+ processSimpleSchemaType(attributeSimpleType, null, parentSchema, schemaTypeQName);
+ metainf.registerMapping(att.getQName(),
+ schemaTypeQName,
+ processedTypemap.get(schemaTypeQName).toString(),
+ SchemaConstants.ATTRIBUTE_TYPE);
+ // add optional attribute status if set
+ String use = att.getUse().getValue();
+ if (use.indexOf("optional") != -1) {
+ metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
+ }
+ }
+
}
}
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?view=diff&rev=521207&r1=521206&r2=521207
==============================================================================
--- 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 Thu Mar 22 04:02:53 2007
@@ -511,8 +511,8 @@
}
</xsl:when>
<xsl:when test="(@maxLenFacet) or (@minLenFacet)">
- if ( <xsl:if test="(@minLenFacet)"> (<xsl:value-of select="$minLenFacet"/> < java.lang.String.valueOf(param).length())</xsl:if>
- <xsl:if test="(@maxLenFacet)"> <xsl:if test="(@minLenFacet)"> && </xsl:if> (java.lang.String.valueOf(param).length() >= <xsl:value-of select="$maxLenFacet"/>) </xsl:if> ) {
+ if ( <xsl:if test="(@minLenFacet)"> (<xsl:value-of select="$minLenFacet"/> <= java.lang.String.valueOf(param).length())</xsl:if>
+ <xsl:if test="(@maxLenFacet)"> <xsl:if test="(@minLenFacet)"> && </xsl:if> (java.lang.String.valueOf(param).length() <= <xsl:value-of select="$maxLenFacet"/>) </xsl:if> ) {
this.<xsl:value-of select="$varName"/>=param;
}
else {
@@ -1725,10 +1725,10 @@
java.lang.String prefix = xmlWriter.getPrefix(namespace);
if (prefix == null) {
- prefix = createPrefix();
+ prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
- prefix = createPrefix();
+ prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}
xmlWriter.writeNamespace(prefix, namespace);
@@ -1737,13 +1737,6 @@
return prefix;
}
-
- /**
- * Create a prefix
- */
- private java.lang.String createPrefix() {
- return "ns" + (int)Math.random();
- }
<!-- ######################################################################################### -->
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=521207&r1=521206&r2=521207
==============================================================================
--- 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 Thu Mar 22 04:02:53 2007
@@ -23,5 +23,14 @@
<xs:attribute name="attribute1" type="xs:string"/>
</xs:complexType>
</xs:element>
+ <xs:element name="TestAttributeSimpleType">
+ <xs:complexType>
+ <xs:attribute name="attribute1" >
+ <xs:simpleType>
+ <xs:restriction base="xs:string"/>
+ </xs:simpleType>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
</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=521207&r1=521206&r2=521207
==============================================================================
--- 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 Thu Mar 22 04:02:53 2007
@@ -19,12 +19,10 @@
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.util.StAXUtils;
-import org.tempuri.attribute.TestElement1;
-import org.tempuri.attribute.TestElement2;
-import org.tempuri.attribute.TestElement3;
-import org.tempuri.attribute.TestElement4;
+import org.tempuri.attribute.*;
import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
import java.io.ByteArrayInputStream;
public class AttributeTest extends TestCase {
@@ -143,6 +141,25 @@
fail();
} catch (Exception e) {
assertTrue(true);
+ }
+ }
+
+ public void testAttributeSimpleType(){
+ TestAttributeSimpleType testAttributeSimpleType = new TestAttributeSimpleType();
+ Attribute1_type0 attribute1_type0 = new Attribute1_type0();
+ attribute1_type0.setAttribute1_type0("test attribute");
+ testAttributeSimpleType.setAttribute1(attribute1_type0);
+
+ OMElement omElement = testAttributeSimpleType.getOMElement(TestAttributeSimpleType.MY_QNAME,
+ OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMString ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestAttributeSimpleType result = TestAttributeSimpleType.Factory.parse(xmlReader);
+ assertEquals(result.getAttribute1().getAttribute1_type0(),"test attribute");
+ } 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