You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by aj...@apache.org on 2005/10/12 14:40:13 UTC

svn commit: r314860 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/databinding/schema/ src/org/apache/axis2/databinding/schema/template/ src/org/apache/axis2/databinding/schema/util/ test-resources/xsd/

Author: ajith
Date: Wed Oct 12 05:39:54 2005
New Revision: 314860

URL: http://svn.apache.org/viewcvs?rev=314860&view=rev
Log:
1. Modified the template and other support classes to generate working code after a few tests. The tests are not possible to be run as pure junit tests  (they are based on code generated classes!) so  yet to figure out the way to do so (may be with reflection)
2. Added xml -> javaname conversion to the bean writer

Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/ConverterUtil.java
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence.xsd
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence_2.xsd

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java?rev=314860&r1=314859&r2=314860&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java Wed Oct 12 05:39:54 2005
@@ -102,7 +102,15 @@
         while (qNameIterator.hasNext()) {
             Element property = XSLTUtils.addChildElement(model,"property",rootElt);
             name = (QName)qNameIterator.next();
-            XSLTUtils.addAttribute(model,"name",name.getLocalPart(),property);
+            String xmlName = name.getLocalPart();
+            String javaName = "";
+            if (JavaUtils.isJavaKeyword(xmlName)){
+                javaName = JavaUtils.makeNonJavaKeyword(xmlName);
+            }else{
+                javaName = JavaUtils.xmlNameToJava(xmlName,false);
+            }
+            XSLTUtils.addAttribute(model,"name",xmlName,property);
+            XSLTUtils.addAttribute(model,"javaname",javaName,property);
             String javaClassNameForElement = metainf.getJavaClassNameForElement(name);
             String shortTypeName = metainf.getSchemaQNameForElement(name).getLocalPart();
             if (javaClassNameForElement==null){

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl?rev=314860&r1=314859&r2=314860&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl Wed Oct 12 05:39:54 2005
@@ -19,25 +19,26 @@
      <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>
+         <xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
         /**
-         * field for <xsl:value-of select="$propertyName"/>
+         * field for <xsl:value-of select="$javaName"/>
          */
-         private <xsl:value-of select="$propertyType"/> local<xsl:value-of select="$propertyName"/>;
+         private <xsl:value-of select="$propertyType"/> local<xsl:value-of select="$javaName"/>;
 
         /**
          * Auto generated getter method
          * @return <xsl:value-of select="$propertyType"/>
          */
-        public  <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text>get<xsl:value-of select="$propertyName"/>(){
-             return local<xsl:value-of select="$propertyName"/>;
+        public  <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text>get<xsl:value-of select="$javaName"/>(){
+             return local<xsl:value-of select="$javaName"/>;
         }
 
         /**
          * Auto generated setter method
-         * @param param<xsl:value-of select="$propertyName"/>
+         * @param param<xsl:value-of select="$javaName"/>
          */
-        public void set<xsl:value-of select="$propertyName"/>(<xsl:value-of select="$propertyType"/> param<xsl:value-of select="$propertyName"/>){
-             this.local<xsl:value-of select="$propertyName"/>=param<xsl:value-of select="$propertyName"/>;
+        public void set<xsl:value-of select="$javaName"/>(<xsl:value-of select="$propertyType"/> param<xsl:value-of select="$javaName"/>){
+             this.local<xsl:value-of select="$javaName"/>=param<xsl:value-of select="$javaName"/>;
         }
      </xsl:for-each>
 
@@ -50,7 +51,16 @@
           Object[] objectList = new Object[]{
           <xsl:for-each select="property">
            <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
-           <xsl:if test="position()>1">,</xsl:if>"<xsl:value-of select="$propertyName"/>",org.apache.axis2.databinding.schema.util.ConverterUtil.convertToObject(local<xsl:value-of select="$propertyName"></xsl:value-of>)
+           <xsl:if test="position()>1">,</xsl:if>
+              <xsl:choose>
+                  <xsl:when test="@ours">
+                      new javax.xml.namespace.QName("<xsl:value-of select="$propertyName"/>"),local<xsl:value-of select="@javaname"/>
+                  </xsl:when>
+                  <xsl:otherwise>
+                       "<xsl:value-of select="$propertyName"/>",org.apache.axis2.databinding.schema.util.ConverterUtil.convertToString(local<xsl:value-of select="@javaname"/>)
+                  </xsl:otherwise>
+              </xsl:choose>
+
           </xsl:for-each>};
 
          return org.apache.axis2.databinding.utils.ADBPullParser.createPullParser(objectList,qName);
@@ -79,27 +89,24 @@
            <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
            <xsl:variable name="propertyType"><xsl:value-of select="@type"/></xsl:variable>
            <xsl:variable name="shortTypeName"><xsl:value-of select="@shorttypename"/></xsl:variable>
+          <xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
 
                if ("<xsl:value-of select="$propertyName"/>".equals(reader.getLocalName())){
               <xsl:choose>
                    <xsl:when test="@ours">
-                     object.set<xsl:value-of select="$propertyName"/>(
+                     object.set<xsl:value-of select="$javaName"/>(
                           <xsl:value-of select="$propertyType"/>.parse(reader));
-                       }
                   </xsl:when>
                   <xsl:otherwise>
-                         String content = reader.getElementText();
-                        object.set<xsl:value-of select="$propertyName"/>(
-                        org.apache.axis2.databinding.schema.util.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(content));
-                        count++;
+                      String content = reader.getElementText();
+                      object.set<xsl:value-of select="$javaName"/>(
+                      org.apache.axis2.databinding.schema.util.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(content));
                   </xsl:otherwise>
                  </xsl:choose>
+                     count++;
                }
           </xsl:for-each>
-                    event = reader.getEventType();
-                    while(javax.xml.stream.XMLStreamConstants.END_ELEMENT!=event){
-                        event = reader.next();
-                    }
+                event = reader.next();
                 }
 
                 if (argumentCount==count){
@@ -110,7 +117,7 @@
             }
 
         } catch (javax.xml.stream.XMLStreamException e) {
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            e.printStackTrace();
         }
 
         return object;

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/ConverterUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/ConverterUtil.java?rev=314860&r1=314859&r2=314860&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/ConverterUtil.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/ConverterUtil.java Wed Oct 12 05:39:54 2005
@@ -17,16 +17,16 @@
 
 public class ConverterUtil {
 
-    public static Object convertToObject(int i){
-        return new Integer(i);
+    public static String convertToString(int i){
+        return i+"";
     }
 
-    public static Object convertToObject(float i){
-        return new Float(i);
+    public static String convertToString(float i){
+        return i+"";
     }
 
-    public static Object convertToObject(long i){
-        return new Long(i);
+    public static String convertToString(long i){
+        return i+"";
     }
 
     // fill the other methods
@@ -44,10 +44,15 @@
         return s;
     }
 
-   
+
     //the pass through method
-    public static Object convertToObject(Object o){
+    public static String convertToString(String o){
         return o;
+    }
+
+     //the pass through method
+    public static String convertToString(Object o){
+        return o.toString();
     }
     //add the others here
 

Modified: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence.xsd?rev=314860&r1=314859&r2=314860&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence.xsd (original)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence.xsd Wed Oct 12 05:39:54 2005
@@ -10,4 +10,5 @@
 					<element name="varFloat" type="xsd:float"/>
 				</sequence>
 			</complexType>
-		</schema>
\ No newline at end of file
+            <element name="myElement" type="tns:SOAPStruct"/>
+        </schema>
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence_2.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence_2.xsd?rev=314860&r1=314859&r2=314860&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence_2.xsd (original)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_sequence_2.xsd Wed Oct 12 05:39:54 2005
@@ -1,21 +1,22 @@
 <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">
-				<sequence>
-					<element name="varString" type="xsd:string"/>
-					<element name="varInt" type="xsd:int"/>
-					<element name="varFloat" type="xsd:float"/>
-				</sequence>
-			</complexType>
-            <!-- Has one more complex type that uses the already defined complex type -->
-            <complexType name="SOAPStructFault">
-				<sequence>
-					<element name="soapStruct" type="tns:SOAPStruct"/>
-				</sequence>
-			</complexType>
-        </schema>
+        xmlns:tns="http://soapinterop.org/types"
+        targetNamespace="http://soapinterop.org/types">
+    <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
+    <complexType name="SOAPStruct">
+        <sequence>
+            <element name="varString" type="xsd:string"/>
+            <element name="varInt" type="xsd:int"/>
+            <element name="varFloat" type="xsd:float"/>
+        </sequence>
+    </complexType>
+    <!-- Has one more complex type that uses the already defined complex type -->
+    <complexType name="SOAPStructFault">
+        <sequence>
+            <element name="soapStruct" type="tns:SOAPStruct"/>
+        </sequence>
+    </complexType>
+    <element name="tempElt" type="tns:SOAPStructFault"/>
+</schema>