axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r372135 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/schema/ src/org/apache/axis2/schema/template/ src/org/apache/axis2/schema/writer/ test-resources/xsd/ test/org/apache/axis2/schema/compile/
Date Wed, 25 Jan 2006 06:39:17 GMT
Author: ajith
Date: Tue Jan 24 22:38:57 2006
New Revision: 372135

URL: http://svn.apache.org/viewcvs?rev=372135&view=rev
Log:
Applied Chuck's patch to solve the xsd:choice handling. His solution seems to be reasonable.
Also added a testcase and a test xsd

Added:
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleChoiceTest.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java?rev=372135&r1=372134&r2=372135&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
Tue Jan 24 22:38:57 2006
@@ -35,6 +35,8 @@
 
     protected boolean ordered = false;
     protected boolean anonymous = false;
+    protected boolean choice = false;
+
     protected boolean extension = false;
     private String extensionClassName = "";
     protected Map elementToSchemaQNameMap = new HashMap();
@@ -50,6 +52,13 @@
     //restrictions
     protected BeanWriterMetaInfoHolder parent = null;
 
+    public boolean isChoice() {
+        return choice;
+    }
+
+    public void setChoice(boolean choice) {
+        this.choice = choice;
+    }
 
     /**
      * Gets the parent

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=372135&r1=372134&r2=372135&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
Tue Jan 24 22:38:57 2006
@@ -383,6 +383,7 @@
             //property file
             className = DEFAULT_CLASS_NAME;
         }
+        
         if (isArray) {
             //append the square braces that say this is an array
             //hope this works for all cases!!!!!!!
@@ -678,7 +679,10 @@
             XmlSchemaObjectCollection items = ((XmlSchemaAll) particle).getItems();
             process(items, metainfHolder, false,parenSchema);
         } else if (particle instanceof XmlSchemaChoice) {
-            //todo put the code here to handle the choice!
+            XmlSchemaObjectCollection items = ((XmlSchemaChoice) particle).getItems();
+            metainfHolder.setChoice(true);
+            process(items, metainfHolder, false,parenSchema);
+
         }
     }
 

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=372135&r1=372134&r2=372135&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
Tue Jan 24 22:38:57 2006
@@ -32,6 +32,7 @@
     <xsl:template match="bean">
 
         <xsl:variable name="name"><xsl:value-of select="@name"/></xsl:variable>
+        <xsl:variable name="choice"><xsl:value-of select="@choice"/></xsl:variable>
     <!-- write the class header. this should be done only when unwrapped -->
 
         <xsl:if test="not(not(@unwrapped) or (@skip-write))">
@@ -65,6 +66,17 @@
             </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">
             <!-- Write only the NOT inherited properties-->
@@ -85,7 +97,7 @@
             protected <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
@@ -119,7 +131,11 @@
                     }
                 </xsl:if>
             </xsl:if>
-             <xsl:if test="$min=0">
+
+             <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>

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=372135&r1=372134&r2=372135&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
Tue Jan 24 22:38:57 2006
@@ -347,10 +347,16 @@
             XSLTUtils.addAttribute(model, "extension", metainf.getExtensionClassName(), rootElt);
         }
 
+
+        if (metainf.isChoice()) {
+            XSLTUtils.addAttribute(model, "choice", "yes", rootElt);
+        }
+
+
         //populate all the information
         populateInfo(metainf, model, rootElt, propertyNames, typeMap,false);
 
-       
+
         return rootElt;
     }
 
@@ -428,16 +434,16 @@
             }
 
             String shortTypeName = "";
-             if (metainf.getSchemaQNameForQName(name) != null) {
-                 //see whether the QName is a basetype
-                 if (baseTypeMap.containsKey(metainf.getSchemaQNameForQName(name))){
+            if (metainf.getSchemaQNameForQName(name) != null) {
+                //see whether the QName is a basetype
+                if (baseTypeMap.containsKey(metainf.getSchemaQNameForQName(name))){
                     shortTypeName= metainf.getSchemaQNameForQName(name).getLocalPart();
-                 }else{
-                     shortTypeName =  getShortTypeName(javaClassNameForElement);
-                 }
+                }else{
+                    shortTypeName =  getShortTypeName(javaClassNameForElement);
+                }
             }else{
-                 shortTypeName =  getShortTypeName(javaClassNameForElement);
-             }
+                shortTypeName =  getShortTypeName(javaClassNameForElement);
+            }
             XSLTUtils.addAttribute(model, "shorttypename", shortTypeName, property);
 
             if (isInherited){
@@ -619,9 +625,9 @@
     }
 
     private String getShortTypeName(String typeClassName){
-         if (typeClassName.endsWith("[]")){
-             typeClassName = typeClassName.substring(0,typeClassName.lastIndexOf("["));
-         }
+        if (typeClassName.endsWith("[]")){
+            typeClassName = typeClassName.substring(0,typeClassName.lastIndexOf("["));
+        }
         String s = typeClassName.substring(typeClassName.lastIndexOf(".")+1, typeClassName.length());
 
         return s;

Added: 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=372135&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd (added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd Tue
Jan 24 22:38:57 2006
@@ -0,0 +1,14 @@
+<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">
+    <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
+    <complexType name="SOAPStruct">
+        <choice>
+            <element name="varString" type="xsd:string"/>
+            <element name="varInt" type="xsd:int"/>
+            <element name="varFloat" type="xsd:float"/>
+        </choice>
+    </complexType>
+    <element name="myElement" type="tns:SOAPStruct"/>
+</schema>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleChoiceTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleChoiceTest.java?rev=372135&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleChoiceTest.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleChoiceTest.java
Tue Jan 24 22:38:57 2006
@@ -0,0 +1,26 @@
+package org.apache.axis2.schema.compile;
+/*
+ * 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 SimpleChoiceTest extends AbstractSchemaCompilerTester {
+
+    protected void setUp() throws Exception {
+        this.fileName = "test-resources/xsd/simple_choice.xsd";
+        super.setUp();
+    }
+
+   
+}



Mime
View raw message