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 ds...@apache.org on 2007/04/20 02:50:58 UTC

svn commit: r530596 - in /webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx: CodeGenerationUtility.java template/JibXDatabindingTemplate.xsl

Author: dsosnoski
Date: Thu Apr 19 17:50:58 2007
New Revision: 530596

URL: http://svn.apache.org/viewvc?view=rev&rev=530596
Log:
Support for polymorphism, improved error checking

Modified:
    webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
    webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl

Modified: webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java?view=diff&rev=530596&r1=530595&r2=530596
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java (original)
+++ webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java Thu Apr 19 17:50:58 2007
@@ -379,16 +379,16 @@
                     dbmethod.setAttribute("method-name", op.getName().getLocalPart());
                     Set nameset = new HashSet(s_reservedWords);
                     if (inmsg != null) {
-                        Element wrapper = unwrapMessage(inmsg, false, simpleTypeMap, complexTypeMap,
-                                                        typeMappedClassMap, bindingMap, nameset,
-                                                        nsMap, doc);
+                        Element wrapper = unwrapMessage(inmsg, false, simpleTypeMap, elementMap,
+                                                        complexTypeMap, typeMappedClassMap,
+                                                        bindingMap, nameset, nsMap, doc);
                         dbmethod.appendChild(wrapper);
                         wrappers.add(wrapper);
                     }
                     if (outmsg != null) {
-                        Element wrapper = unwrapMessage(outmsg, true, simpleTypeMap, complexTypeMap,
-                                                        typeMappedClassMap, bindingMap, nameset,
-                                                        nsMap, doc);
+                        Element wrapper = unwrapMessage(outmsg, true, simpleTypeMap, elementMap,
+                                                        complexTypeMap, typeMappedClassMap,
+                                                        bindingMap, nameset, nsMap, doc);
                         dbmethod.appendChild(wrapper);
                         wrappers.add(wrapper);
                     }
@@ -672,6 +672,7 @@
      * @param msg                message to be unwrapped
      * @param isout              output message flag (wrapper inherits inner type, for XSLTs)
      * @param simpleTypeMap      binding formats
+     * @param elementMap         map from element names to concrete mapping components of binding
      * @param complexTypeMap     binding mappings
      * @param typeMappedClassMap map from type qname to index
      * @param bindingMap         map from mapping components to containing binding definition
@@ -682,7 +683,7 @@
      * @return detailed description element for code generation
      */
     private Element unwrapMessage(AxisMessage msg, boolean isout,
-                                  Map simpleTypeMap, Map complexTypeMap, Map typeMappedClassMap,
+                                  Map simpleTypeMap, Map elementMap, Map complexTypeMap, Map typeMappedClassMap,
                                   Map bindingMap, Set nameset, Map nsmap, Document doc) {
 
         // find the schema definition for this message element
@@ -738,14 +739,15 @@
                     XmlSchemaParticle item = (XmlSchemaParticle)iter.next();
                     if (!(item instanceof XmlSchemaElement)) {
                         throw new RuntimeException("Cannot unwrap element " +
-                                qname + ": only element items allowed in seqence");
+                                qname + ": only element items allowed in sequence");
                     }
                     XmlSchemaElement element = (XmlSchemaElement)item;
+                    QName refname = element.getRefName();
                     QName typename = element.getSchemaTypeName();
-                    if (typename == null) {
+                    if (refname == null && typename == null) {
                         throw new RuntimeException("Cannot unwrap element " +
                                 qname +
-                                ": all elements in contained sequence must reference a named type");
+                                ": all elements in contained sequence must be element references or reference a named type");
                     }
                     if (first) {
                         first = false;
@@ -758,7 +760,7 @@
                     // add element to output with details of this element handling
                     Element param =
                             doc.createElement(isout ? "return-element" : "parameter-element");
-                    QName itemname = element.getQName();
+                    QName itemname = (refname == null) ? element.getQName() : refname;
                     nons = nons || itemname.getNamespaceURI().length() == 0;
                     param.setAttribute("ns", itemname.getNamespaceURI());
                     param.setAttribute("name", itemname.getLocalPart());
@@ -805,24 +807,50 @@
                         }
 
                     } else {
+                        
+                        // conversion must be defined by mapping
+                        MappingElement mapping;
+                        if (refname == null) {
+
+                            // complex type reference translates to abstract mapping in binding
+                            mapping = (MappingElement)complexTypeMap.get(typename);
+                            if (mapping == null) {
+                                throw new RuntimeException("Cannot unwrap element " +
+                                        qname + ": no abstract mapping definition found for type " +
+                                        typename + " (used by element " + itemname + ')');
+                            }
+                            Integer tindex = (Integer)typeMappedClassMap.get(typename);
+                            if (tindex == null) {
+                                tindex = new Integer(typeMappedClassMap.size());
+                                typeMappedClassMap.put(typename, tindex);
+                            }
+                            param.setAttribute("type-index", tindex.toString());
+                            
+                        } else {
+                            
+                            // element reference translates to concrete mapping
+                            mapping = (MappingElement)elementMap.get(refname);
+                            if (mapping == null) {
+                                throw new RuntimeException("Cannot unwrap element " +
+                                        qname + ": no concrete mapping definition found for element " +
+                                        refname + " (used by element " + itemname + ')');
+                            }
+                            param.setAttribute("type-index", "");
+                            
+                        }
 
-                        // complex type translates to abstract mapping in binding
+                        // configure based on the mapping information
+                        param.setAttribute("form", "complex");
                         complex = true;
-                        MappingElement mapping = (MappingElement)complexTypeMap.get(typename);
-                        if (mapping == null) {
-                            throw new RuntimeException("Cannot unwrap element " +
-                                    qname + ": no abstract mapping definition found for type " +
-                                    typename + " (used by element " + itemname + ')');
-                        }
-                        Integer tindex = (Integer)typeMappedClassMap.get(typename);
-                        if (tindex == null) {
-                            tindex = new Integer(typeMappedClassMap.size());
-                            typeMappedClassMap.put(typename, tindex);
-                        }
                         javatype = mapping.getClassName();
                         createtype = mapping.getCreateType();
-                        param.setAttribute("form", "complex");
-                        param.setAttribute("type-index", tindex.toString());
+                        if (createtype == null && mapping.isAbstract() &&
+                            mapping.getExtensionTypes().isEmpty()) {
+                            
+                            // abstract mapping with no extensions requires instance
+                            //  this assumes the mapped type can be created, but no easy way to check
+                            createtype = javatype;
+                        }
 
                         // merge contained namespace definitions into set for operation
                         Iterator citer = mapping.topChildIterator();
@@ -1038,12 +1066,14 @@
             } else if (child.type() == ElementBase.MAPPING_ELEMENT) {
                 MappingElement mapping = (MappingElement)child;
                 bindingMap.put(mapping, binding);
-                if (mapping.isAbstract()) {
+                if (mapping.isAbstract() && mapping.getTypeQName() != null) {
 
                     // register named abstract mappings as complex type conversions
                     registerElement(mapping.getTypeQName(), mapping,
                                     complexTypeMap);
 
+                } else if (mapping.getName() == null) {
+                    throw new RuntimeException("Non-abstract mapping for class " + mapping.getClassName() + " needs element name.");
                 } else {
 
                     // register concrete mappings as element conversions

Modified: webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl?view=diff&rev=530596&r1=530595&r2=530596
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl (original)
+++ webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl Thu Apr 19 17:50:58 2007
@@ -183,7 +183,14 @@
                           if (bindingFactory == null) {
                               throw new RuntimeException(bindingErrorMessage);
                           }
+            <xsl:choose>
+              <xsl:when test="out-wrapper/return-element/@form='complex' and out-wrapper/return-element/@type-index=''">
+                          org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource((org.jibx.runtime.IMarshallable)result, bindingFactory);
+              </xsl:when>
+              <xsl:otherwise>
                           org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(result, _type_index<xsl:value-of select="out-wrapper/return-element/@type-index"/>, "<xsl:value-of select='out-wrapper/return-element/@name'/>", "<xsl:value-of select='out-wrapper/return-element/@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory);
+              </xsl:otherwise>
+            </xsl:choose>
                           org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='out-wrapper/return-element/@ns'/>", "");
                           org.apache.axiom.om.OMElement child = factory.createOMElement(src, "<xsl:value-of select='out-wrapper/return-element/@name'/>", appns);
                           wrapper.addChild(child);
@@ -248,7 +255,14 @@
                   if (bindingFactory == null) {
                       throw new RuntimeException(bindingErrorMessage);
                   }
+            <xsl:choose>
+              <xsl:when test="out-wrapper/return-element/@form='complex' and out-wrapper/return-element/@type-index=''">
+                  org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource((org.jibx.runtime.IMarshallable)result, bindingFactory);
+              </xsl:when>
+              <xsl:otherwise>
                   org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(result, _type_index<xsl:value-of select="out-wrapper/return-element/@type-index"/>, "<xsl:value-of select='out-wrapper/return-element/@name'/>", "<xsl:value-of select='out-wrapper/return-element/@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory);
+              </xsl:otherwise>
+            </xsl:choose>
                   org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='out-wrapper/return-element/@ns'/>", "");
                   org.apache.axiom.om.OMElement child = factory.createOMElement(src, "<xsl:value-of select='out-wrapper/return-element/@name'/>", appns);
                   wrapper.addChild(child);
@@ -597,6 +611,14 @@
         child = factory.createOMElement("<xsl:value-of select='@name'/>", "<xsl:value-of select='@ns'/>", "<xsl:value-of select='@prefix'/>");
         child.setText(<xsl:value-of select="@serializer"/>(<xsl:call-template name="parameter-or-array-item"/>));
       </xsl:when>
+      <xsl:when test="@form='complex' and @type-index=''">
+        if (bindingFactory == null) {
+            throw new RuntimeException(bindingErrorMessage);
+        }
+        org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource((org.jibx.runtime.IMarshallable)<xsl:call-template name="parameter-or-array-item"/>, bindingFactory);
+        org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='@ns'/>", "");
+        child = factory.createOMElement(src, "<xsl:value-of select='@name'/>", appns);
+      </xsl:when>
       <xsl:when test="@form='complex'">
         if (bindingFactory == null) {
             throw new RuntimeException(bindingErrorMessage);
@@ -830,7 +852,14 @@
   <xsl:template name="unmarshal-array">
     <xsl:value-of select="@java-type"/>[] <xsl:value-of select="@java-name"/> = new <xsl:value-of select="@java-type"/>[4];
       index = 0;
+    <xsl:choose>
+      <xsl:when test="@form='complex' and @type-index=''">
+      while (uctx.getUnmarshaller("<xsl:value-of select="@ns"/>", "<xsl:value-of select="@name"/>").isPresent(uctx)) {
+      </xsl:when>
+      <xsl:otherwise>
       while (uctx.isAt("<xsl:value-of select="@ns"/>", "<xsl:value-of select="@name"/>")) {
+      </xsl:otherwise>
+    </xsl:choose>
           if (index >= <xsl:value-of select="@java-name"/>.length) {
               <xsl:value-of select="@java-name"/> = (<xsl:value-of select="@java-type"/>[])org.jibx.runtime.Utility.growArray(<xsl:value-of select="@java-name"/>);
           }
@@ -840,7 +869,7 @@
           } else {
     </xsl:if>
     <xsl:value-of select="@java-name"/>[index++] = (<xsl:value-of select="@java-type"/>)<xsl:call-template name="deserialize-element-value"/>;
-    <xsl:if test="@form='complex'">
+    <xsl:if test="@form='complex' and @type-index!=''">
               uctx.parsePastCurrentEndTag("<xsl:value-of select='@ns'/>", "<xsl:value-of select='@name'/>");
     </xsl:if>
     <xsl:if test="@nillable='true'">
@@ -858,27 +887,34 @@
   <!-- Unmarshal a non-repeated element into an simple value -->
   <xsl:template name="unmarshal-value">
     <xsl:value-of select="@java-type"/><xsl:text> </xsl:text><xsl:value-of select="@java-name"/> = <xsl:choose><xsl:when test="boolean(@default)"><xsl:value-of select="@default"/></xsl:when><xsl:otherwise>null</xsl:otherwise></xsl:choose>;
-          if (uctx.isAt("<xsl:value-of select="@ns"/>", "<xsl:value-of select="@name"/>")) {
+    <xsl:choose>
+      <xsl:when test="@form='complex' and @type-index=''">
+            if (uctx.getUnmarshaller("<xsl:value-of select="@ns"/>", "<xsl:value-of select="@name"/>").isPresent(uctx)) {
+      </xsl:when>
+      <xsl:otherwise>
+            if (uctx.isAt("<xsl:value-of select="@ns"/>", "<xsl:value-of select="@name"/>")) {
+      </xsl:otherwise>
+    </xsl:choose>
     <xsl:if test="@nillable='true'">
-              if (uctx.attributeBoolean("http://www.w3.org/2001/XMLSchema-instance", "nil", false)) {
-                  uctx.skipElement();
-              } else {
+                if (uctx.attributeBoolean("http://www.w3.org/2001/XMLSchema-instance", "nil", false)) {
+                    uctx.skipElement();
+                } else {
     </xsl:if>
     <xsl:value-of select="@java-name"/> = (<xsl:value-of select="@java-type"/>)<xsl:call-template name="deserialize-element-value"/>;
-    <xsl:if test="@form='complex'">
-              uctx.parsePastCurrentEndTag("<xsl:value-of select='@ns'/>", "<xsl:value-of select='@name'/>");
+    <xsl:if test="@form='complex' and @type-index!=''">
+                uctx.parsePastCurrentEndTag("<xsl:value-of select='@ns'/>", "<xsl:value-of select='@name'/>");
     </xsl:if>
     <xsl:if test="@nillable='true'">
-              }
+                }
     </xsl:if>
     <xsl:choose>
       <xsl:when test="@optional='true'">
-          }
+            }
       </xsl:when>
       <xsl:otherwise>
-          } else {
-              throw new org.apache.axis2.AxisFault("Missing required element {<xsl:value-of select='@ns'/>}<xsl:value-of select='@name'/>");
-          }
+            } else {
+                throw new org.apache.axis2.AxisFault("Missing required element {<xsl:value-of select='@ns'/>}<xsl:value-of select='@name'/>");
+            }
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
@@ -897,6 +933,9 @@
       </xsl:when>
       <xsl:when test="@form='simple'">
         <xsl:value-of select="@deserializer"/>(uctx.parseElementText("<xsl:value-of select="@ns"/>", "<xsl:value-of select="@name"/>"))
+      </xsl:when>
+      <xsl:when test="@form='complex' and @type-index=''">
+        uctx.unmarshalElement()
       </xsl:when>
       <xsl:when test="@form='complex'">
         uctx.getUnmarshaller(_type_index<xsl:value-of select="@type-index"/>).unmarshal(<xsl:choose><xsl:when test="string-length(normalize-space(@create-type)) = 0">null</xsl:when><xsl:otherwise>new <xsl:value-of select="@create-type"/>()</xsl:otherwise></xsl:choose>, uctx)



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org