Ajith, thanks again! Very nice of you to not embarass me on the list,
although I managed to do that myself pretty well. :-) For the benefit of others using 0.94, the corrected patch is attached to this message. I also updated the bean schema for completeness, although it appears it is missing a couple other attributes as well so probably not important. Chuck Well Actualy when I went through the patch I figured out the mistake:) It's already corrected :) |
diff -ur 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-24 21:09:20.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 -ur 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-24 21:09:20.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 -ur 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-24 21:09:20.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,8 +127,9 @@ } </xsl:if> </xsl:if> - <xsl:if test="$min=0"> + <xsl:if test="($min=0) or $choice"> //update the setting tracker + clearAllSettingTrackers(); <xsl:value-of select="$settingTracker"/> = true; </xsl:if> this.<xsl:value-of select="$varName"/>=param; @@ -143,7 +156,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 +173,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 -ur 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-24 21:09:20.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()) {