You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ds...@apache.org on 2006/10/13 02:17:49 UTC

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

Author: dsosnoski
Date: Thu Oct 12 17:17:49 2006
New Revision: 463523

URL: http://svn.apache.org/viewvc?view=rev&rev=463523
Log:
Fix JiBX unwrapped code generation use of names for parameter elements

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

Modified: webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java?view=diff&rev=463523&r1=463522&r2=463523
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java (original)
+++ webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java Thu Oct 12 17:17:49 2006
@@ -353,7 +353,6 @@
         List partNameList = new ArrayList();
         String wrappertype = "";
         if (type instanceof XmlSchemaComplexType) {
-            wrapdetail.setAttribute("empty", "false");
             XmlSchemaComplexType ctype = (XmlSchemaComplexType)type;
             if (ctype.getAttributes().getCount() != 0) {
                 throw new RuntimeException("Cannot unwrap element " +
@@ -464,12 +463,15 @@
                 codeGenConfig.getTypeMapper().addTypeMappingName(partqname, fulltype);
             }
             
-        } else if (type == null) {
+        } else if (type != null) {
+            throw new RuntimeException("Cannot unwrap element " + qname +
+                ": not a complexType definition");
+        }
+        if (wrapdetail.getFirstChild() == null) {
             wrapdetail.setAttribute("empty", "true");
             wrappertype = "";
         } else {
-            throw new RuntimeException("Cannot unwrap element " + qname +
-                ": not a complexType definition");
+            wrapdetail.setAttribute("empty", "false");
         }
 
         // this magic code comes from org.apache.axis2.wsdl.codegen.extension.SchemaUnwrapperExtension

Modified: webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java?view=diff&rev=463523&r1=463522&r2=463523
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java (original)
+++ webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java Thu Oct 12 17:17:49 2006
@@ -17,6 +17,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.OutputStream;
 import java.io.Writer;
 
@@ -44,6 +45,12 @@
      mapping definition in the binding, <code>-1</code> if not used). */
     private final int marshallerIndex;
     
+    /** Element name (only used with {@link #marshallerIndex}). */
+    private final String elementName;
+    
+    /** Element namespace URI (only used with {@link #marshallerIndex}). */
+    private final String elementNamespaceUri;
+    
     /** Data object for output. */
     private final Object dataObject;
     
@@ -60,6 +67,7 @@
         marshallerIndex = -1;
         dataObject = obj;
         bindingFactory = factory;
+        elementName = elementNamespaceUri = null;
     }
     
     /**
@@ -67,10 +75,19 @@
      * 
      * @param obj
      * @param index
+     * @param name
+     * @param uri
      * @param factory
      */
-    public JiBXDataSource(Object obj, int index, IBindingFactory factory) {
+    public JiBXDataSource(Object obj, int index, String name, String uri,
+        IBindingFactory factory) {
+        if (index < 0) {
+            throw new
+                IllegalArgumentException("index value must be non-negative");
+        }
         marshallerIndex = index;
+        elementName = name;
+        elementNamespaceUri = uri;
         dataObject = obj;
         bindingFactory = factory;
     }
@@ -82,12 +99,43 @@
      * @throws JiBXException
      */
     private void marshal(IMarshallingContext ctx) throws JiBXException {
-        if (dataObject instanceof IMarshallable) {
+        if (marshallerIndex < 0) {
             ((IMarshallable)dataObject).marshal(ctx);
         } else {
-            IMarshaller mrsh = ctx.getMarshaller(marshallerIndex,
-                bindingFactory.getMappedClasses()[marshallerIndex]);
-            mrsh.marshal(dataObject, ctx);
+            IXMLWriter wrtr = ctx.getXmlWriter();
+            int nsidx = 0;
+            boolean nsfound = true;
+            if (!"".equals(elementNamespaceUri)) {
+                nsfound = false;
+                for (nsidx = wrtr.getNamespaceCount()-1; nsidx > 1; nsidx--) {
+                    if (elementNamespaceUri.equals(wrtr.getNamespaceUri(nsidx))) {
+                        nsfound = true;
+                        break;
+                    }
+                }
+            }
+            try {
+                if (nsfound) {
+                    wrtr.startTagOpen(nsidx, elementName);
+                } else {
+                    nsidx = wrtr.getNamespaceCount();
+                    String[] uris = new String[] { elementNamespaceUri };
+                    int[] indexes = new int[] { nsidx };
+                    String[] prefixes = new String[] { "" };
+                    wrtr.pushExtensionNamespaces(uris);
+                    wrtr.startTagNamespaces(nsidx, elementName, indexes, prefixes);
+                }
+                IMarshaller mrsh = ctx.getMarshaller(marshallerIndex,
+                    bindingFactory.getMappedClasses()[marshallerIndex]);
+                mrsh.marshal(dataObject, ctx);
+                wrtr.endTag(nsidx, elementName);
+                if (!nsfound) {
+                    wrtr.popExtensionNamespaces();
+                }
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
         }
     }
 

Modified: webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl?view=diff&rev=463523&r1=463522&r2=463523
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl (original)
+++ webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl Thu Oct 12 17:17:49 2006
@@ -147,7 +147,7 @@
               </xsl:otherwise>
             </xsl:choose>
                       } else {
-                          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"/>, bindingFactory);
+                          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/@ns'/>", bindingFactory);
                           org.apache.axiom.om.OMElement child = factory.createOMElement(src, "<xsl:value-of select='out-wrapper/return-element/@name'/>", appns);
                           wrapper.addChild(child);
                       }
@@ -197,7 +197,7 @@
               </xsl:otherwise>
             </xsl:choose>
               } else {
-                  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"/>, bindingFactory);
+                  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/@ns'/>", bindingFactory);
                   org.apache.axiom.om.OMElement child = factory.createOMElement(src, "<xsl:value-of select='out-wrapper/return-element/@name'/>", appns);
                   wrapper.addChild(child);
               }
@@ -212,6 +212,7 @@
               child.setText(<xsl:value-of select="out-wrapper/return-element/@serializer"/>(result));
               </xsl:otherwise>
             </xsl:choose>
+              wrapper.addChild(child);
           </xsl:otherwise>
         </xsl:choose>
       </xsl:when>
@@ -221,7 +222,7 @@
               skel.<xsl:call-template name="call-arg-list"/>;
         <xsl:if test="count(out-wrapper)&gt;0">
               envelope = factory.getDefaultEnvelope();
-              envelope.getBody().addChild(factory.createOMElement("<xsl:value-of select='out-wrapper/@name'/>", "<xsl:value-of select='out-wrapper/@ns'/>", ""););
+              envelope.getBody().addChild(factory.createOMElement("<xsl:value-of select='out-wrapper/@name'/>", "<xsl:value-of select='out-wrapper/@ns'/>", ""));
         </xsl:if>
       </xsl:otherwise>
       
@@ -272,7 +273,7 @@
          * @param param18
          * 
          */
-        public <xsl:value-of select="$return-full-type"/><xsl:text> </xsl:text><xsl:value-of select="@method-name"/>(
+        public <xsl:choose><xsl:when test="out-wrapper/@empty='true'">void</xsl:when><xsl:otherwise><xsl:value-of select="$return-full-type"/></xsl:otherwise></xsl:choose><xsl:text> </xsl:text><xsl:value-of select="@method-name"/>(
     <xsl:for-each select="in-wrapper/parameter-element">
       <xsl:if test="position()&gt;1">, </xsl:if><xsl:value-of select="@java-type"/><xsl:if test="@array='true'">[]</xsl:if><xsl:text> </xsl:text><xsl:value-of select="@java-name"/>
     </xsl:for-each>
@@ -321,8 +322,10 @@
                     throw new org.apache.axis2.AxisFault("Missing expected result wrapper element {<xsl:value-of select='out-wrapper/@ns'/>}<xsl:value-of select='out-wrapper/@name'/>");
                 }
     </xsl:if>
+    <xsl:if test="out-wrapper/@empty='false' or count(in-wrapper/parameter-element[@form='simple']) &gt; 0">
             } catch (org.jibx.runtime.JiBXException e) {
                 throw new org.apache.axis2.AxisFault(e);
+    </xsl:if>
             } catch (org.apache.axis2.AxisFault f) {
                 org.apache.axiom.om.OMElement faultElt = f.getDetail();
                 if (faultElt != null) {
@@ -489,9 +492,8 @@
         child.setText(<xsl:value-of select="@serializer"/>(<xsl:call-template name="parameter-or-array-item"/>));
       </xsl:when>
       <xsl:when test="@form='complex'">
-        org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(<xsl:call-template name="parameter-or-array-item"/>, _type_index<xsl:value-of select="@type-index"/>, bindingFactory);
+        org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(<xsl:call-template name="parameter-or-array-item"/>, _type_index<xsl:value-of select="@type-index"/>, "<xsl:value-of select='@name'/>", "<xsl:value-of select='@ns'/>", bindingFactory);
         org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='@ns'/>", "");
-        child.declareNamespace(appns);
         child = factory.createOMElement(src, "<xsl:value-of select='@name'/>", appns);
       </xsl:when>
     </xsl:choose>
@@ -544,6 +546,7 @@
               (org.jibx.runtime.impl.UnmarshallingContext)bindingFactory.createUnmarshallingContext();
           org.jibx.runtime.IXMLReader reader = new org.jibx.runtime.impl.StAXReaderWrapper(param.getXMLStreamReaderWithoutCaching(), "SOAP-message", true);
           ctx.setDocument(reader);
+          ctx.toTag();
           return ctx;
       }
   </xsl:template>
@@ -578,10 +581,12 @@
           } 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'">
+              uctx.parsePastCurrentEndTag("<xsl:value-of select='@ns'/>", "<xsl:value-of select='@name'/>");
+    </xsl:if>
     <xsl:if test="@nillable='true'">
           }
     </xsl:if>
-          uctx.next();
       }
       <xsl:value-of select="@java-name"/> = (<xsl:value-of select="@java-type"/>[])org.jibx.runtime.Utility.resizeArray(index, <xsl:value-of select="@java-name"/>);
     <xsl:if test="@optional!='true'">
@@ -601,6 +606,9 @@
               } 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>
     <xsl:if test="@nillable='true'">
               }
     </xsl:if>



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