Ajith, Thre was another problem in the patch I submitted to handle <choice>: the generated adb bean parse() methods used an incorrect value for the argumentCount. They assumed all arguments were required, rather than precisely 1. Fixing this required one more simple change to ADBBeanTemplate.xsl. The updated version of the complete patch (relative to 0.94 release) is attached. 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-02-08 22:24:45.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-02-08 22:24:45.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-02-08 22:24:45.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]"> @@ -218,7 +233,10 @@ try { int event = reader.getEventType(); int count = 0; - int argumentCount = <xsl:value-of select="count(property)"/> ; + int argumentCount = <xsl:choose> + <xsl:when test="$choice">1</xsl:when> + <xsl:otherwise><xsl:value-of select="count(property)"/></xsl:otherwise> + </xsl:choose>; boolean done =false; //event better be a START_ELEMENT. if not we should go up to the start element here while (!reader.isStartElement()){ 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-02-08 22:24:45.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()) {