axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r326082 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/databinding/schema/ src/org/apache/axis2/databinding/schema/template/ test-resources/xsd/ test/org/apache/axis2/databinding/schema/
Date Tue, 18 Oct 2005 10:51:51 GMT
Author: ajith
Date: Tue Oct 18 03:51:12 2005
New Revision: 326082

URL: http://svn.apache.org/viewcvs?rev=326082&view=rev
Log:
Added support for minOccurs/maxOccurs (Array support). The generation of validation code is
yet to be done!

Added:
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs.xsd
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs2.xsd
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlMaxOccurs2.java
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlmaxOccursTest.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/BeanWriterMetaInfoHolder.java
    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/SchemaConstants.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/BeanWriterMetaInfoHolder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/BeanWriterMetaInfoHolder.java?rev=326082&r1=326081&r2=326082&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/BeanWriterMetaInfoHolder.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/BeanWriterMetaInfoHolder.java
Tue Oct 18 03:51:12 2005
@@ -62,7 +62,7 @@
     }
 
     public void registerMapping(QName qName,QName schemaName,String javaClassName){
-           registerMapping(qName,schemaName,javaClassName,SchemaConstants.ELEMENT_TYPE);
+        registerMapping(qName,schemaName,javaClassName,SchemaConstants.ELEMENT_TYPE);
     }
 
     public void registerMapping(QName qName,QName schemaName,String javaClassName,Integer
type){
@@ -76,7 +76,7 @@
         return (QName)this.elementToSchemaQNameMap.get(eltQName);
     }
 
-     public String getJavaClassNameForQName(QName eltQName){
+    public String getJavaClassNameForQName(QName eltQName){
         return (String)this.elementToJavaClassMap.get(eltQName);
     }
 
@@ -84,11 +84,17 @@
         Integer attribState = (Integer) specialTypeFlagMap.get(qName);
         return attribState != null && attribState.equals(SchemaConstants.ATTRIBUTE_TYPE);
     }
-                                                                                        
     
+
     public boolean getAnyStatusForQName(QName qName){
         Integer anyState = (Integer) specialTypeFlagMap.get(qName);
         return anyState != null && anyState.equals(SchemaConstants.ANY_TYPE);
     }
+
+    public boolean getArrayStatusForQName(QName qName){
+        Integer anyState = (Integer) specialTypeFlagMap.get(qName);
+        return anyState != null && anyState.equals(SchemaConstants.ANY_ARRAY_TYPE);
+    }
+
     public void clearTables(){
         this.elementToJavaClassMap.clear();
         this.elementToSchemaQNameMap.clear();

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=326082&r1=326081&r2=326082&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 18 03:51:12 2005
@@ -144,12 +144,17 @@
             }
 
             XSLTUtils.addAttribute(model,"shorttypename",shortTypeName,property);
+
             if (metainf.getAnyStatusForQName(name)){
                 XSLTUtils.addAttribute(model,"any","yes",property);
             }
+
+            if (metainf.getArrayStatusForQName(name)){
+                  XSLTUtils.addAttribute(model,"array","yes",property);
+            }
         }
 
-       
+
         //create the file
         OutputStream out = createOutFile(packageName,className);
         //parse with the template and create the files

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=326082&r1=326081&r2=326082&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 18 03:51:12 2005
@@ -1,7 +1,6 @@
 package org.apache.axis2.databinding.schema;
 
 import org.apache.ws.commons.schema.*;
-import org.apache.axis2.util.URLProcessor;
 import org.apache.axis2.om.OMElement;
 
 import javax.xml.namespace.QName;
@@ -103,6 +102,8 @@
         Iterator  xmlSchemaElement1Iterator = elements.getValues();
         while (xmlSchemaElement1Iterator.hasNext()) {
             //this is the set of outer elements so we need to generate classes
+            //The outermost elements do not contain occurence counts (!) so we do not need
+            //to check for arraytypes
             processElement((XmlSchemaElement)xmlSchemaElement1Iterator.next(),true);
         }
 
@@ -126,24 +127,34 @@
             BeanWriterMetaInfoHolder metainf = new BeanWriterMetaInfoHolder();
             QName qName = schemaType.getQName();
             //find the class name
-            String className = findClassName(schemaType);
+            String className = findClassName(schemaType,isArray(schemaElement));
             metainf.registerMapping(schemaElement.getQName(),
                     qName,
                     className);
             String writtenClassName = writer.write(schemaElement,processedTypemap,metainf);
             processedElementmap.put(schemaElement.getQName(),writtenClassName);
         }
-
-
     }
 
 
-
     /**
      *
      * @param xsElt
+     * @param isOuter
+     * @throws SchemaCompilationException
      */
     private void processElement(XmlSchemaElement xsElt,boolean isOuter) throws SchemaCompilationException{
+        processElement(xsElt,isOuter,false);
+    }
+
+    /**
+     *
+     * @param xsElt
+     * @param isOuter
+     * @param isArray
+     * @throws SchemaCompilationException
+     */
+    private void processElement(XmlSchemaElement xsElt,boolean isOuter,boolean isArray) throws
SchemaCompilationException{
         //The processing element logic seems to be quite simple. Look at the relevant schema
type
         //for each and every element and process that accordingly.
         //this means that any unused type definitions would not be generated!
@@ -162,7 +173,7 @@
             //later
 
             if (!isOuter){
-                String className = findClassName(schemaType);
+                String className = findClassName(schemaType,isArray);
                 this.processedElementmap.put(xsElt.getQName(),className);
             }
             this.processedElementList.add(xsElt.getQName());
@@ -179,7 +190,7 @@
      * @param schemaType
      * @return
      */
-    private String findClassName(XmlSchemaType schemaType) {
+    private String findClassName(XmlSchemaType schemaType,boolean isArray) {
         //find the class name
         QName qName = schemaType.getQName();
         String className;
@@ -192,6 +203,11 @@
             //contained schema type. We better set the default then
             className = OMElement.class.getName();
         }
+        if (isArray){
+            //append the square braces that say this is an array
+            //hope this works for all cases!!!!!!!
+            className = className + "[]";
+        }
         return className;
     }
 
@@ -261,9 +277,9 @@
     private void processAnyAttribute(BeanWriterMetaInfoHolder metainf) {
         //The best thing we can do here is to add a set of OMAttributes
         metainf.registerMapping(new QName("extraAttributes"),
-                                null,
-                                OMElement[].class.getName(),
-                                SchemaConstants.ANY_ATTRIBUTE_TYPE);
+                null,
+                OMElement[].class.getName(),
+                SchemaConstants.ANY_ATTRIBUTE_TYPE);
 
     }
 
@@ -311,15 +327,16 @@
                          BeanWriterMetaInfoHolder metainfHolder,
                          boolean order) throws SchemaCompilationException {
         int count = items.getCount();
-        List processedElements = new ArrayList();
+        Map processedElements = new HashMap();
 
         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,false); //we know for sure this is not an outer type
-                processedElements.add(xsElt);
+                boolean isArray = isArray(xsElt);
+                processElement(xsElt,false,isArray); //we know for sure this is not an outer
type
+                processedElements.put(xsElt, (isArray) ? Boolean.TRUE : Boolean.FALSE);
             }else if (item instanceof XmlSchemaComplexContent){
                 // process the extension
                 XmlSchemaContent content = ((XmlSchemaComplexContent)item).getContent();
@@ -338,13 +355,16 @@
         }
 
         // 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);
+        Iterator processedElementsIterator= processedElements.keySet().iterator();
+        while(processedElementsIterator.hasNext()){
+            XmlSchemaElement elt = (XmlSchemaElement)processedElementsIterator.next();
             String clazzName = (String)processedElementmap.get(elt.getQName());
             metainfHolder.registerMapping(elt.getQName(),
                     elt.getSchemaTypeName()
-                    ,clazzName);
+                    ,clazzName,
+                    ((Boolean)processedElements.get(elt)).booleanValue()?
+                            SchemaConstants.ANY_ARRAY_TYPE:
+                            SchemaConstants.ELEMENT_TYPE);
 
         }
         //set the ordered flag in the metainf holder
@@ -356,12 +376,12 @@
      */
     private void processAny(XmlSchemaAny any,BeanWriterMetaInfoHolder metainf) {
         //handle the minoccurs/maxoccurs here.
-        // However since the any element does not have a name
+        //However since the any element does not have a name
         //we need to put a name here
-          metainf.registerMapping(new QName(ANY_ELEMENT_FIELD_NAME),
-                                null,
-                                OMElement.class.getName(),
-                                SchemaConstants.ANY_TYPE);
+        metainf.registerMapping(new QName(ANY_ELEMENT_FIELD_NAME),
+                null,
+                OMElement.class.getName(),
+                SchemaConstants.ANY_TYPE);
 
     }
 
@@ -375,11 +395,15 @@
     }
 
 
-/*     Utility methods       */
-    private String getJavaClassNameFromComplexTypeQName(QName name){
-        String className = name.getLocalPart();
-        String packageName = URLProcessor.getNameSpaceFromURL(name.getNamespaceURI());
-        return packageName + "." +className;
+    private boolean isArray(XmlSchemaParticle particle) throws SchemaCompilationException{
+        long minOccurs = particle.getMinOccurs();
+        long maxOccurs = particle.getMaxOccurs();
+        if (maxOccurs < minOccurs){
+            throw new SchemaCompilationException();
+        }else{
+            return (maxOccurs>1);
+        }
 
     }
+
 }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaConstants.java?rev=326082&r1=326081&r2=326082&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaConstants.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaConstants.java
Tue Oct 18 03:51:12 2005
@@ -43,7 +43,8 @@
     public static final Integer ATTRIBUTE_TYPE = new Integer(0);
     public static final Integer ANY_TYPE = new Integer(1);
     public static final Integer ELEMENT_TYPE = new Integer(2);
-    public static final Integer ANY_ATTRIBUTE_TYPE = new Integer(3); 
+    public static final Integer ANY_ATTRIBUTE_TYPE = new Integer(3);
+    public static final Integer ANY_ARRAY_TYPE = new Integer(4); 
 
 }
 

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=326082&r1=326081&r2=326082&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
Tue Oct 18 03:51:12 2005
@@ -34,6 +34,8 @@
         /**
          * field for <xsl:value-of select="$javaName"/>
          <xsl:if test="@attribute">* This was an Attribute!</xsl:if>
+         <xsl:if test="@array">* This was an Array!</xsl:if>
+
          */
          private <xsl:value-of select="$propertyType"/> local<xsl:value-of select="$javaName"/>;
 

Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs.xsd?rev=326082&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs.xsd (added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs.xsd Tue
Oct 18 03:51:12 2005
@@ -0,0 +1,15 @@
+<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">
+        <sequence>
+            <element name="varFloat" type="xsd:float"/>
+            <element name="varInt" type="xsd:int"/>
+            <element name="varString" type="xsd:string" maxOccurs="10"/>
+        </sequence>
+    </complexType>
+    <element name="myobject" type="xsd1:SOAPStruct" />
+</schema>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs2.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs2.xsd?rev=326082&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs2.xsd
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_maxOccurs2.xsd
Tue Oct 18 03:51:12 2005
@@ -0,0 +1,20 @@
+<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">
+        <sequence>
+            <element name="varFloat" type="xsd:float"/>
+            <element name="varInt" type="xsd:int"/>
+            <element name="varString" type="xsd:string" maxOccurs="10"/>
+        </sequence>
+    </complexType>
+    <complexType name="SOAPStructArray">
+        <sequence>
+            <element name="soapStructures" type="xsd1:SOAPStruct" maxOccurs="10"></element>
+        </sequence>
+    </complexType>
+    <element name="myobject" type="xsd1:SOAPStructArray" />
+</schema>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlMaxOccurs2.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlMaxOccurs2.java?rev=326082&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlMaxOccurs2.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlMaxOccurs2.java
Tue Oct 18 03:51:12 2005
@@ -0,0 +1,24 @@
+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 XmlMaxOccurs2 extends AbstractSchemaCompilerTester{
+    protected void setUp() throws Exception {
+        this.fileName = "test-resources/xsd/simple_maxOccurs2.xsd";
+        super.setUp();
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlmaxOccursTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlmaxOccursTest.java?rev=326082&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlmaxOccursTest.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/XmlmaxOccursTest.java
Tue Oct 18 03:51:12 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 XmlmaxOccursTest extends AbstractSchemaCompilerTester{
+       protected void setUp() throws Exception {
+        this.fileName = "test-resources/xsd/simple_maxOccurs.xsd";
+        super.setUp();
+    }
+}



Mime
View raw message