Ajith, You probably already saw the second issue in the xsl (an unintended side effect on optional and array-valued properties). Just in case you didn't notice that one, please see the difference in the new version of the patch (still against 0.94). I've now created and generated code for a large wsdl and so have growing confidence in the patch. The biggest issue I've seen in using the code generator is the lack of error detection. E.g., missing name attributes where axis2 expects them (even if they are not required by the wsdl spec), multiple parts in messages that take elements rather than types (element= as opposed to type=), typos in certain references, all generally yield NullPointerException. With a large wsdl especially, the problems can be a challenge to find. Are there plans to beef up the error checking? Thanks, Chuck
|
diff -urX exclude.files codegen.src.orig/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java codegen.src.new/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java --- codegen.src.orig/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java 2006-01-24 18:14:07.000000000 -1000 +++ codegen.src.new/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java 2006-01-26 00:13:42.000000000 -1000 @@ -32,6 +32,7 @@ private boolean ordered = false; + private boolean choice = false; private boolean anonymous = false; private boolean extension = false; private String extensionClassName = ""; @@ -115,6 +116,24 @@ public void setOrdered(boolean ordered) { this.ordered = ordered; } + + /** + * Gets the choice status. + * + * @return Returns boolean. + */ + public boolean isChoice() { + return choice; + } + + /** + * Sets the choice flag. + * + * @param choice + */ + public void setChoice(boolean choice) { + this.choice = choice; + } /** * Registers a mapping. diff -urX exclude.files codegen.src.orig/org/apache/axis2/schema/SchemaCompiler.java codegen.src.new/org/apache/axis2/schema/SchemaCompiler.java --- codegen.src.orig/org/apache/axis2/schema/SchemaCompiler.java 2006-01-24 18:14:07.000000000 -1000 +++ codegen.src.new/org/apache/axis2/schema/SchemaCompiler.java 2006-01-26 00:13:42.000000000 -1000 @@ -497,7 +497,9 @@ XmlSchemaObjectCollection items = ((XmlSchemaAll) particle).getItems(); process(items, metainfHolder, false); } else if (particle instanceof XmlSchemaChoice) { - //put the code here to handle the choice! + XmlSchemaObjectCollection items = ((XmlSchemaChoice) particle).getItems(); + metainfHolder.setChoice(true); + process(items, metainfHolder, false); } } diff -urX exclude.files codegen.src.orig/org/apache/axis2/schema/template/ADBBeanTemplate.xsl codegen.src.new/org/apache/axis2/schema/template/ADBBeanTemplate.xsl --- codegen.src.orig/org/apache/axis2/schema/template/ADBBeanTemplate.xsl 2006-01-24 18:14:07.000000000 -1000 +++ codegen.src.new/org/apache/axis2/schema/template/ADBBeanTemplate.xsl 2006-01-26 00:13:42.000000000 -1000 @@ -32,6 +32,8 @@ <xsl:template match="bean"> <xsl:variable name="name"><xsl:value-of select="@name"/></xsl:variable> + <xsl:variable name="choice" select="@choice"/> + <!-- write the class header. this should be done only when unwrapped --> <xsl:if test="not(not(@unwrapped) or (@skip-write))"> @@ -64,8 +66,18 @@ </xsl:otherwise> </xsl:choose> - - + + <xsl:if test="$choice"> + /** Whenever a new property is set ensure all others are unset + * There can be only one choice and the last one wins + */ + private void clearAllSettingTrackers() { + <xsl:for-each select="property"> + local<xsl:value-of select="@javaname"/>Tracker = false; + </xsl:for-each> + } + </xsl:if> + <xsl:for-each select="property"> <xsl:variable name="propertyType"><xsl:value-of select="@type"></xsl:value-of></xsl:variable> <xsl:variable name="propertyName"><xsl:value-of select="@name"></xsl:value-of></xsl:variable> @@ -81,7 +93,7 @@ private <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text><xsl:value-of select="$varName" /> ; <!-- Generate a tracker only if the min occurs is zero, which means if the user does not bother to set that value, we do not send it --> - <xsl:if test="$min=0"> + <xsl:if test="($min=0) or $choice"> /* This tracker boolean wil be used to detect whether the user called the set method for this attribute. It will be used to determine whether to include this field in the serialized XML @@ -115,10 +127,13 @@ } </xsl:if> </xsl:if> - <xsl:if test="$min=0"> - //update the setting tracker - <xsl:value-of select="$settingTracker"/> = true; - </xsl:if> + <xsl:if test="$choice"> + clearAllSettingTrackers(); + </xsl:if> + <xsl:if test="($min=0) or $choice"> + //update the setting tracker + <xsl:value-of select="$settingTracker"/> = true; + </xsl:if> this.<xsl:value-of select="$varName"/>=param; } </xsl:for-each> @@ -143,7 +158,7 @@ <xsl:variable name="settingTracker">local<xsl:value-of select="@javaname"/>Tracker</xsl:variable> - <xsl:if test="$min=0"> if (<xsl:value-of select="$settingTracker"/>){</xsl:if> + <xsl:if test="($min=0) or $choice"> if (<xsl:value-of select="$settingTracker"/>){</xsl:if> <xsl:choose> <xsl:when test="@ours or @any"> elementList.add(new javax.xml.namespace.QName("<xsl:value-of select="$namespace"/>", @@ -160,7 +175,7 @@ elementList.add(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>)); </xsl:otherwise> </xsl:choose> - <xsl:if test="$min=0">}</xsl:if> + <xsl:if test="($min=0) or $choice">}</xsl:if> </xsl:for-each> <xsl:for-each select="[EMAIL PROTECTED]"> diff -urX exclude.files codegen.src.orig/org/apache/axis2/schema/writer/JavaBeanWriter.java codegen.src.new/org/apache/axis2/schema/writer/JavaBeanWriter.java --- codegen.src.orig/org/apache/axis2/schema/writer/JavaBeanWriter.java 2006-01-24 18:14:07.000000000 -1000 +++ codegen.src.new/org/apache/axis2/schema/writer/JavaBeanWriter.java 2006-01-26 00:13:41.000000000 -1000 @@ -342,6 +342,11 @@ if (metainf.isExtension()) { XSLTUtils.addAttribute(model, "extension", metainf.getExtensionClassName(), rootElt); } + + if (metainf.isChoice()) { + XSLTUtils.addAttribute(model, "choice", "yes", rootElt); + } + // go in the loop and add the part elements QName[] qNames; if (metainf.isOrdered()) {