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/18 09:41:27 UTC

svn commit: r326045 - 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/

Author: ajith
Date: Tue Oct 18 00:40:47 2005
New Revision: 326045

URL: http://svn.apache.org/viewcvs?rev=326045&view=rev
Log:
Added support for xsd:any. Still have to modify the generation/writing code in the template

Added:
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_any.xsd
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/SimpleAnyTest.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
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_attrib.xsd

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=326045&r1=326044&r2=326045&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 00:40:47 2005
@@ -23,15 +23,19 @@
 /**
  * This is a class used as a holder to pass on the meta information to the bean writer
  * This meta information will be used by the writer to write the databinding conversion code
+ * Note - Metainfholders are not meant to be reused!!!. They are per-class basis
  */
 public class BeanWriterMetaInfoHolder {
 
+
+
     private boolean ordered = false;
     private boolean extension = false;
+//    private boolean hasAny = false;
     private String extensionClassName = "";
     private Map elementToSchemaQNameMap = new HashMap();
     private Map elementToJavaClassMap = new HashMap();
-    private Map attributeFlagMap = new HashMap();
+    private Map specialTypeFlagMap = new HashMap();
 
     public String getExtensionClassName() {
         return extensionClassName;
@@ -58,13 +62,13 @@
     }
 
     public void registerMapping(QName qName,QName schemaName,String javaClassName){
-           registerMapping(qName,schemaName,javaClassName,false);
+           registerMapping(qName,schemaName,javaClassName,SchemaConstants.ELEMENT_TYPE);
     }
 
-    public void registerMapping(QName qName,QName schemaName,String javaClassName,boolean isAttribute){
+    public void registerMapping(QName qName,QName schemaName,String javaClassName,Integer type){
         this.elementToJavaClassMap.put(qName,javaClassName);
         this.elementToSchemaQNameMap.put(qName,schemaName);
-        this.attributeFlagMap.put(qName,new Boolean(isAttribute));
+        this.specialTypeFlagMap.put(qName,type);
 
     }
 
@@ -77,8 +81,13 @@
     }
 
     public boolean getAttributeStatusForQName(QName qName){
-        Boolean aBoolean = (Boolean) attributeFlagMap.get(qName);
-        return aBoolean != null && aBoolean.booleanValue();
+        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 void clearTables(){
         this.elementToJavaClassMap.clear();
@@ -89,5 +98,6 @@
     public Iterator getElementQNameIterator(){
         return elementToJavaClassMap.keySet().iterator();
     }
+
 
 }

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=326045&r1=326044&r2=326045&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 00:40:47 2005
@@ -126,7 +126,11 @@
             XSLTUtils.addAttribute(model,"name",xmlName,property);
             XSLTUtils.addAttribute(model,"javaname",javaName,property);
             String javaClassNameForElement = metainf.getJavaClassNameForQName(name);
-            String shortTypeName = metainf.getSchemaQNameForQName(name).getLocalPart();
+            String shortTypeName = "";
+            if (metainf.getSchemaQNameForQName(name)!=null){
+                shortTypeName = metainf.getSchemaQNameForQName(name).getLocalPart();
+            }
+
             if (javaClassNameForElement==null){
                 throw new SchemaCompilationException("Type missing!");
             }
@@ -140,8 +144,12 @@
             }
 
             XSLTUtils.addAttribute(model,"shorttypename",shortTypeName,property);
+            if (metainf.getAnyStatusForQName(name)){
+                XSLTUtils.addAttribute(model,"any","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=326045&r1=326044&r2=326045&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 00:40:47 2005
@@ -36,6 +36,7 @@
     private JavaBeanWriter writer;
 
     private Map baseSchemaTypeMap = TypeMap.getTypeMap();
+    private static final String ANY_ELEMENT_FIELD_NAME = "extraElements";
 
 
     public HashMap getProcessedElementmap() {
@@ -173,6 +174,11 @@
 
     }
 
+    /**
+     *
+     * @param schemaType
+     * @return
+     */
     private String findClassName(XmlSchemaType schemaType) {
         //find the class name
         QName qName = schemaType.getQName();
@@ -232,6 +238,12 @@
 
             }
         }
+
+        //process any attribute
+        XmlSchemaAnyAttribute anyAtt = complexType.getAnyAttribute();
+        if (anyAtt!=null){
+            processAnyAttribute();
+        }
         // Process the other types - Say the complex content, extensions and so on
 
 
@@ -245,13 +257,19 @@
 
     }
 
+    private void processAnyAttribute(BeanWriterMetaInfoHolder metainf) {
+        //The best thing we can do here is to add a set of OMAttributes
+        metainf.registerMapping(new QName(""))
+
+    }
+
     public void processAttribute(XmlSchemaAttribute att,BeanWriterMetaInfoHolder metainf){
-         //for now we assume (!!!) that attributes refer to standard types only
+        //for now we assume (!!!) that attributes refer to standard types only
         QName schemaTypeName = att.getSchemaTypeName();
         if (baseSchemaTypeMap.containsKey(schemaTypeName)){
             metainf.registerMapping(att.getQName(),
-                     schemaTypeName,
-                     baseSchemaTypeMap.get(schemaTypeName).toString(),true);
+                    schemaTypeName,
+                    baseSchemaTypeMap.get(schemaTypeName).toString(),SchemaConstants.ATTRIBUTE_TYPE);
         } else {
             //this attribute refers to a custom type, probably one of the extended simple types.
             //handle it here
@@ -306,7 +324,10 @@
                 }else if (content instanceof XmlSchemaComplexContentRestriction){
                     //handle complex restriction
                 }
-                //handle the other types here
+
+                //handle xsd:any ! We place an OMElement in the generated class
+            }else if (item instanceof XmlSchemaAny){
+                processAny((XmlSchemaAny)item,metainfHolder);
             }
 
 
@@ -324,6 +345,20 @@
         }
         //set the ordered flag in the metainf holder
         metainfHolder.setOrdered(order);
+    }
+
+    /**
+     *
+     */
+    private void processAny(XmlSchemaAny any,BeanWriterMetaInfoHolder metainf) {
+        //handle the minoccurs/maxoccurs here.
+        // 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);
+
     }
 
     /**

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=326045&r1=326044&r2=326045&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 00:40:47 2005
@@ -37,5 +37,12 @@
     public static final QName XSD_DATETIME = new QName(URI_DEFAULT_SCHEMA_XSD, "dateTime");
     public static final QName XSD_DATE = new QName(URI_DEFAULT_SCHEMA_XSD, "date");
     public static final QName XSD_TIME = new QName(URI_DEFAULT_SCHEMA_XSD, "time");
+
+
+
+    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); 
+
 }
 

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=326045&r1=326044&r2=326045&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 00:40:47 2005
@@ -68,6 +68,9 @@
                   <xsl:when test="@ours">
                       new javax.xml.namespace.QName("<xsl:value-of select="$propertyName"/>"),local<xsl:value-of select="@javaname"/>
                   </xsl:when>
+                  <xsl:when test="@any">
+                      null,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>
@@ -108,6 +111,9 @@
                    <xsl:when test="@ours">
                      object.set<xsl:value-of select="$javaName"/>(
                           <xsl:value-of select="$propertyType"/>.parse(reader));
+                  </xsl:when>
+                  <xsl:when test="@any">
+                      //do nothing yet!!!!
                   </xsl:when>
                   <xsl:otherwise>
                       String content = reader.getElementText();

Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_any.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_any.xsd?rev=326045&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_any.xsd (added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_any.xsd Tue Oct 18 00:40:47 2005
@@ -0,0 +1,17 @@
+<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"/>
+            <any></any>
+        </sequence>
+
+    </complexType>
+    <element name="myobject" type="xsd1:SOAPStruct"/>
+</schema>
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_attrib.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_attrib.xsd?rev=326045&r1=326044&r2=326045&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_attrib.xsd (original)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_attrib.xsd Tue Oct 18 00:40:47 2005
@@ -12,7 +12,8 @@
         </all>
         <attribute name="type1" type="xsd:string"></attribute>
         <attribute name="type2" type="xsd:string"></attribute>
-            
+        <attribute name="type3" type="xsd:int"></attribute>
+        <attribute name="type4" type="xsd:float"></attribute>
     </complexType>
     <element name="echoStringParam" type="xsd:string"/>
     <element name="echoStringReturn" type="xsd:string"/>

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