axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r375022 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/schema/ src/org/apache/axis2/schema/template/ src/org/apache/axis2/schema/writer/ test-resources/xsd/
Date Sun, 05 Feb 2006 13:10:50 GMT
Author: ajith
Date: Sun Feb  5 05:10:49 2006
New Revision: 375022

URL: http://svn.apache.org/viewcvs?rev=375022&view=rev
Log:
Halfway through in implementing the nillable support for ADB.
Build passes since I have not added test cases that test this functionality

Added:
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_nillable.xsd
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java?rev=375022&r1=375021&r2=375022&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
Sun Feb  5 05:10:49 2006
@@ -46,6 +46,8 @@
     protected Map qNameMinOccursCountMap = new HashMap();
     protected Map qNameOrderMap = new HashMap();
 
+    protected List nillableQNameList  = new ArrayList();
+
 
 
     //the parent metainfo holder, useful in handling extensions and
@@ -155,6 +157,27 @@
         registerMapping(qName, schemaName, javaClassName, SchemaConstants.ELEMENT_TYPE);
     }
 
+
+    /* Registers a Qname as nillable
+     * The qName better be of an element
+     *
+     * @param qName
+     * @param schemaName
+     * @param javaClassName
+     */
+    public void registerNillableQName(QName eltQName) {
+        nillableQNameList.add(eltQName);
+    }
+
+    /**
+     * Returns whether a QName is nillable or not
+     * @param eltQName
+     * @return
+     */
+    public boolean isNillable(QName eltQName) {
+        return nillableQNameList.contains(eltQName);
+    }
+
     /**
      * Registers a mapping.
      *
@@ -342,7 +365,7 @@
         QName[] allNames = getQNameArray();
         for (int i = 0; i < allNames.length; i++) {
             if(getAttributeStatusForQName(allNames[i])){
-              returnQNames.add(allNames[i]);
+                returnQNames.add(allNames[i]);
             }
         }
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=375022&r1=375021&r2=375022&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
Sun Feb  5 05:10:49 2006
@@ -80,9 +80,11 @@
     // of types
     private HashMap processedTypeMetaInfoMap;
 
-
+    //
     private ArrayList processedElementList;
 
+    //
+    private List nillableElementList;
 
     private BeanWriter writer = null;
 
@@ -135,6 +137,7 @@
         changedTypeMap = new HashMap();
         processedTypeMetaInfoMap = new HashMap();
         processedElementRefMap = new HashMap();
+        nillableElementList = new ArrayList();
 
         //load the writer a nd initiliaze the base type
         writer = SchemaPropertyLoader.getBeanWriterInstance();
@@ -248,6 +251,7 @@
             QName qName = schemaType.getQName();
             //find the class name
             String className = findClassName(qName, isArray(xsElt));
+
             //this means the schema type actually returns a different QName
             if (changedTypeMap.containsKey(qName)) {
                 metainf.registerMapping(xsElt.getQName(),
@@ -261,7 +265,7 @@
 
 
         }else if (xsElt.getRefName()!= null){
-            //Since top level elements would not have references
+            // Since top level elements would not have references
             // and we only write toplevel elements, this should
             // not be a problem , atleast should not occur in a legal schema
         }else if (xsElt.getSchemaTypeName()!= null) {
@@ -282,23 +286,17 @@
             metainf.setAnonymous(true);
         }
 
+        if (nillableElementList.contains(xsElt.getQName())){
+            metainf.registerNillableQName(xsElt.getQName());
+        }
+
 
         String writtenClassName = writer.write(xsElt, processedTypemap, metainf);
         processedElementMap.put(xsElt.getQName(), writtenClassName);
     }
 
 
-    /**
-     * Process the element
-     *
-     * @param xsElt
-     * @param isOuter - We need to know this since the treatment of outer elements is different
that
-     *                inner elements
-     * @throws SchemaCompilationException
-     */
-    private void processElement(XmlSchemaElement xsElt, boolean isOuter,XmlSchema parenSchema)
throws SchemaCompilationException {
-        processElement(xsElt, isOuter, false, parenSchema);
-    }
+
 
     /**
      * Process and Element
@@ -309,7 +307,8 @@
      * @param isArray-  flag saying whether the elements represents an array
      * @throws SchemaCompilationException
      */
-    private void processElement(XmlSchemaElement xsElt, boolean isOuter, boolean isArray,XmlSchema
parentSchema) throws SchemaCompilationException {
+    private void processElement(XmlSchemaElement xsElt, boolean isOuter,XmlSchema parentSchema)
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!
@@ -325,7 +324,6 @@
             //pass through. We'll be iterating through the elements writing them
             //later
 
-
             if (!isOuter) {
                 String className = findClassName(schemaType.getQName(), isArray(xsElt));
                 this.processedElementMap.put(xsElt.getQName(), className);
@@ -360,8 +358,10 @@
             this.processedElementList.add(xsElt.getQName());
         }
 
-
-
+        //add this elements QName to the nillable group if it has the  nillable attribute
+        if (xsElt.isNillable()){
+            this.nillableElementList.add(xsElt.getQName());
+        }
 
     }
 
@@ -637,7 +637,8 @@
     }
 
     private void processSimpleContent(XmlSchemaSimpleContent simpleContent,BeanWriterMetaInfoHolder
metaInfHolder){
-        XmlSchemaContent content = simpleContent.getContent();
+        XmlSchemaContent content;
+        content = simpleContent.getContent();
         if (content instanceof XmlSchemaSimpleContentExtension){
             //todo - handle simple type extension here
         }else if (content instanceof XmlSchemaSimpleContentRestriction){
@@ -723,7 +724,7 @@
                 XmlSchemaElement xsElt = (XmlSchemaElement) item;
 
                 boolean isArray = isArray(xsElt);
-                processElement(xsElt, false, isArray,parentSchema); //we know for sure this
is not an outer type
+                processElement(xsElt, false,parentSchema); //we know for sure this is not
an outer type
                 processedElements.put(xsElt, (isArray) ? Boolean.TRUE : Boolean.FALSE);
                 if (order) {
                     //we need to keep the order of the elements. So push the elements to
another
@@ -735,7 +736,8 @@
             } else if (item instanceof XmlSchemaAny) {
                 processAny((XmlSchemaAny) item, metainfHolder);
             } else {
-                //there are other types to be handled
+                //there may be other types to be handled here. Add them
+                //when we are ready
             }
 
 
@@ -747,7 +749,8 @@
         while (processedElementsIterator.hasNext()) {
             XmlSchemaElement elt = (XmlSchemaElement) processedElementsIterator.next();
             String clazzName;
-            QName qName = null;
+            QName qName;
+
             if (elt.getQName()!=null){ //probably this is referenced
                 clazzName = (String) processedElementMap.get(elt.getQName());
                 qName = elt.getQName();
@@ -779,6 +782,11 @@
                 Integer integer = (Integer) elementOrderMap.get(elt);
                 metainfHolder.registerQNameIndex(qName,
                         startingItemNumberOrder + integer.intValue());
+            }
+
+            //get the nillable state and register that on the metainf holder
+            if (nillableElementList.contains(elt.getQName())){
+                metainfHolder.registerNillableQName(elt.getQName());
             }
 
         }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?rev=375022&r1=375021&r2=375022&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
Sun Feb  5 05:10:49 2006
@@ -67,15 +67,15 @@
         </xsl:choose>
 
         <xsl:if test="$choice">
-                    /** Whenever a new property is set ensure all others are unset
-                     *  There can be only one choice and the last one wins
-                     */
-                    private void clearAllSettingTrackers() {
-                    <xsl:for-each select="property">
-                        local<xsl:value-of select="@javaname"/>Tracker = false;
-                   </xsl:for-each>
-                    }
-                </xsl:if>
+            /** Whenever a new property is set ensure all others are unset
+             *  There can be only one choice and the last one wins
+             */
+            private void clearAllSettingTrackers() {
+            <xsl:for-each select="property">
+                local<xsl:value-of select="@javaname"/>Tracker = false;
+           </xsl:for-each>
+            }
+        </xsl:if>
 
 
         <xsl:for-each select="property">
@@ -141,6 +141,8 @@
              </xsl:if>
             this.<xsl:value-of select="$varName"/>=param;
             }
+
+             <!-- end of xsl:if for not(@inherited) -->
             </xsl:if>
         </xsl:for-each>
 
@@ -152,7 +154,7 @@
 
 
         <xsl:choose>
-            <xsl:when test="@type|@anon">
+            <xsl:when test="@type or @anon">
                  java.util.ArrayList elementList = new java.util.ArrayList();
                  java.util.ArrayList attribList = new java.util.ArrayList();
 
@@ -166,20 +168,34 @@
 
                     <xsl:if test="$min=0 or $choice"> if (<xsl:value-of select="$settingTracker"/>){</xsl:if>
                     <xsl:choose>
-                        <xsl:when test="@ours or @any or @default">
-                            elementList.add(new javax.xml.namespace.QName("<xsl:value-of
select="$namespace"/>",
-                                                                      "<xsl:value-of select="$propertyName"/>"));
-                            elementList.add(<xsl:value-of select="$varName"/>);
-                        </xsl:when>
-                        <xsl:when test="@array">
+                        <xsl:when test="@ours or @any or @default or @array">
                             elementList.add(new javax.xml.namespace.QName("<xsl:value-of
select="$namespace"/>",
                                                                       "<xsl:value-of select="$propertyName"/>"));
+                            <!-- Arraylist can handle null's -->
+                                 <xsl:choose>
+                                    <xsl:when test="@nillable">
+                                     elementList.add(<xsl:value-of select="$varName"/>==null?null:
+                                     <xsl:value-of select="$varName"/>);
+                                     </xsl:when>
+                                     <xsl:otherwise>
+                                      if (<xsl:value-of select="$varName"/>==null){
+                                         throw new RuntimeException("<xsl:value-of select="$propertyName"/>
cannot be null!!");
+                                      }
+                                      elementList.add(<xsl:value-of select="$varName"/>);
+                                     </xsl:otherwise>
+                                   </xsl:choose>
                             elementList.add(<xsl:value-of select="$varName"/>);
                         </xsl:when>
                         <xsl:otherwise>
                              elementList.add(new javax.xml.namespace.QName("<xsl:value-of
select="$namespace"/>",
                                                                       "<xsl:value-of select="$propertyName"/>"));
-                             elementList.add(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of
select="$varName"/>));
+                             <!-- for some primitive types - there's no concept of a null,
say for int. hence we
+                                  are unbale to test for null unless a supporting parameter
is supplied to say
+                                  whether a type is primitive or not -->
+
+                            elementList.add(
+                            org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of
select="$varName"/>));
+
                         </xsl:otherwise>
                     </xsl:choose>
                     <xsl:if test="$min=0 or $choice">}</xsl:if>
@@ -203,29 +219,29 @@
                 </xsl:for-each>
 
                 return org.apache.axis2.databinding.utils.ADBPullParser.createPullParser(qName,
elementList.toArray(), attribList.toArray());
+            <!-- end of when for type & anon -->    
             </xsl:when>
+            <!-- Not a type and not anon. So it better be only one inclusion-->
             <xsl:otherwise>
                 <!-- if the element is associated with a type, then its gonna be only
one -->
                 //We can safely assume an element has only one type associated with it
-                <!-- This better be only one!!-->
-                <xsl:for-each select="property[@ours]">
-                    <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
-                    <xsl:variable name="varName">local<xsl:value-of select="@javaname"/></xsl:variable>
-                    return <xsl:value-of select="$varName"/>.getPullParser(MY_QNAME);
-                </xsl:for-each>
-
-                <!-- What do we do for the other case ???? -->
-                <xsl:for-each select="property[not(@ours)]">
-                    <xsl:variable name="varName">local<xsl:value-of select="@javaname"/></xsl:variable>
-                    return org.apache.axis2.databinding.utils.ADBPullParser.createPullParser(MY_QNAME,
-                    new Object[]{
-                    org.apache.axis2.databinding.utils.ADBPullParser.ELEMENT_TEXT,
-                    org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of
select="$varName"/>)
-                    },
-                    new Object[]{});
-
 
-                </xsl:for-each>
+                <xsl:choose>
+                    <!-- This better be only one!!-->
+                    <xsl:when test="property/@ours">
+                        <xsl:variable name="varName">local<xsl:value-of select="property/@javaname"/></xsl:variable>
+                        return <xsl:value-of select="$varName"/>.getPullParser(MY_QNAME);
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:variable name="varName">local<xsl:value-of select="property/@javaname"/></xsl:variable>
+                        return org.apache.axis2.databinding.utils.ADBPullParser.createPullParser(MY_QNAME,
+                            new Object[]{
+                            org.apache.axis2.databinding.utils.ADBPullParser.ELEMENT_TEXT,
+                            org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of
select="$varName"/>)
+                            },
+                            new Object[]{});
+                    </xsl:otherwise>
+                </xsl:choose>
             </xsl:otherwise>
         </xsl:choose>
 
@@ -343,6 +359,9 @@
                                     if (javax.xml.stream.XMLStreamConstants.START_ELEMENT
== event
                                             &amp;&amp; <xsl:value-of select="$startQname"/>.equals(reader.getName())){
 
+                                    <!-- todo put the code here for nillable -->
+
+
                                     // We need to wrap the reader so that it produces a fake
START_DOCUEMENT event
                                     org.apache.axis2.databinding.utils.NamedStaxOMBuilder
<xsl:value-of select="$builderName"/> = new org.apache.axis2.databinding.utils.NamedStaxOMBuilder(
                                             new org.apache.axis2.util.StreamWrapper(reader),<xsl:value-of
select="$startQname"/>);
@@ -409,7 +428,9 @@
                     }
                 }
 
+                <!-- todo  put the code here for nillable -->
                 // We need to wrap the reader so that it produces a fake START_DOCUEMENT
event
+                // this is needed by the builder classes
                 org.apache.axis2.databinding.utils.NamedStaxOMBuilder <xsl:value-of select="$builderName"/>
= new org.apache.axis2.databinding.utils.NamedStaxOMBuilder(
                         new org.apache.axis2.util.StreamWrapper(reader),<xsl:value-of
select="$startQname"/>);
                 object.set<xsl:value-of select="$javaName"/>(<xsl:value-of select="$builderName"/>.getOMElement());

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=375022&r1=375021&r2=375022&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
Sun Feb  5 05:10:49 2006
@@ -352,6 +352,9 @@
             XSLTUtils.addAttribute(model, "choice", "yes", rootElt);
         }
 
+        if (metainf.isOrdered()) {
+            XSLTUtils.addAttribute(model, "ordered", "yes", rootElt);
+        }
 
         //populate all the information
         populateInfo(metainf, model, rootElt, propertyNames, typeMap,false);
@@ -431,6 +434,10 @@
 
             if (metainf.getAttributeStatusForQName(name)) {
                 XSLTUtils.addAttribute(model, "attribute", "yes", property);
+            }
+
+            if (metainf.isNillable(name)){
+                XSLTUtils.addAttribute(model, "nillable", "yes", property);
             }
 
             String shortTypeName = "";

Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_nillable.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_nillable.xsd?rev=375022&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_nillable.xsd (added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_nillable.xsd Sun
Feb  5 05:10:49 2006
@@ -0,0 +1,13 @@
+<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">
+    <complexType name="SOAPStruct1">
+        <sequence>
+            <element name="varString" type="xsd:string" nillable="true"/>
+            <element name="varInt" type="xsd:int"/>
+            <element name="varFloat" type="xsd:float"/>
+        </sequence>
+    </complexType>
+    <element name="myElementNillable" type="tns:SOAPStruct1" nillable="true"/>
+</schema>
\ No newline at end of file



Mime
View raw message