tomj        2002/09/24 09:03:38

  Modified:    java/src/org/apache/axis/encoding/ser ArraySerializer.java
               java/src/org/apache/axis/wsdl/gen Parser.java
               java/src/org/apache/axis/providers/java RPCProvider.java
               java/src/org/apache/axis/wsdl/symbolTable SymbolTable.java
  Added:       java/test/wsdl/wrapped_holders build.xml thing.wsdl
                        ThingImpl.java Wrapped_HoldersTestCase.java
  Log:
  Fix bug 12868 - no holders generated for Array types
  
  SymbolTable
  - Scan parameter names and prevent duplicates
  - When dealing with Collection types, make the XML name
    the type in the collection, not the internal bracket
    notation (i.e. foo[unbounded])
  
  RPCPRovider
  - When creating output parameters, set the ParameterDescription
  
  Parser
  - optimize imports
  - Call generate() on Collection types to get holders if needed
  
  ArraySerializer
  - Serialize attributes for each item if we are doing
    literal style: <type>data</type>
    instead of:    <item></item>
  
  Add a new WSDL test case: wrapped_holders.
  
  Revision  Changes    Path
  1.35      +4 -2      
xml-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java
  
  Index: ArraySerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- ArraySerializer.java      18 Sep 2002 16:10:35 -0000      1.34
  +++ ArraySerializer.java      24 Sep 2002 16:03:37 -0000      1.35
  @@ -284,7 +284,9 @@
           // we got in the arguments.  For normal array case, we write an element with
           // that QName, and then serialize each item as <item>
           QName elementName = name;
  +        Attributes serializeAttr = attributes;
           if (!maxOccursUsage) {
  +            serializeAttr = null;  // since we are putting them here
               context.startElement(name, attributes);
               elementName = Constants.QNAME_LITERAL_ITEM;
           }
  @@ -296,7 +298,7 @@
                       Object aValue = Array.get(value, index);
   
                       // Serialize the element.
  -                    context.serialize(elementName, null, aValue,
  +                    context.serialize(elementName, serializeAttr, aValue,
                                         componentQName, // prefered type QName
                                         true,   // Send null values
                                         Boolean.FALSE); // Don't send xsi:type if it 
matches preferred QName
  @@ -306,7 +308,7 @@
                       Object aValue = (Object)iterator.next();
   
                       // Serialize the element.
  -                    context.serialize(elementName, null, aValue,
  +                    context.serialize(elementName, serializeAttr, aValue,
                                         componentQName, // prefered type QName
                                         true,   // Send null values
                                         Boolean.FALSE); // Don't send xsi:type if it 
matches preferred QName
  
  
  
  1.1                  xml-axis/java/test/wsdl/wrapped_holders/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE project [
          <!ENTITY properties SYSTEM "file:../../../xmls/properties.xml">
          <!ENTITY paths  SYSTEM "file:../../../xmls/path_refs.xml">
          <!ENTITY taskdefs SYSTEM "file:../../../xmls/taskdefs.xml">
          <!ENTITY taskdefs_post_compile SYSTEM 
"file:../../../xmls/taskdefs_post_compile.xml">
          <!ENTITY targets SYSTEM "file:../../../xmls/targets.xml">
  ]>
  
  <!-- ===================================================================
  <description>
     Test/Sample Component file for Axis
  
  Notes:
     This is a build file for use with the Jakarta Ant build tool.
  
  Prerequisites:
  
     jakarta-ant from http://jakarta.apache.org
  
  Build Instructions:
     To compile
          ant compile
     To execute
          ant run
  
  Author:
    Matt Seibert [EMAIL PROTECTED]
  
  Copyright:
    Copyright (c) 2002-2003 Apache Software Foundation.
  </description>
  ==================================================================== -->
  
  <project default="compile">
  
  <property name="axis.home" location="../../.." />
  <property name="componentName" value="test/wsdl/wrapped_holders" />
          &properties;
          &paths;
          &taskdefs;
          &taskdefs_post_compile;
          &targets;
  
  <target name="clean">
      <echo message="Removing ${build.dir}/classes/${componentName} and 
${build.dir}/work/${componentName}" />
      <delete dir="${build.dir}/classes/${componentName}"/>
      <delete dir="${build.dir}/work/${componentName}"/>
  </target>
  
  <target name="copy" depends="setenv"/>
  
  <target name="compile" depends="copy">
    <echo message="Compiling test.wsdl.wrapped_holders"/>
      <!-- Wrapped Sample Test -->
      <wsdl2java url="${axis.home}/test/wsdl/wrapped_holders/thing.wsdl"
                 output="${axis.home}/build/work"
                 serverSide="yes"
                 skeletonDeploy="no"
                 testcase="yes">
          <mapping namespace="urn:Thing" package="test.wsdl.wrapped_holders"/>
      </wsdl2java>
  
      <copy todir="${build.dir}/work/test/wsdl/wrapped_holders" overwrite="yes">
        <fileset dir="${axis.home}/test/wsdl/wrapped_holders">
          <include name="*TestCase.java"/>
          <include name="*Impl.java"/>
        </fileset>
      </copy>
  
      <javac srcdir="${build.dir}/work" destdir="${build.dest}" fork="${javac.fork}"
             debug="${debug}">
        <classpath refid="classpath" />
        <include name="test/wsdl/wrapped_holders/*.java" />
      </javac>
  
  </target>
  
  <target name="run" >
    <antcall target="execute-Component" />
  </target>
  
  </project>
  
  
  
  1.1                  xml-axis/java/test/wsdl/wrapped_holders/thing.wsdl
  
  Index: thing.wsdl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"; 
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"; 
  xmlns:s="http://www.w3.org/2001/XMLSchema"; xmlns:s0="urn:Thing" 
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; 
  xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"; 
  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"; 
  targetNamespace="urn:Thing" xmlns="http://schemas.xmlsoap.org/wsdl/";>
  <!--
  
  This test checks out the emitting of holders for container elements
  (arrays) that are inside elements.
  
  -->
  
  
    <types>
        <s:schema elementFormDefault="qualified" targetNamespace="urn:Thing">
            <s:element name="aThing" type="s0:aThing" final="restriction"/>
            <s:simpleType name="aThing">
                <s:restriction base="s:string">
                    <s:maxLength value="255"/>
                </s:restriction>
            </s:simpleType>
            <s:element name="otherData" type="s0:otherData" final="restriction"/>
            <s:simpleType name="otherData">
                <s:restriction base="s:string">
                    <s:maxLength value="1024"/>
                </s:restriction>
            </s:simpleType>
            <s:element name="find_aThing" type="s0:find_aThing" final="restriction"/>
            <s:complexType name="find_aThing" final="restriction">
                <s:sequence>
                    <s:element ref="s0:aThing" maxOccurs="1"/>
                </s:sequence>
            </s:complexType>
            <s:element name="AThingResponse" type="s0:AThingResponse" 
final="restriction"/>
            <s:complexType name="AThingResponse" final="restriction">
                <s:sequence>
                    <s:element ref="s0:aThing" minOccurs="0" maxOccurs="unbounded"/>
                    <s:element ref="s0:otherData" minOccurs="0" maxOccurs="unbounded"/>
                </s:sequence>
            </s:complexType>
        </s:schema>
    </types>
    <message name="ThingIn">
      <part name="parameters" element="s0:find_aThing" />
    </message>
    <message name="ThingOut">
      <part name="parameters" element="s0:AThingResponse" />
    </message>
    <portType name="Thing">
      <operation name="find_aThing">
        <input message="s0:ThingIn" />
        <output message="s0:ThingOut" />
      </operation>
    </portType>
    <binding name="Thing" type="s0:Thing">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http"; style="document" 
/>
      <operation name="find_aThing">
        <soap:operation soapAction="http://tempuri.org/find_aThing"; style="document" />
        <input>
          <soap:body use="literal" />
        </input>
        <output>
          <soap:body use="literal" />
        </output>
      </operation>
    </binding>
    <service name="wrapped_holders">
      <port name="Thing" binding="s0:Thing">
        <soap:address location="http://localhost:8080/axis/services/Thing"; />
      </port>
    </service>
  </definitions>
  
  
  
  1.1                  xml-axis/java/test/wsdl/wrapped_holders/ThingImpl.java
  
  Index: ThingImpl.java
  ===================================================================
  /**
   * ThingImpl.java
   *
   * This file was auto-generated from WSDL
   * by the Apache Axis WSDL2Java emitter.
   */
  
  package test.wsdl.wrapped_holders;
  
  import java.rmi.RemoteException;
  
  /**
   * This test verify's that arrays in a wrapped doc/lit service get holders
   * generated for them, and that they work.
   * 
   * @author Tom Jordahl
   */ 
  public class ThingImpl implements test.wsdl.wrapped_holders.Thing{
      public void find_AThing(test.wsdl.wrapped_holders.AThing aThing, 
                              test.wsdl.wrapped_holders.holders.AThingArrayHolder 
aThingUnbounded, 
                              test.wsdl.wrapped_holders.holders.OtherDataArrayHolder 
otherDataUnbounded) 
              throws java.rmi.RemoteException {
          // Verify we get a string in aThing input argument
          String input = aThing.getValue();
          if (input == null || !input.equals("This is a test")) {
              String error = "Input argument did not match expected string, got: ";
              error += input != null ? "'" + input + "'" : "NULL";
              error += " Expected: 'This is a test'";
              throw new java.rmi.RemoteException(error);
          }
          
          // now send something back
          test.wsdl.wrapped_holders.AThing[] things = new 
test.wsdl.wrapped_holders.AThing[2];
          things[0] = new AThing("Thing one");
          things[1] = new AThing("Thing two");
          aThingUnbounded.value = things;
          test.wsdl.wrapped_holders.OtherData[] others = new 
test.wsdl.wrapped_holders.OtherData[2];
          others[0] = new OtherData("Other 1");
          others[1] = new OtherData("Other 2");
          otherDataUnbounded.value = others;
      }
  
  }
  
  
  
  1.1                  
xml-axis/java/test/wsdl/wrapped_holders/Wrapped_HoldersTestCase.java
  
  Index: Wrapped_HoldersTestCase.java
  ===================================================================
  /**
   * Wrapped_HoldersTestCase.java
   *
   * This file was auto-generated from WSDL
   * by the Apache Axis WSDL2Java emitter.
   */
  
  package test.wsdl.wrapped_holders;
  
  /**
   * This test verify's that arrays in a wrapped doc/lit service get holders
   * generated for them, and that they work.
   * 
   * @author Tom Jordahl
   */ 
  public class Wrapped_HoldersTestCase extends junit.framework.TestCase {
      public Wrapped_HoldersTestCase(java.lang.String name) {
          super(name);
      }
      public void test1ThingFind_AThing() throws Exception {
          test.wsdl.wrapped_holders.Thing binding;
          try {
              binding = new 
test.wsdl.wrapped_holders.Wrapped_HoldersLocator().getThing();
          }
          catch (javax.xml.rpc.ServiceException jre) {
              if(jre.getLinkedCause()!=null)
                  jre.getLinkedCause().printStackTrace();
              throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException 
caught: " + jre);
          }
          assertTrue("binding is null", binding != null);
  
          // expected results
          test.wsdl.wrapped_holders.AThing[] things = new 
test.wsdl.wrapped_holders.AThing[2];
          things[0] = new AThing("Thing one");
          things[1] = new AThing("Thing two");
          test.wsdl.wrapped_holders.OtherData[] others = new 
test.wsdl.wrapped_holders.OtherData[2];
          others[0] = new OtherData("Other 1");
          others[1] = new OtherData("Other 2");
          
          // input arguments
          AThing AthingInput = new AThing("This is a test");
          test.wsdl.wrapped_holders.holders.AThingArrayHolder AThingsOut = new 
test.wsdl.wrapped_holders.holders.AThingArrayHolder();
          test.wsdl.wrapped_holders.holders.OtherDataArrayHolder OtherDataOut = new 
test.wsdl.wrapped_holders.holders.OtherDataArrayHolder();
  
          // call the operation
          binding.find_AThing(AthingInput, AThingsOut, OtherDataOut);
          
          // verify results
          assertEquals("Output argument (Things) does not match expected", things[0], 
AThingsOut.value[0]);
          assertEquals("Output argument (Things) does not match expected", things[1], 
AThingsOut.value[1]);
          assertEquals("Output argument (OtherData) does not match expected", 
others[0], OtherDataOut.value[0]);
          assertEquals("Output argument (OtherData) does not match expected", 
others[1], OtherDataOut.value[1]);
      }
  
  }
  
  
  
  1.11      +19 -19    xml-axis/java/src/org/apache/axis/wsdl/gen/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/gen/Parser.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Parser.java       19 Sep 2002 20:45:54 -0000      1.10
  +++ Parser.java       24 Sep 2002 16:03:38 -0000      1.11
  @@ -54,29 +54,25 @@
    */
   package org.apache.axis.wsdl.gen;
   
  -import java.io.IOException;
  -
  -import java.util.Iterator;
  -import java.util.Vector;
  -
  -import javax.wsdl.Binding;
  -import javax.wsdl.Definition;
  -import javax.wsdl.WSDLException;
  -
  -import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.Messages;
  -
   import org.apache.axis.wsdl.symbolTable.BindingEntry;
  -import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
  +import org.apache.axis.wsdl.symbolTable.CollectionElement;
   import org.apache.axis.wsdl.symbolTable.MessageEntry;
  +import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
   import org.apache.axis.wsdl.symbolTable.ServiceEntry;
  -import org.apache.axis.wsdl.symbolTable.SymbolTable;
   import org.apache.axis.wsdl.symbolTable.SymTabEntry;
  +import org.apache.axis.wsdl.symbolTable.SymbolTable;
   import org.apache.axis.wsdl.symbolTable.Type;
   import org.apache.axis.wsdl.symbolTable.TypeEntry;
  -
   import org.w3c.dom.Document;
   
  +import javax.wsdl.Binding;
  +import javax.wsdl.Definition;
  +import javax.wsdl.WSDLException;
  +import java.io.IOException;
  +import java.util.Iterator;
  +import java.util.Vector;
  +
   /**
    * This is a class with no documentation.
    *
  @@ -345,13 +341,17 @@
               //  - we found its definition (getNode())
               //  - it is referenced 
               //  - it is not a base type
  -            //  - it is a Type (not an Element)
  +            //  - it is a Type (not an Element) or a CollectionElement
               // (Note that types that are arrays are passed to getGenerator
               //  because they may require a Holder)
  -            if (type.getNode() != null && 
  -                type instanceof Type &&
  -                type.isReferenced() && 
  -                type.getBaseType() == null) {
  +
  +            // A CollectionElement is an array that might need a holder
  +            boolean isType = (type instanceof Type ||
  +                    type instanceof CollectionElement);
  +            if (type.getNode() != null &&
  +                    type.isReferenced() &&
  +                    isType &&
  +                    type.getBaseType() == null) {
                   Generator gen = genFactory.getGenerator(type, symbolTable);
                   gen.generate();
               }
  
  
  
  1.96      +4 -2      
xml-axis/java/src/org/apache/axis/providers/java/RPCProvider.java
  
  Index: RPCProvider.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/providers/java/RPCProvider.java,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- RPCProvider.java  18 Sep 2002 16:10:34 -0000      1.95
  +++ RPCProvider.java  24 Sep 2002 16:03:38 -0000      1.96
  @@ -274,8 +274,10 @@
                       // Store an RPCParam in the outs collection so we
                       // have an easy and consistent way to write these
                       // back to the client below
  -                    outs.add(new RPCParam(param.getQName(),
  -                                          argValues[numArgs + i]));
  +                    RPCParam p = new RPCParam(param.getQName(),
  +                                              argValues[numArgs + i]);
  +                    p.setParamDesc(param);
  +                    outs.add(p);
                   } else {
                       throw new AxisFault(Messages.getMessage("badOutParameter00",
                                                                "" + param.getQName(),
  
  
  
  1.39      +30 -1     
xml-axis/java/src/org/apache/axis/wsdl/symbolTable/SymbolTable.java
  
  Index: SymbolTable.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/symbolTable/SymbolTable.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- SymbolTable.java  19 Sep 2002 20:45:54 -0000      1.38
  +++ SymbolTable.java  24 Sep 2002 16:03:38 -0000      1.39
  @@ -1110,6 +1110,20 @@
           }
           parameters.faults = operation.getFaults();
   
  +        // before we add return the paramters, 
  +        // make sure we dont have a duplicate name
  +        Vector used = new Vector(parameters.list.size());
  +        Iterator i = parameters.list.iterator();
  +        while (i.hasNext()) {
  +            Parameter parameter = (Parameter) i.next();
  +            int count = 2;
  +            while (used.contains(parameter.getName())) {
  +                // duplicate, add a suffix and try again
  +                parameter.setName(parameter.getName() + Integer.toString(count++));
  +            }
  +            used.add(parameter.getName());
  +        }
  +                
           return parameters;
       } // parameters
   
  @@ -1136,11 +1150,17 @@
                                 boolean trimInput) {
           Parameter p = (Parameter)inputs.get(index);
           // If this is an element, we want the XML to reflect the element name
  -        // not the part name.
  +        // not the part name.  Same check is made in addOutParam below.
           if (p.getType() instanceof DefinedElement) {
               DefinedElement de = (DefinedElement)p.getType();
               p.setQName(de.getQName());
           }
  +        // If this is a collection we want the XML to reflect the type in
  +        // the collection, not foo[unbounded].  
  +        // Same check is made in addOutParam below.
  +        if (p.getType() instanceof CollectionTE) {
  +            p.setQName(p.getType().getRefType().getQName());
  +        }
   
           // Should we remove the given parameter type/name entries from the Vector?
           if (trimInput) {
  @@ -1205,10 +1225,18 @@
                               boolean trim) {
           Parameter p = (Parameter)outputs.get(outdex);
   
  +        // If this is an element, we want the XML to reflect the element name
  +        // not the part name.  Same check is made in addInishParam above.
           if (p.getType() instanceof DefinedElement) {
               DefinedElement de = (DefinedElement)p.getType();
               p.setQName(de.getQName());
           }
  +        // If this is a collection we want the XML to reflect the type in
  +        // the collection, not foo[unbounded].  
  +        // Same check is made in addInishParam above.
  +        if (p.getType() instanceof CollectionTE) {
  +            p.setQName(p.getType().getRefType().getQName());
  +        }
   
           if (trim) {
               outputs.remove(outdex);
  @@ -1216,6 +1244,7 @@
   
           p.setMode(Parameter.OUT);
           ++parameters.outputs;
  +        
           parameters.list.add(p);
       } // addOutParm
   
  
  
  


Reply via email to