You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by aj...@apache.org on 2006/04/28 08:01:33 UTC
svn commit: r397776 - in /webservices/axis2/trunk/java/modules/codegen: ./
src/org/apache/axis2/schema/template/ test-resources/xsd/
test/org/apache/axis2/schema/populate/other/
Author: ajith
Date: Thu Apr 27 23:01:32 2006
New Revision: 397776
URL: http://svn.apache.org/viewcvs?rev=397776&view=rev
Log:
1. modified the ADBBeanTemplate.xsl so that it parses the minOccurs=0 and resursive datatypes properly. Thanks chuck for the patches and support
2. Added a new test case to check the use of choice and sequence together
3. Modified the tests to suit the situation since in the minoccurs case the array output is null - not en empty array
Added:
webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/mixed_minoccus0.xsd
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMixedMinoccurs0Test.java
Modified:
webservices/axis2/trunk/java/modules/codegen/maven.xml
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java
Modified: webservices/axis2/trunk/java/modules/codegen/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/maven.xml?rev=397776&r1=397775&r2=397776&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/codegen/maven.xml Thu Apr 27 23:01:32 2006
@@ -119,6 +119,15 @@
<arg file="${schema.source.dir}/simple-recursive-datatypes.xsd"/>
<arg file="${schema.generated.src.dir}"/>
</java>
+
+ <ant:echo>Compiling mixed_minoccus0.xsd</ant: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="${schema.source.dir}/mixed_minoccus0.xsd"/>
+ <arg file="${schema.generated.src.dir}"/>
+ </java>
<!-- ################################################################### -->
<!-- All simple primitive types xsd -->
<java classname="org.apache.axis2.schema.XSD2Java" fork="true">
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?rev=397776&r1=397775&r2=397776&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl Thu Apr 27 23:01:32 2006
@@ -431,11 +431,12 @@
- <xsl:choose>
- <xsl:when test="@choice">
<!-- start of template for choice/all. Select either for the
presence of choice or the absence of ordered
+
+ Note :For now the order in the sequence is not enforced. The
+ following template is used for sequence also
-->
/**
* Factory class that keeps the parse method
@@ -448,6 +449,7 @@
// happens with outer (document) elements, but not with inner elements. The root bug is in OMStAXWrapper.java, which is now part
// of commons and so cannot just be fixed in axis2. This method should be removed and the calls to it below replaced with
// simple calls to getElementText() as soon as this serious bug can be fixed.
+
private static String getElementTextProperly(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception {
String value = reader.getElementText();
while (!reader.isEndElement())
@@ -457,16 +459,23 @@
/**
* static method to create the object
+ * Precondition: If this object is an element, the current or next start element starts this object and any intervening reader events are ignorable
+ * If this object is not an element, it is a complex type and the reader is at the event just after the outer start element
+ * Postcondition: If this object is an element, the reader is positioned at its end element
+ * If this object is a complex type, the reader is positioned at the end element of its outer element
*/
public static <xsl:value-of select="$name"/> parse(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
<xsl:value-of select="$name"/> object = new <xsl:value-of select="$name"/>();
try {
- // We should already be at our outer StartElement, but make sure
- while (!reader.isStartElement())
+ <!-- Advance to our start element, or if we are a complex type, to our first property start element or the outer end element if no properties -->
+ while (!reader.isStartElement() && !reader.isEndElement())
reader.next();
<xsl:if test="@nillable">
if ("true".equals(reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","nil"))){
+ // Skip the element and report the null value. It cannot have subelements.
+ while (!reader.isEndElement())
+ reader.next();
return null;
}
</xsl:if>
@@ -493,16 +502,21 @@
<xsl:if test="$isType or $anon">
<!-- Skip the outer start element in order to process the subelements. -->
reader.next();
- </xsl:if> <!-- If we are not a type and not an element with anonymous type, then we are an element with one property for our named type. -->
- <!-- Our single named-type property applies to our entire outer element, so don't skip it. -->
+ </xsl:if>
+ <!-- If we are not a type and not an element with anonymous type, then we are an element with one property for our named type. -->
+ <!-- Our single named-type property applies to our entire outer element, so don't skip it. -->
<!-- First loop creates arrayLists for handling arrays -->
<xsl:for-each select="property">
<xsl:if test="@array">
java.util.ArrayList list<xsl:value-of select="position()"/> = new java.util.ArrayList();
</xsl:if>
</xsl:for-each>
+
+ <xsl:if test="$choice"> <!-- If choice, properties can be in any order -->
while(!reader.isEndElement()) {
if (reader.isStartElement()){
+ </xsl:if>
+
<!-- Now reloop and populate the code -->
<xsl:for-each select="property">
<xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
@@ -518,7 +532,20 @@
<xsl:variable name="namespace"><xsl:value-of select="@nsuri"/></xsl:variable>
<xsl:variable name="min"><xsl:value-of select="@minOccurs"/></xsl:variable>
- <xsl:if test="position()>1">else</xsl:if> if ("<xsl:value-of select="$propertyName"/>".equals(reader.getLocalName())){
+ <xsl:variable name="propQName">new javax.xml.namespace.QName("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>")</xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="$choice"> <!-- One property per iteration if choice -->
+ <xsl:if test="position()>1">
+ else
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise> <!-- If sequence, advance to start of next property or to end of outer element -->
+ while (!reader.isStartElement() && !reader.isEndElement())
+ reader.next();
+ </xsl:otherwise>
+ </xsl:choose>
+ if (reader.isStartElement() && <xsl:value-of select="$propQName"/>.equals(reader.getName())){
<xsl:choose>
<xsl:when test="@array">
<!-- We must be a named type or element with anonymous type. -->
@@ -540,7 +567,7 @@
//two continuous end elements means we are exiting the xml structure
<xsl:value-of select="$loopBoolName"/> = true;
} else if (reader.isStartElement()){
- if ("<xsl:value-of select="$propertyName"/>".equals(reader.getLocalName())){
+ if (<xsl:value-of select="$propQName"/>.equals(reader.getName())){
<xsl:value-of select="$listName"/>.add(<xsl:value-of select="$basePropertyType"/>.Factory.parse(reader));
}else{
<xsl:value-of select="$loopBoolName"/> = true;
@@ -614,7 +641,7 @@
//two continuous end elements means we are exiting the xml structure
<xsl:value-of select="$loopBoolName"/> = true;
}else if (reader.isStartElement()){
- if ("<xsl:value-of select="$propertyName"/>".equals(reader.getLocalName())){
+ if (<xsl:value-of select="$propQName"/>.equals(reader.getName())){
<xsl:value-of select="$listName"/>.add(getElementTextProperly(reader));
}else{
<xsl:value-of select="$loopBoolName"/> = true;
@@ -692,15 +719,25 @@
</xsl:otherwise>
</xsl:choose>
- }
+ } // End of if for expected property start element
+ <xsl:if test="not($choice) and $min!=0">
+ else{
+ // A start element we are not expecting indicates an invalid parameter was passed
+ throw new java.lang.RuntimeException("Unexpected subelement " + reader.getLocalName());
+ }
+ </xsl:if>
</xsl:for-each>
- else
- // A start element we are not expecting indicates an invalid parameter was passed
- throw new java.lang.RuntimeException("Unexpected subelement " + reader.getLocalName());
- } else reader.next(); <!-- At neither a start nor an end element, skip it -->
- }
+ <xsl:if test="$choice">
+ else{
+ // A start element we are not expecting indicates an invalid parameter was passed
+ throw new java.lang.RuntimeException("Unexpected subelement " + reader.getLocalName());
+ }
+ } else reader.next(); <!-- At neither a start nor an end element, skip it -->
+ } // end of while loop
+ </xsl:if>
+
} catch (javax.xml.stream.XMLStreamException e) {
throw new java.lang.Exception(e);
@@ -712,412 +749,7 @@
}//end of factory class
<!-- end of template for choice/all -->
- </xsl:when>
- <!--
- Start of the template that generates the factory class for the sequence
- we select this template if the ordered attribute is present
- -->
- <xsl:otherwise>
-
- /**
- * Factory class that keeps the parse method
- */
- public static class Factory{
-
- /**
- * static method to create the object
- */
- public static <xsl:value-of select="$name"/> parse(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
- <xsl:value-of select="$name"/> object = new <xsl:value-of select="$name"/>();
- try {
- int event = reader.getEventType();
-
- //event better be a START_ELEMENT. if not we should go up to the start element here
- while (event!= javax.xml.stream.XMLStreamReader.START_ELEMENT) {
- event = reader.next();
- }
-
- <xsl:if test="not(@type)">
- if (!MY_QNAME.equals(reader.getName())){
- throw new Exception("Wrong QName");
- }
- </xsl:if>
-
- <xsl:if test="@nillable">
- if ("true".equals(reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","nil"))){
- return null;
- }
- </xsl:if>
-
- <!-- populate attributes here!!!. The attributes are part of an element, not part of a
- type -->
- <xsl:for-each select="property[@attribute]">
- <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
- <xsl:variable name="propertyType"><xsl:value-of select="@type"/></xsl:variable>
- <xsl:variable name="shortTypeName"><xsl:value-of select="@shorttypename"/></xsl:variable>
- <xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
- <xsl:variable name="namespace"><xsl:value-of select="@nsuri"/></xsl:variable>
- <xsl:variable name="attribName">tempAttrib<xsl:value-of select="$propertyName"/></xsl:variable>
-
- java.lang.String <xsl:value-of select="$attribName"/> =
- reader.getAttributeValue("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>");
- if (<xsl:value-of select="$attribName"/>!=null){
- object.set<xsl:value-of select="$javaName"/>(
- org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
- <xsl:value-of select="$attribName"/>));
- }
-
- </xsl:for-each>
-
- <!-- Now reloop and populate the code for non-attribute values-->
- <xsl:for-each select="property[not(@attribute)]">
- <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
- <xsl:variable name="propertyType"><xsl:value-of select="@type"/></xsl:variable>
- <xsl:variable name="shortTypeName"><xsl:value-of select="@shorttypename"/></xsl:variable>
- <xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
- <xsl:variable name="listName">list<xsl:value-of select="position()"/></xsl:variable>
- <xsl:variable name="loopBoolName">loopDone<xsl:value-of select="position()"/></xsl:variable>
- <xsl:variable name="skipBoolName">skip<xsl:value-of select="position()"/></xsl:variable>
- <xsl:variable name="startQname">startQname<xsl:value-of select="position()"/></xsl:variable>
- <xsl:variable name="stateMachineName">stateMachine<xsl:value-of select="position()"/></xsl:variable>
- <xsl:variable name="builderName">builder<xsl:value-of select="position()"/></xsl:variable>
- <xsl:variable name="basePropertyType"><xsl:value-of select="@arrayBaseType"/></xsl:variable>
- <xsl:variable name="namespace"><xsl:value-of select="@nsuri"/></xsl:variable>
- <xsl:variable name="min"><xsl:value-of select="@minOccurs"/></xsl:variable>
- <xsl:variable name="nillable"><xsl:value-of select="@nillable"/></xsl:variable>
-
-
- <xsl:choose>
- <!-- Start of array handling code -->
- <xsl:when test="@array">
- <xsl:choose>
- <xsl:when test="@ours">
- <!-- Somebody put the magic number 5000 here. I wonder who did that! -->
- java.util.ArrayList <xsl:value-of select="$listName"/> = new java.util.ArrayList();
- <!-- Start of Array handling of ADB classes -->
- boolean <xsl:value-of select="$loopBoolName"/>=false;
- boolean <xsl:value-of select="$skipBoolName"/>=false;
-
- javax.xml.namespace.QName <xsl:value-of select="$startQname"/> = new javax.xml.namespace.QName(
- "<xsl:value-of select="$namespace"/>",
- "<xsl:value-of select="$propertyName"/>");
-
- // Find the first element
- while (!<xsl:value-of select="$loopBoolName"/>){
- event = reader.getEventType();
- if (javax.xml.stream.XMLStreamConstants.START_ELEMENT == event
- && <xsl:value-of select="$startQname"/>.equals(reader.getName())){
- //we are at the first element
- <xsl:value-of select="$loopBoolName"/> = true;
- <xsl:if test="$min=0">
- }else if (javax.xml.stream.XMLStreamConstants.END_ELEMENT == event
- && !<xsl:value-of select="$startQname"/>.equals(reader.getName())){
- //we've found an end element that does not belong to this type
- //since this can occur zero times, this may well be empty.
-
- object.set<xsl:value-of select="$javaName"/>(
- (<xsl:value-of select="$propertyType"/>)
- org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(
- <xsl:value-of select="$basePropertyType"/>.class,<xsl:value-of select="$listName"/>));
- <xsl:value-of select="$skipBoolName"/>=true;
- break;
-
- </xsl:if>
- }else{
- reader.next();
- }
-
- }
-
- //Now loop and populate the array
- <xsl:value-of select="$loopBoolName"/> = false;
- if (!<xsl:value-of select="$skipBoolName"/>){
- while (!<xsl:value-of select="$loopBoolName"/>){
- event = reader.getEventType();
- if (javax.xml.stream.XMLStreamConstants.START_ELEMENT == event
- && <xsl:value-of select="$startQname"/>.equals(reader.getName())){
- if (org.apache.axis2.databinding.utils.Constants.TRUE.equals(
- reader.getAttributeValue(
- org.apache.axis2.databinding.utils.Constants.XSI_NAMESPACE,
- org.apache.axis2.databinding.utils.Constants.NIL))){
- <xsl:value-of select="$listName"/>.add(null);
- }else{
- <xsl:value-of select="$listName"/>.add(<xsl:value-of select="$basePropertyType"/>.Factory.parse(reader));
- }
-
-
- }else if (javax.xml.stream.XMLStreamConstants.START_ELEMENT == event
- && !<xsl:value-of select="$startQname"/>.equals(reader.getName())){
- <xsl:value-of select="$loopBoolName"/> = true;
- }else if (javax.xml.stream.XMLStreamConstants.END_ELEMENT == event &&
- !<xsl:value-of select="$startQname"/>.equals(reader.getName())){
- <xsl:value-of select="$loopBoolName"/> = true;
- }else{
- reader.next();
- }
-
- }
-
- object.set<xsl:value-of select="$javaName"/>(
- (<xsl:value-of select="$propertyType"/>)
- org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(
- <xsl:value-of select="$basePropertyType"/>.class,<xsl:value-of select="$listName"/>));
-
- } //end of skip
-
- //move to the next event, probably past the last end_element event
- if (reader.getEventType()== javax.xml.stream.XMLStreamConstants.END_ELEMENT){
- reader.next();
- }
- </xsl:when>
- <xsl:when test="@default">
- <!-- Somebody put the magic number 5000 here. I wonder who did that! -->
- java.util.ArrayList <xsl:value-of select="$listName"/> = new java.util.ArrayList();
- boolean <xsl:value-of select="$loopBoolName"/>=false;
- javax.xml.namespace.QName <xsl:value-of select="$startQname"/> = new javax.xml.namespace.QName(
- "<xsl:value-of select="$namespace"/>",
- "<xsl:value-of select="$propertyName"/>");
- <xsl:variable name="internalLoopVar"><xsl:value-of select="$loopBoolName"/>_internal</xsl:variable>
- boolean <xsl:value-of select="$internalLoopVar"/> = false;
-
- while(!<xsl:value-of select="$internalLoopVar"/>){
- if (reader.isStartElement() && <xsl:value-of select="$startQname"/>.equals(reader.getName())){
- <xsl:value-of select="$internalLoopVar"/> = true;
- }else{
- reader.next();
- }
- }
-
- while (!<xsl:value-of select="$loopBoolName"/>){
- event = reader.getEventType();
- if (javax.xml.stream.XMLStreamConstants.START_ELEMENT == event
- && <xsl:value-of select="$startQname"/>.equals(reader.getName())){
-
- <!-- if-block that handles nillable -->
- <xsl:if test="@nillable">
- if ("true".equals(reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","nil"))){
- <xsl:value-of select="$listName"/>.add(null);
- }else{
- </xsl:if>
-
- // We need to wrap the reader so that it produces a fake START_DOCUEMENT event
- org.apache.axis2.databinding.utils.NamedStaxOMBuilder <xsl:value-of select="$builderName"/>
- = new org.apache.axis2.databinding.utils.NamedStaxOMBuilder(
- new org.apache.axis2.util.StreamWrapper(reader), <xsl:value-of select="$startQname"/>);
-
- <xsl:value-of select="$listName"/>.add(<xsl:value-of select="$builderName"/>.getOMElement());
- <xsl:if test="@nillable">}</xsl:if>
- } else if (javax.xml.stream.XMLStreamConstants.START_ELEMENT == event &&
- !<xsl:value-of select="$startQname"/>.equals(reader.getName())){
- <xsl:value-of select="$loopBoolName"/> = true;
- }else if (javax.xml.stream.XMLStreamConstants.END_ELEMENT == event &&
- !<xsl:value-of select="$startQname"/>.equals(reader.getName())){
- <xsl:value-of select="$loopBoolName"/> = true;
- }else if (javax.xml.stream.XMLStreamConstants.END_DOCUMENT == event){
- <xsl:value-of select="$loopBoolName"/> = true;
- }else{
- reader.next();
- }
-
- }
-
- object.set<xsl:value-of select="$javaName"/>(
- (<xsl:value-of select="$propertyType"/>)
- org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(
- <xsl:value-of select="$basePropertyType"/>.class,<xsl:value-of select="$listName"/>));
-
-
- </xsl:when>
- <!-- End of Array handling of ADB classes -->
- <xsl:otherwise>
- <xsl:variable name="arrayVarName">textArray<xsl:value-of select="position()"/></xsl:variable>
- <xsl:if test="position()>1">
- <xsl:if test="$min!=0">
- // Move to a start element
- event = reader.getEventType();
- while (event!= javax.xml.stream.XMLStreamReader.START_ELEMENT) {
- event = reader.next();
- }
- </xsl:if>
- </xsl:if>
- <!-- Start of Array handling of simple types -->
- org.apache.axis2.databinding.utils.SimpleArrayReaderStateMachine <xsl:value-of select="$stateMachineName"/> = new
- org.apache.axis2.databinding.utils.SimpleArrayReaderStateMachine();
- <xsl:value-of select="$stateMachineName"/>.setElementNameToTest(new javax.xml.namespace.QName(
- "<xsl:value-of select="$namespace"/>",
- "<xsl:value-of select="$propertyName"/>"));
- <xsl:if test="@nillable">
- <xsl:value-of select="$stateMachineName"/>.setNillable();
- </xsl:if>
- <xsl:if test="$min=0">
- <xsl:value-of select="$stateMachineName"/>.setCanbeAbsent(true);
- </xsl:if>
- <xsl:value-of select="$stateMachineName"/>.read(reader);
- java.lang.String[] <xsl:value-of select="$arrayVarName"/> =
- <xsl:value-of select="$stateMachineName"/>.getTextArray();
- object.set<xsl:value-of select="$javaName"/>(
- (<xsl:value-of select="$propertyType"/>)
- org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(
- <xsl:value-of select="$basePropertyType"/>.class,<xsl:value-of select="$arrayVarName"/>));
- <!-- end of Array handling of simple types -->
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <!-- end of array handling -->
-
- <!-- start of adb handling-->
- <xsl:when test="@ours">
- <xsl:if test="$min=0">
- if (new javax.xml.namespace.QName(
- "<xsl:value-of select="$namespace"/>",
- "<xsl:value-of select="$propertyName"/>").equals(
- reader.getName())){
- </xsl:if>
- object.set<xsl:value-of select="$javaName"/>(
- <xsl:value-of select="$propertyType"/>.Factory.parse(reader));
- <xsl:if test="$min=0">
- }
- </xsl:if>
-
- //go one more step if the parser is resting at the end element
- if (reader.getEventType()==javax.xml.stream.XMLStreamConstants.END_ELEMENT
- && new javax.xml.namespace.QName(
- "<xsl:value-of select="$namespace"/>",
- "<xsl:value-of select="$propertyName"/>").
- equals(reader.getName())){
- reader.next();
- }
- </xsl:when>
-
- <!-- start of any handling. Any can also be @default so we need to
- handle the any case before default! -->
- <xsl:when test="@any">
- <!--No concerns of being nillable here. if it's ours and if the nillable attribute was present
- we would have outputted a null already-->
- boolean <xsl:value-of select="$loopBoolName"/> = false;
- //move to the start element
- while(!<xsl:value-of select="$loopBoolName"/>){
- if (reader.isStartElement()){
- <xsl:value-of select="$loopBoolName"/> = true;
- }else{
- reader.next();
- }
- }
-
- <!--This can be any element and we may not know the name. so we pick the name of the
- element from the parser-->
- //use the QName from the parser as the name for the builder
- javax.xml.namespace.QName <xsl:value-of select="$startQname"/> = reader.getName();
-
- // We need to wrap the reader so that it produces a fake START_DOCUEMENT event
- // this is needed by the builder classes
- org.apache.axis2.databinding.utils.NamedStaxOMBuilder <xsl:value-of select="$builderName"/> = new org.apache.axis2.databinding.utils.NamedStaxOMBuilder(
- new org.apache.axis2.util.StreamWrapper(reader),<xsl:value-of select="$startQname"/>);
- object.set<xsl:value-of select="$javaName"/>(<xsl:value-of select="$builderName"/>.getOMElement());
-
-
- </xsl:when>
- <!-- end of adb type handling code -->
- <!-- start of OMelement handling -->
- <xsl:when test="@default">
- boolean <xsl:value-of select="$loopBoolName"/> = false;
- javax.xml.namespace.QName <xsl:value-of select="$startQname"/> = new javax.xml.namespace.QName(
- "<xsl:value-of select="$namespace"/>",
- "<xsl:value-of select="$propertyName"/>");
-
- while(!<xsl:value-of select="$loopBoolName"/>){
- if (reader.isStartElement() && <xsl:value-of select="$startQname"/>.equals(reader.getName())){
- <xsl:value-of select="$loopBoolName"/> = true;
- }else{
- reader.next();
- }
- }
-
- <!-- todo put the code here for nillable -->
- // We need to wrap the reader so that it produces a fake START_DOCUEMENT event
- // this is needed by the builder classes
- org.apache.axis2.databinding.utils.NamedStaxOMBuilder <xsl:value-of select="$builderName"/> = new org.apache.axis2.databinding.utils.NamedStaxOMBuilder(
- new org.apache.axis2.util.StreamWrapper(reader),<xsl:value-of select="$startQname"/>);
- object.set<xsl:value-of select="$javaName"/>(<xsl:value-of select="$builderName"/>.getOMElement());
-
- //step one more event from the current position
- reader.next();
- </xsl:when>
- <!-- end of OMelement handling -->
- <!-- start of the simple types handling -->
- <xsl:otherwise>
- <xsl:if test="position()>1">
- <xsl:if test="$min!=0">
- // Move to a start element
- event = reader.getEventType();
- while (event!= javax.xml.stream.XMLStreamReader.START_ELEMENT) {
- event = reader.next();
- }
- </xsl:if>
- </xsl:if>
- org.apache.axis2.databinding.utils.SimpleElementReaderStateMachine <xsl:value-of select="$stateMachineName"/>
- = new org.apache.axis2.databinding.utils.SimpleElementReaderStateMachine();
- javax.xml.namespace.QName <xsl:value-of select="$startQname"/> = new javax.xml.namespace.QName(
- "<xsl:value-of select="$namespace"/>",
- "<xsl:value-of select="$propertyName"/>");
- <xsl:value-of select="$stateMachineName"/>.setElementNameToTest(<xsl:value-of select="$startQname"/>);
- <xsl:if test="@nillable">
- <xsl:value-of select="$stateMachineName"/>.setNillable();
- </xsl:if>
- <xsl:value-of select="$stateMachineName"/>.read(reader);
- <xsl:choose>
- <xsl:when test="$min=0">
- if (!<xsl:value-of select="$stateMachineName"/>.isElementSkipped()){
- object.set<xsl:value-of select="$javaName"/>(
- <xsl:choose>
- <xsl:when test="@nillable and not(@primitive)">
- <xsl:value-of select="$stateMachineName"/>.getText()==null?null:
- org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
- <xsl:value-of select="$stateMachineName"/>.getText()));
- </xsl:when>
- <xsl:otherwise>
- org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
- <xsl:value-of select="$stateMachineName"/>.getText()));
- </xsl:otherwise>
- </xsl:choose>
- }
- </xsl:when>
- <xsl:otherwise>
- object.set<xsl:value-of select="$javaName"/>(
- <xsl:choose>
- <xsl:when test="@nillable and not(@primitive)">
- <xsl:value-of select="$stateMachineName"/>.getText()==null?null:
- org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
- <xsl:value-of select="$stateMachineName"/>.getText()));
- </xsl:when>
- <xsl:otherwise>
- org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
- <xsl:value-of select="$stateMachineName"/>.getText()));
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
-
-
- </xsl:otherwise>
- <!-- end of simple type handling -->
-
- </xsl:choose>
-
- </xsl:for-each>
- } catch (javax.xml.stream.XMLStreamException e) {
- throw new java.lang.Exception(e);
- }
-
- return object;
- }
- }//end of factory class
-
-
- <!-- end of the template -->
- </xsl:otherwise>
- </xsl:choose>
}
<!-- end of main template -->
</xsl:template>
Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/mixed_minoccus0.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/mixed_minoccus0.xsd?rev=397776&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/mixed_minoccus0.xsd (added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/mixed_minoccus0.xsd Thu Apr 27 23:01:32 2006
@@ -0,0 +1,23 @@
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://recursion1.org"
+ targetNamespace="http://recursion1.org"
+ elementFormDefault="qualified">
+ <xsd:element name="stringListResponseElement" type="tns:StringListResponseType"/>
+ <xsd:complexType name="StringListResponseType">
+ <xsd:choice>
+ <xsd:element name="stringList" type="tns:StringList"/>
+ <xsd:element name="exception" type="tns:ExceptionType"/>
+ </xsd:choice>
+ </xsd:complexType>
+ <xsd:complexType name="StringList">
+ <xsd:sequence>
+ <xsd:element name="s" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:complexType name="ExceptionType">
+ <xsd:sequence>
+ <xsd:element name="message" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+</schema>
\ No newline at end of file
Modified: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd?rev=397776&r1=397775&r2=397776&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd (original)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd Thu Apr 27 23:01:32 2006
@@ -1,7 +1,8 @@
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://soapinterop.org/types"
- targetNamespace="http://soapinterop.org/types">
+ targetNamespace="http://soapinterop.org/types"
+ elementFormDefault="qualified">
<complexType name="SOAPStruct">
<choice>
<element name="varString" type="xsd:string"/>
Modified: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java?rev=397776&r1=397775&r2=397776&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java Thu Apr 27 23:01:32 2006
@@ -124,9 +124,10 @@
}else if ("address".equals(propertyDescriptor.getDisplayName())) {
readMethod = propertyDescriptor.getReadMethod();
addressObject = readMethod.invoke(obj, null);
-
- Object[] objArray = (Object[])addressObject;
- assertEquals(expectedAddressCount,objArray.length);
+ if (expectedAddressCount!=0) {
+ Object[] objArray = (Object[])addressObject;
+ assertEquals(expectedAddressCount,objArray.length);
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java?rev=397776&r1=397775&r2=397776&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java Thu Apr 27 23:01:32 2006
@@ -76,8 +76,13 @@
populateAndAssert(xmlString3, 1, "a");
}
- private void populateAndAssert(String s, int expectedCount, String itemtoTest) throws XMLStreamException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IntrospectionException {
- XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(s.getBytes()));
+ private void populateAndAssert(String s, int expectedCount,
+ String itemtoTest) throws XMLStreamException,
+ ClassNotFoundException, NoSuchMethodException,
+ IllegalAccessException, InvocationTargetException,
+ IntrospectionException {
+ XMLStreamReader reader =
+ XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(s.getBytes()));
Class clazz = Class.forName("org.test.Root");
Class innerClazz = clazz.getDeclaredClasses()[0];
Method parseMethod = innerClazz.getMethod("parse", new Class[]{XMLStreamReader.class});
@@ -99,9 +104,11 @@
}
}
- assertNotNull(stringArray);
- String[] array = (String[]) stringArray;
- assertEquals(array.length, expectedCount);
+ if (expectedCount!=0){
+ assertNotNull(stringArray);
+ String[] array = (String[]) stringArray;
+ assertEquals(array.length, expectedCount);
+ }
}
Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMixedMinoccurs0Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMixedMinoccurs0Test.java?rev=397776&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMixedMinoccurs0Test.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMixedMinoccurs0Test.java Thu Apr 27 23:01:32 2006
@@ -0,0 +1,135 @@
+package org.apache.axis2.schema.populate.other;
+
+import junit.framework.TestCase;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.beans.IntrospectionException;
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.io.ByteArrayInputStream;
+/*
+ * 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.
+ */
+
+public class PopulateMixedMinoccurs0Test extends TestCase {
+
+ /*
+
+ <xsd:element name="stringListResponseElement" type="tns:StringListResponseType"/>
+ <xsd:complexType name="StringListResponseType">
+ <xsd:choice>
+ <xsd:element name="stringList" type="tns:StringList"/>
+ <xsd:element name="exception" type="tns:ExceptionType"/>
+ </xsd:choice>
+ </xsd:complexType>
+ <xsd:complexType name="StringList">
+ <xsd:sequence>
+ <xsd:element name="s" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ */
+
+
+ private String xmlString1 = "<stringListResponseElement " +
+ "xmlns=\"http://recursion1.org\">" +
+ "<stringList>" +
+ "<s>item1</s>" +
+ "<s>item2</s>" +
+ "<s>item3</s>" +
+ "</stringList>" +
+ "</stringListResponseElement>";
+
+ private String xmlString2 = "<stringListResponseElement " +
+ "xmlns=\"http://recursion1.org\">" +
+ "<stringList>" +
+ "</stringList>" +
+ "</stringListResponseElement>";
+
+
+ public void testPopulate1() throws Exception {
+ populateAndAssert(xmlString1,3);
+ }
+
+ public void testPopulate2() throws Exception {
+ populateAndAssert(xmlString2,0);
+ }
+
+
+ private void populateAndAssert(String s,int count) throws XMLStreamException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IntrospectionException {
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(s.getBytes()));
+ Class clazz = Class.forName("org.recursion1.StringListResponseElement");
+ Class innerClazz = clazz.getDeclaredClasses()[0];
+ Method parseMethod = innerClazz.getMethod("parse", new Class[]{XMLStreamReader.class});
+ Object obj = parseMethod.invoke(null, new Object[]{reader});
+
+ assertNotNull(obj);
+
+ Object stringListResponseElement = null;
+ BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ Method readMethod;
+
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
+ String displayName = propertyDescriptor.getDisplayName();
+ if ("stringListResponseElement".equals(displayName)) {
+ readMethod = propertyDescriptor.getReadMethod();
+ stringListResponseElement = readMethod.invoke(obj, null);
+ break;
+ }
+ }
+
+ assertNotNull(stringListResponseElement);
+
+ beanInfo = Introspector.getBeanInfo(stringListResponseElement.getClass());
+ propertyDescriptors = beanInfo.getPropertyDescriptors();
+ Object stringArray = null;
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
+ String displayName = propertyDescriptor.getDisplayName();
+ if ("stringList".equals(displayName)) {
+ readMethod = propertyDescriptor.getReadMethod();
+ stringArray = readMethod.invoke(stringListResponseElement, null);
+ break;
+ }
+ }
+
+ assertNotNull(stringArray);
+
+ beanInfo = Introspector.getBeanInfo(stringArray.getClass());
+ propertyDescriptors = beanInfo.getPropertyDescriptors();
+ Object sArray = null;
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
+ String displayName = propertyDescriptor.getDisplayName();
+ if ("stringList".equals(displayName)) {
+ readMethod = propertyDescriptor.getReadMethod();
+ sArray = readMethod.invoke(stringArray, null);
+ break;
+ }
+ }
+ if (sArray!=null){
+ Object[] array = (Object[])sArray;
+ assertEquals(count,array.length);
+ }
+
+ }
+}