axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r312869 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/databinding/schema/ test-resources/xsd/ test/org/apache/axis2/databinding/schema/
Date Tue, 11 Oct 2005 12:54:32 GMT
Author: ajith
Date: Tue Oct 11 05:54:13 2005
New Revision: 312869

URL: http://svn.apache.org/viewcvs?rev=312869&view=rev
Log:
1.Optimized the compiler
2. removed the complex extension support. If we are doing it it has to be done right and at
the current state it has a long way to go. It's better to limit ourselves at the start

The schema compiler can handle sequence and all right now. I guess that's enough for a simple
schema compiler!

Added:
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element.xsd
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/SimpleElementTest.java
Removed:
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/complex_extension.xsd
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/ComplexExtensionTest.java
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/TypeMap.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=312869&r1=312868&r2=312869&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
Tue Oct 11 05:54:13 2005
@@ -1,6 +1,7 @@
 package org.apache.axis2.databinding.schema;
 
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.axis2.util.*;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -51,7 +52,14 @@
 
     }
 
-    public void write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder
metainf) throws SchemaCompilationException{
+    /**
+     *
+     * @param complexType
+     * @param typeMap
+     * @param metainf
+     * @throws SchemaCompilationException
+     */
+    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder
metainf) throws SchemaCompilationException{
 
         try {
             //determine the package for this type.
@@ -83,10 +91,71 @@
                 Element property = XSLTUtils.addChildElement(model,"property",rootElt);
                 name = (QName)qNameIterator.next();
                 XSLTUtils.addAttribute(model,"name",name.getLocalPart(),property);
-                XSLTUtils.addAttribute(model,"type",metainf.getJavaClassNameForElement(name),property);
-                if (typeMap.containsKey(metainf.getSchemaQNameForElement(name))){
-                    XSLTUtils.addAttribute(model,"ours","yes",property); //todo introduce
a better name for this
+                String javaClassNameForElement = metainf.getJavaClassNameForElement(name);
+                if (javaClassNameForElement==null){
+                    throw new SchemaCompilationException("Type missing!");
                 }
+                XSLTUtils.addAttribute(model,"type",javaClassNameForElement,property);
+            }
+
+            //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;
+
+        }catch (SchemaCompilationException e) {
+            throw e;
+        }catch (Exception e) {
+            throw new SchemaCompilationException(e);
+        }
+
+
+    }
+
+    /**
+     *
+     * @param element
+     * @param typeMap
+     * @param metainf
+     * @return
+     * @throws SchemaCompilationException
+     */
+    public String write(XmlSchemaElement element, Map typeMap, BeanWriterMetaInfoHolder metainf)
throws SchemaCompilationException{
+
+        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);
+                XSLTUtils.addAttribute(model,"type",metainf.getJavaClassNameForElement(name),property);
+//                if (typeMap.containsKey(metainf.getSchemaQNameForElement(name))){
+//                    XSLTUtils.addAttribute(model,"ours","yes",property); //todo introduce
a better name for this
+//                }
 
             }
 
@@ -94,13 +163,13 @@
             OutputStream out = createOutFile(packageName,className);
             //parse with the template and create the files
             parse(model,out);
+            return packageName+"."+className;
         } catch (Exception e) {
             throw new SchemaCompilationException(e);
         }
 
 
     }
-
 
 
     /** A bit of code from the code generator. We are better off using the template

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=312869&r1=312868&r2=312869&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
Tue Oct 11 05:54:13 2005
@@ -4,10 +4,7 @@
 import org.apache.axis2.util.URLProcessor;
 
 import javax.xml.namespace.QName;
-import java.util.List;
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 import java.io.IOException;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
@@ -29,6 +26,7 @@
 
     private CompilerOptions options;
     private HashMap processedTypemap;
+    private HashMap processedElementmap;
     private JavaBeanWriter writer;
 
     private Map baseSchemaTypeMap = TypeMap.getTypeMap();
@@ -48,6 +46,7 @@
             }
 
             this.processedTypemap = new HashMap();
+            this.processedElementmap = new HashMap();
 
             this.writer = new JavaBeanWriter(this.options.getOutputLocation());
 
@@ -98,6 +97,8 @@
             processElement((XmlSchemaElement)xmlSchemaElementIterator.next());
         }
 
+
+
     }
 
     /**
@@ -109,11 +110,31 @@
         //for each and every element and process that accordingly.
         //this means that any unused type definitions would not be generated!
         XmlSchemaType schemaType = xsElt.getSchemaType();
-        if (schemaType!=null){
-            processSchema(schemaType);
+        if (processedElementmap.containsKey(xsElt.getQName())){
+            return;
+        }
+        if (schemaType==null){
+            throw new SchemaCompilationException("Schema type not found!");
         }
+        processSchema(schemaType);
+        QName qName = schemaType.getQName();
 
         //write a class for this element
+        BeanWriterMetaInfoHolder metainf = new BeanWriterMetaInfoHolder();
+        //there can be only one schema type
+        String className = "";
+        if (processedTypemap.containsKey(qName)){
+            className =  processedTypemap.get(qName).toString();
+        }else if (baseSchemaTypeMap.containsKey(qName)){
+            className =  baseSchemaTypeMap.get(qName).toString();
+        }else{
+            //throw an exception here
+        }
+        metainf.addElementInfo(xsElt.getQName(),qName,className);
+
+        String fullyQualifiedClassName = writer.write(xsElt,processedTypemap,metainf);
+        processedElementmap.put(xsElt.getQName(),fullyQualifiedClassName);
+
 
     }
 
@@ -132,7 +153,8 @@
      */
     private void processComplexSchemaType(XmlSchemaComplexType complexType) throws SchemaCompilationException{
 
-        if (processedTypemap.containsKey(complexType.getQName())){
+        if (processedTypemap.containsKey(complexType.getQName())
+                || baseSchemaTypeMap.containsKey(complexType.getQName())){
             return;
         }
 
@@ -145,83 +167,82 @@
             //Process the particle
             processParticle(particle, metaInfHolder);
         }else{
-            XmlSchemaContentModel contentModel = complexType.getContentModel();
-            if (contentModel!=null){
-                XmlSchemaContent content =  (contentModel).getContent();
-                if (content instanceof XmlSchemaComplexContentExtension){
-                    XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = (XmlSchemaComplexContentExtension)
content;
-                    processParticle(xmlSchemaComplexContentExtension.getParticle(),metaInfHolder);
-                    metaInfHolder.setExtension(true);
-                    metaInfHolder.setExtensionClassName(
-                            getJavaClassNameFromComplexTypeQName(
-                                    xmlSchemaComplexContentExtension.getBaseTypeName()));
-                }
-
-
-            }
+            // Process the other types - Say the complex content, extensions and so on
         }
 
         //write the class. This type mapping would have been populated right now
-        writer.write(complexType,processedTypemap,metaInfHolder);
-        processedTypemap.put(complexType.getQName(),"");
+        String fullyQualifiedClassName = writer.write(complexType,processedTypemap,metaInfHolder);
+        processedTypemap.put(complexType.getQName(),fullyQualifiedClassName);
 
         //populate the type mapping with the elements
 
     }
 
     private void processParticle(XmlSchemaParticle particle, //particle being processed
-                                BeanWriterMetaInfoHolder metainfHolder // metainf holder
+                                 BeanWriterMetaInfoHolder metainfHolder // metainf holder
     ) throws SchemaCompilationException {
         if (particle instanceof XmlSchemaSequence ){
             XmlSchemaObjectCollection items = ((XmlSchemaSequence)particle).getItems();
-            int count = items.getCount();
-            for (int i = 0; i < count; i++) {
-                XmlSchemaObject item = items.getItem(i);
-                if (item instanceof XmlSchemaElement){
-                    //recursively process the element
-                    XmlSchemaElement xsElt = (XmlSchemaElement) item;
-                    processElement(xsElt);
-                    //add this to the processed element list
-                    QName schemaTypeQName = xsElt.getSchemaType().getQName();
-                    Class clazz = (Class)baseSchemaTypeMap.get(schemaTypeQName);
-                    if (clazz!=null){
-                        metainfHolder.addElementInfo(xsElt.getQName(),
-                                                     xsElt.getSchemaTypeName()
-                                                     ,clazz.getName());
-                    }else{
-                         metainfHolder.addElementInfo(xsElt.getQName(),
-                                                     xsElt.getSchemaTypeName()
-                                                     ,getJavaClassNameFromComplexTypeQName(schemaTypeQName));
-                    }
-                }else if (item instanceof XmlSchemaComplexContent){
-                    // process the extension
-                    XmlSchemaContent content = ((XmlSchemaComplexContent)item).getContent();
-                    if (content instanceof XmlSchemaComplexContentExtension){
-                        processParticle(((XmlSchemaComplexContentExtension)content).getParticle(),metainfHolder);
-                    }else if (content instanceof XmlSchemaComplexContentRestriction){
-                        //handle complex restriction
-                    }
-                    //handle the other types here
-                }
-
-
-            }
-            //set the ordered flag in the metainf holder
-            metainfHolder.setOrdered(true);
+            process(items, metainfHolder,true);
         }else if (particle instanceof XmlSchemaAll){
-            //handle the all !
+            XmlSchemaObjectCollection items = ((XmlSchemaAll)particle).getItems();
+            process(items, metainfHolder,false);
 
         }else if (particle instanceof XmlSchemaChoice){
             //handle the choice!
         }
     }
 
+    private void process(XmlSchemaObjectCollection items,
+                         BeanWriterMetaInfoHolder metainfHolder,
+                         boolean order) throws SchemaCompilationException {
+        int count = items.getCount();
+        List processedElements = new ArrayList();
+
+        for (int i = 0; i < count; i++) {
+            XmlSchemaObject item = items.getItem(i);
+            if (item instanceof XmlSchemaElement){
+                //recursively process the element
+                XmlSchemaElement xsElt = (XmlSchemaElement) item;
+                processElement(xsElt);
+                processedElements.add(xsElt);
+            }else if (item instanceof XmlSchemaComplexContent){
+                // process the extension
+                XmlSchemaContent content = ((XmlSchemaComplexContent)item).getContent();
+                if (content instanceof XmlSchemaComplexContentExtension){
+                    // handle the complex extension
+                }else if (content instanceof XmlSchemaComplexContentRestriction){
+                    //handle complex restriction
+                }
+                //handle the other types here
+            }
+
+
+        }
+
+        // loop through the processed items and add them to the matainf object
+        int processedCount = processedElements.size();
+        for (int i = 0; i < processedCount; i++) {
+            XmlSchemaElement elt = (XmlSchemaElement)processedElements.get(i);
+            String clazzName = (String)processedElementmap.get(elt.getQName());
+            metainfHolder.addElementInfo(elt.getQName(),
+                    elt.getSchemaTypeName()
+                    ,clazzName);
+
+        }
+        //set the ordered flag in the metainf holder
+        metainfHolder.setOrdered(order);
+    }
+
     /**
      * Handle the simple content
      * @param simpleType
      */
     private void processSimpleSchemaType(XmlSchemaSimpleType simpleType){
-        //nothing to here yet
+        //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));
     }
 
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java?rev=312869&r1=312868&r2=312869&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java
Tue Oct 11 05:54:13 2005
@@ -29,31 +29,31 @@
 
     static{
 // If SOAP 1.1 over the wire, map wrapper classes to XSD primitives.
-        addTypemapping(SchemaConstants.XSD_STRING, java.lang.String.class);
-        addTypemapping(SchemaConstants.XSD_BOOLEAN, java.lang.Boolean.class);
-        addTypemapping(SchemaConstants.XSD_DOUBLE, java.lang.Double.class);
-        addTypemapping(SchemaConstants.XSD_FLOAT, java.lang.Float.class);
-        addTypemapping(SchemaConstants.XSD_INT, java.lang.Integer.class);
-        addTypemapping(SchemaConstants.XSD_INTEGER, java.math.BigInteger.class
+        addTypemapping(SchemaConstants.XSD_STRING, java.lang.String.class.getName());
+        addTypemapping(SchemaConstants.XSD_BOOLEAN, java.lang.Boolean.class.getName());
+        addTypemapping(SchemaConstants.XSD_DOUBLE, java.lang.Double.class.getName());
+        addTypemapping(SchemaConstants.XSD_FLOAT, java.lang.Float.class.getName());
+        addTypemapping(SchemaConstants.XSD_INT, java.lang.Integer.class.getName());
+        addTypemapping(SchemaConstants.XSD_INTEGER, java.math.BigInteger.class.getName()
         );
-        addTypemapping(SchemaConstants.XSD_DECIMAL, java.math.BigDecimal.class
+        addTypemapping(SchemaConstants.XSD_DECIMAL, java.math.BigDecimal.class.getName()
         );
-        addTypemapping(SchemaConstants.XSD_LONG, java.lang.Long.class);
-        addTypemapping(SchemaConstants.XSD_SHORT, java.lang.Short.class);
-        addTypemapping(SchemaConstants.XSD_BYTE, java.lang.Byte.class);
+        addTypemapping(SchemaConstants.XSD_LONG, java.lang.Long.class.getName());
+        addTypemapping(SchemaConstants.XSD_SHORT, java.lang.Short.class.getName());
+        addTypemapping(SchemaConstants.XSD_BYTE, java.lang.Byte.class.getName());
 
         // The XSD Primitives are mapped to java primitives.
-        addTypemapping(SchemaConstants.XSD_BOOLEAN, boolean.class);
-        addTypemapping(SchemaConstants.XSD_DOUBLE, double.class);
-        addTypemapping(SchemaConstants.XSD_FLOAT, float.class);
-        addTypemapping(SchemaConstants.XSD_INT, int.class);
-        addTypemapping(SchemaConstants.XSD_LONG, long.class);
-        addTypemapping(SchemaConstants.XSD_SHORT, short.class);
-        addTypemapping(SchemaConstants.XSD_BYTE, byte.class);
+        addTypemapping(SchemaConstants.XSD_BOOLEAN, boolean.class.getName());
+        addTypemapping(SchemaConstants.XSD_DOUBLE, double.class.getName());
+        addTypemapping(SchemaConstants.XSD_FLOAT, float.class.getName());
+        addTypemapping(SchemaConstants.XSD_INT, int.class.getName());
+        addTypemapping(SchemaConstants.XSD_LONG, long.class.getName());
+        addTypemapping(SchemaConstants.XSD_SHORT, short.class.getName());
+        addTypemapping(SchemaConstants.XSD_BYTE, byte.class.getName());
 
     }
-    private static void addTypemapping(QName name,Class clazz) {
-        typeMap.put( name,clazz);
+    private static void addTypemapping(QName name,String str) {
+        typeMap.put( name,str);
     }
 
 

Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element.xsd?rev=312869&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element.xsd (added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element.xsd Tue
Oct 11 05:54:13 2005
@@ -0,0 +1,18 @@
+<schema targetNamespace="http://soapinterop.org/xsd"
+        xmlns="http://www.w3.org/2001/XMLSchema"
+        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+        xmlns:xsd1="http://soapinterop.org/xsd"
+        elementFormDefault="qualified">
+    <complexType name="SOAPStruct">
+        <all>
+            <element name="varFloat" type="xsd:float"/>
+            <element name="varInt" type="xsd:int"/>
+            <element name="varString" type="xsd:string"/>
+        </all>
+    </complexType>
+    <element name="echoStringParam" type="xsd:string"/>
+    <element name="echoStringReturn" type="xsd:string"/>
+    <element name="echoStructParam" type="xsd1:SOAPStruct"/>
+    <element name="echoStructReturn" type="xsd1:SOAPStruct"/>
+</schema>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/SimpleElementTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/SimpleElementTest.java?rev=312869&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/SimpleElementTest.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/SimpleElementTest.java
Tue Oct 11 05:54:13 2005
@@ -0,0 +1,23 @@
+package org.apache.axis2.databinding.schema;
+/*
+ * 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 SimpleElementTest extends AbstractSchemaCompilerTester {
+    protected void setUp() throws Exception {
+        this.fileName = "test-resources/xsd/simple_element.xsd";
+        super.setUp();
+    }
+}



Mime
View raw message