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


Chuck Williams <[EMAIL PROTECTED]> wrote on 01/26/2006 08:23:24 AM:

Hi Ajith

I think the validation is a good idea, but the issues I listed below all generated NullPointerException's on valid wsdl.  I have been validating the wsdl with my ide (Netbeans) prior to submitting it to the code generator.  That did help to diagnose some problems, but not all.  The code generator has many constraints that go beyond validation (e.g., names in many places they are not required due to the way the data structures work, valid references of course, and one I don't understand yet:  messages with multiple parts are only supported if the part constraints are type=, not if they are element=).

Thanks,

Chuck


Ajith Ranabahu <[EMAIL PROTECTED]> wrote on 01/26/2006 03:13:00 AM:

Hi Chuck,
Thanks for pointing out the issues.
Yes, the code generator being non-validating  is the problem here. We do not check whether the WSDL is valid before attempting to generate code. IMHO I think we should have a WOM validator as one of the extensions in the codegenerator - the user can switch off validation if needed.
My guess is if we have the WSDL validator then we may overcome a number of issues

On 1/26/06, Chuck Williams < [EMAIL PROTECTED]> wrote:
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


Chuck Williams <[EMAIL PROTECTED]> wrote on 01/24/2006 09:17:14 PM:

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


Ajith Ranabahu <[EMAIL PROTECTED]> wrote on 01/24/2006 09:04:56 PM:

Well Actualy when I went through the patch I figured out the mistake:) It's already corrected :)

On 1/25/06, Chuck Williams < [EMAIL PROTECTED]> wrote:
Thanks Ajith!  Unfortunately, I need to send you a revised version.  There is a stupid mistake in my xsl that broke the other types!  I had only verified that the <choice> code worked, not yet verified that the rest of the generated code wasn't affected.  It's a trivial change I'm testing now, so should be just few.  Mea culpa -- sorry for the confusion.

Regarding the code, it is very easy to read.  I compliment you on the organizaiton.

Chuck


Ajith Ranabahu <[EMAIL PROTECTED]> wrote on 01/24/2006 08:52:44 PM:

Hi Chuck,
I looked at your solution and it is reasonable for handling choice. I applied the patch (Actually modified the classes looking at the patch. TortoiseSVN  throws an exception when I try to apply the given patch)
Thanks a lot for your effort in participating in the development effort. We really appreciate you coming forward and solving this issue. I've already solved the ref issue.

BTW you seem to have understood the workings of the code well. Did it take a lot of effort to figure out the stuff ?


On 1/25/06, Chuck Williams <[EMAIL PROTECTED] > wrote:
Dims and Ajith,

I took Dims' advice and created the attached patch to modules/codegen/src of Axis2 0.94.  This may not be the best implementation of <choice> but it is very simple and meets my use cases.  The idea is this.  A <choice> is treated just like an <all> where each enclosed element has minOccurs=0, except that in the generated code setting any constituent element automatically unsets all the others.  Thus, whatever choice you set last is the choice you get and you only get one.  (The code does not enforce what happens if you don't set any; this, additional error checking, and accessors to fully determine the state of what has been chosen, could all be improved.)

I'm just starting to work with it so have not tested it much yet, but the generated code looks right to me.  It's very simple because it reuses all the code that is already there and makes just a few mods.

I haven't tried complex nesting cases to see if they all work, and probably wont' because I only need <choice> of <element>'s, although in principle any nesting that <all> handles, choice should too.

I noticed in doing this that none of the particles handle the <element ref=...> construction.  This is somewhat painful, but livable.  If I had more time, I'd try to fix that.  It looks like it might be more complex than this hack due to the way the names are used in the data structures.

I'd appreciate if you guys would add this to axis2 so I don't have to patch future releases.  If it is not deemed suitable, please let me know why as perhaps I could fix it, or just fix it!

Thanks,

Chuck







--
Ajith Ranabahu




--
Ajith Ranabahu






--
Ajith Ranabahu




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()) {

Reply via email to