You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by aj...@apache.org on 2005/10/12 11:08:33 UTC

svn commit: r314829 - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema: JavaBeanWriter.java SchemaCompiler.java template/BeanTemplate.xsl util/ConverterUtil.java

Author: ajith
Date: Wed Oct 12 02:08:22 2005
New Revision: 314829

URL: http://svn.apache.org/viewcvs?rev=314829&view=rev
Log:
updated the schema compiler to generate code to generate an object from a pull stream and serialize the object to a pull stream. A decent test case is still missing!

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/SchemaCompiler.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

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=314829&r1=314828&r2=314829&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 02:08:22 2005
@@ -64,57 +64,64 @@
         try {
             //determine the package for this type.
             QName qName = complexType.getQName();
-            String packageName = URLProcessor.getNameSpaceFromURL(qName.getNamespaceURI());
-            String className = qName.getLocalPart();
+            return process(qName, metainf, typeMap);
 
-            if (!templateLoaded){
-                loadTemplate();
-            }
+        }catch (SchemaCompilationException e) {
+            throw e;
+        }catch (Exception e) {
+            throw new SchemaCompilationException(e);
+        }
 
-            //create the model
-            Document model= XSLTUtils.getDocument();
 
-            //make the XML
-            Element rootElt = XSLTUtils.addChildElement(model,"bean",model);
-            XSLTUtils.addAttribute(model,"name",className,rootElt);
-            XSLTUtils.addAttribute(model,"package",packageName,rootElt);
-            XSLTUtils.addAttribute(model,"nsuri",qName.getNamespaceURI(),rootElt);
-            XSLTUtils.addAttribute(model,"nsprefix",qName.getPrefix(),rootElt);
-            if (metainf.isExtension()){
-                XSLTUtils.addAttribute(model,"extension",metainf.getExtensionClassName(),rootElt);
-            }
-            // go in the loop and add the part elements
-            Iterator qNameIterator = metainf.getElementQNameIterator();
+    }
 
-            QName name;
-            while (qNameIterator.hasNext()) {
-                Element property = XSLTUtils.addChildElement(model,"property",rootElt);
-                name = (QName)qNameIterator.next();
-                XSLTUtils.addAttribute(model,"name",name.getLocalPart(),property);
-                String javaClassNameForElement = metainf.getJavaClassNameForElement(name);
-                if (javaClassNameForElement==null){
-                    throw new SchemaCompilationException("Type missing!");
-                }
-                XSLTUtils.addAttribute(model,"type",javaClassNameForElement,property);
-                if (typeMap.containsKey(metainf.getSchemaQNameForElement(name))){
-                    XSLTUtils.addAttribute(model,"ours","yes",property); //todo introduce a better name for this
-                }
-            }
+    private String process(QName qName, BeanWriterMetaInfoHolder metainf, Map typeMap) throws Exception {
+        String packageName = URLProcessor.getNameSpaceFromURL(qName.getNamespaceURI());
+        String className = qName.getLocalPart();
 
-            //create the file
-            OutputStream out = createOutFile(packageName,className);
-            //parse with the template and create the files
-            parse(model,out);
-            //return the fully qualified class name
-            return packageName+"."+className;
+        if (!templateLoaded){
+            loadTemplate();
+        }
 
-        }catch (SchemaCompilationException e) {
-            throw e;
-        }catch (Exception e) {
-            throw new SchemaCompilationException(e);
+        //create the model
+        Document model= XSLTUtils.getDocument();
+
+        //make the XML
+        Element rootElt = XSLTUtils.addChildElement(model,"bean",model);
+        XSLTUtils.addAttribute(model,"name",className,rootElt);
+        XSLTUtils.addAttribute(model,"package",packageName,rootElt);
+        XSLTUtils.addAttribute(model,"nsuri",qName.getNamespaceURI(),rootElt);
+        XSLTUtils.addAttribute(model,"nsprefix",qName.getPrefix(),rootElt);
+        if (metainf.isExtension()){
+            XSLTUtils.addAttribute(model,"extension",metainf.getExtensionClassName(),rootElt);
         }
+        // go in the loop and add the part elements
+        Iterator qNameIterator = metainf.getElementQNameIterator();
 
+        QName name;
+        while (qNameIterator.hasNext()) {
+            Element property = XSLTUtils.addChildElement(model,"property",rootElt);
+            name = (QName)qNameIterator.next();
+            XSLTUtils.addAttribute(model,"name",name.getLocalPart(),property);
+            String javaClassNameForElement = metainf.getJavaClassNameForElement(name);
+            String shortTypeName = metainf.getSchemaQNameForElement(name).getLocalPart();
+            if (javaClassNameForElement==null){
+                throw new SchemaCompilationException("Type missing!");
+            }
+            XSLTUtils.addAttribute(model,"type",javaClassNameForElement,property);
+            if (typeMap.containsKey(metainf.getSchemaQNameForElement(name))){
+                XSLTUtils.addAttribute(model,"ours","yes",property); //todo introduce a better name for this
+            }
+             XSLTUtils.addAttribute(model,"shorttypename",shortTypeName,property);
+        }
 
+        System.out.println("rootElt = " + rootElt);
+        //create the file
+        OutputStream out = createOutFile(packageName,className);
+        //parse with the template and create the files
+        parse(model,out);
+        //return the fully qualified class name
+        return packageName+"."+className;
     }
 
     /**
@@ -130,47 +137,7 @@
         try {
             //determine the package for this type.
             QName qName = element.getQName();
-            String packageName = URLProcessor.getNameSpaceFromURL(qName.getNamespaceURI());
-            String className = qName.getLocalPart();
-
-            if (!templateLoaded){
-                loadTemplate();
-            }
-
-            //create the model
-            Document model= XSLTUtils.getDocument();
-
-            //make the XML
-            Element rootElt = XSLTUtils.addChildElement(model,"bean",model);
-            XSLTUtils.addAttribute(model,"name",className,rootElt);
-            XSLTUtils.addAttribute(model,"package",packageName,rootElt);
-            XSLTUtils.addAttribute(model,"nsuri",qName.getNamespaceURI(),rootElt);
-            XSLTUtils.addAttribute(model,"nsprefix",qName.getPrefix(),rootElt);
-
-            // go in the loop and add the part elements
-            Iterator qNameIterator = metainf.getElementQNameIterator();
-
-            QName name;
-            while (qNameIterator.hasNext()) {
-                Element property = XSLTUtils.addChildElement(model,"property",rootElt);
-                name = (QName)qNameIterator.next();
-                XSLTUtils.addAttribute(model,"name",name.getLocalPart(),property);
-                String javaClassNameForElement = metainf.getJavaClassNameForElement(name);
-                if (javaClassNameForElement==null){
-                    throw new SchemaCompilationException("Type missing!");
-                }
-                XSLTUtils.addAttribute(model,"type",javaClassNameForElement,property);
-                if (typeMap.containsKey(metainf.getSchemaQNameForElement(name))){
-                    XSLTUtils.addAttribute(model,"ours","yes",property); //todo introduce a better name for this
-                }
-
-            }
-
-            //create the file
-            OutputStream out = createOutFile(packageName,className);
-            //parse with the template and create the files
-            parse(model,out);
-            return packageName+"."+className;
+             return process(qName, metainf, typeMap);
         } catch (Exception e) {
             throw new SchemaCompilationException(e);
         }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java?rev=314829&r1=314828&r2=314829&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java Wed Oct 12 02:08:22 2005
@@ -238,10 +238,8 @@
      * @param simpleType
      */
     private void processSimpleSchemaType(XmlSchemaSimpleType simpleType){
-        //nothing to here yet. just populate the processed type map with this
-        //the class Name would be from the base type map!
-        QName qName = simpleType.getQName();
-        processedTypemap.put(qName,baseSchemaTypeMap.get(qName));
+        //nothing to here yet.
+        
     }
 
 

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=314829&r1=314828&r2=314829&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 02:08:22 2005
@@ -45,15 +45,15 @@
          * databinding method to get an XML representation of this object
          * Note - this is not complete
          */
-        public javax.xml.stream.XMLStreamReader getPullParser(){
+        public javax.xml.stream.XMLStreamReader getPullParser(javax.xml.namespace.QName qName){
 
-          java.util.List list = new  java.util.ArrayList();
+          Object[] objectList = new Object[]{
           <xsl:for-each select="property">
-           <xsl:variable name="propertyName"><xsl:value-of select="@name"></xsl:value-of></xsl:variable>
-           list.add(org.apache.axis2.databinding.schema.util.ConverterUtil.convertToObject(local<xsl:value-of select="$propertyName"></xsl:value-of>));
-          </xsl:for-each>
+           <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:for-each>};
 
-          return null;
+         return org.apache.axis2.databinding.utils.ADBPullParser.createPullParser(objectList,qName);
 
         }
 
@@ -62,10 +62,58 @@
          * Note -  This is not complete
          */
         public static <xsl:value-of select="$name"/> parse(javax.xml.stream.XMLStreamReader reader){
-             
+        <xsl:value-of select="$name"/> object = new <xsl:value-of select="$name"/>();
+        try {
+            int event = reader.getEventType();
+            int count = 0;
+            int argumentCount = <xsl:value-of select="count(property)"/> ;
+            boolean done =false;
+            //event better be a START_ELEMENT. if not we should go up to the start element here
+            while (!reader.isStartElement()){
+                event = reader.next();
+            }
+
+            while(!done){
+                if (javax.xml.stream.XMLStreamConstants.START_ELEMENT==event){
+           <xsl:for-each select="property">
+           <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>
+
+               if ("<xsl:value-of select="$propertyName"/>".equals(reader.getLocalName())){
+              <xsl:choose>
+                   <xsl:when test="@ours">
+                     object.set<xsl:value-of select="$propertyName"/>(
+                          <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++;
+                  </xsl:otherwise>
+                 </xsl:choose>
+               }
+          </xsl:for-each>
+                    event = reader.getEventType();
+                    while(javax.xml.stream.XMLStreamConstants.END_ELEMENT!=event){
+                        event = reader.next();
+                    }
+                }
+
+                if (argumentCount==count){
+                   done=true;
+                }
 
 
-             return new <xsl:value-of select="$name"/>();
+            }
+
+        } catch (javax.xml.stream.XMLStreamException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+
+        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=314829&r1=314828&r2=314829&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 02:08:22 2005
@@ -21,7 +21,7 @@
         return new Integer(i);
     }
 
-     public static Object convertToObject(float i){
+    public static Object convertToObject(float i){
         return new Float(i);
     }
 
@@ -29,6 +29,22 @@
         return new Long(i);
     }
 
+    // fill the other methods
+
+
+    public static int convertToint(String s){
+        return Integer.parseInt(s);
+    }
+
+    public static float convertTofloat(String s){
+        return Float.parseFloat(s);
+    }
+
+      public static String convertTostring(String s){
+        return s;
+    }
+
+   
     //the pass through method
     public static Object convertToObject(Object o){
         return o;