axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject cvs commit: xml-axis/java/test/wsdl Wsdl2javaTestSuite.xml
Date Sat, 08 Dec 2001 04:23:39 GMT
scheu       01/12/07 20:23:38

  Modified:    java     build.xml
               java/src/org/apache/axis/wsdl JavaWriterFactory.java
                        SchemaUtils.java SymbolTable.java
               java/test/clash AirportWeather.xml
               java/test/wsdl Wsdl2javaTestSuite.xml
  Added:       java/test/refattr RefTestServiceTestCase.java refattr.wsdl
  Log:
  Added more adequate support for ref= attribute.
  Several fixes to the resolve conflicting java names code.
  Added refattr.wsdl testcase to test ref stuff and mangling.
  
  Revision  Changes    Path
  1.92      +1 -0      xml-axis/java/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/build.xml,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- build.xml	2001/12/05 23:46:34	1.91
  +++ build.xml	2001/12/08 04:23:38	1.92
  @@ -268,6 +268,7 @@
         <exclude name="test/faults/wsdl/*.java" />
         <exclude name="test/multiref/*.java" />
         <exclude name="test/arrays/*.java" />
  +      <exclude name="test/refattr/*.java" />
         <exclude name="test/*/impl/*.java" />
         <exclude name="test/wsdl/Wsdl2javaTestSuite.java" unless="servlet.present"/>
         <exclude name="test/md5attach/*.java" unless="attachments.present"/>
  
  
  
  1.16      +107 -19   xml-axis/java/src/org/apache/axis/wsdl/JavaWriterFactory.java
  
  Index: JavaWriterFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/JavaWriterFactory.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- JavaWriterFactory.java	2001/12/07 18:32:43	1.15
  +++ JavaWriterFactory.java	2001/12/08 04:23:38	1.16
  @@ -65,6 +65,7 @@
   import javax.wsdl.Message;
   import javax.wsdl.Operation;
   import javax.wsdl.PortType;
  +import javax.wsdl.QName;
   import javax.wsdl.Service;
   
   /**
  @@ -171,33 +172,120 @@
       private void resolveNameClashes(SymbolTable symbolTable) {
           Iterator it = symbolTable.getHashMap().values().iterator();
           while (it.hasNext()) {
  -            Vector v = (Vector) it.next();
  +            Vector v = new Vector((Vector) it.next());  // New vector we can temporarily
add to it
               if (v.size() > 1) {
  -                for (int i = 0; i < v.size(); ++i) {
  -                    SymTabEntry entry = (SymTabEntry) v.elementAt(i);
  -                    if (entry instanceof ElementType) {
  -                        entry.setName(entry.getName() + "_ElemType");
  -                    }
  -                    else if (entry instanceof Type) {
  -                        entry.setName(entry.getName() + "_Type");
  +                boolean resolve = true;
  +                // Common Special Case:
  +                // If a Type and ElementType have the same QName, and the ElementType
  +                // uses type= to reference the Type, then they are the same class so 
  +                // don't bother mangling.
  +                if (v.size() == 2 &&
  +                    ((v.elementAt(0) instanceof ElementType &&
  +                      v.elementAt(1) instanceof Type) ||
  +                     (v.elementAt(1) instanceof ElementType &&
  +                      v.elementAt(0) instanceof Type))) {
  +                    ElementType e = null;
  +                    if (v.elementAt(0) instanceof ElementType) {
  +                        e = (ElementType)v.elementAt(0);
  +                    } else {
  +                        e = (ElementType)v.elementAt(1);
                       }
  -                    else if (entry instanceof PortTypeEntry) {
  -                        entry.setName(entry.getName() + "_Port");
  +                    QName eType = Utils.getNodeTypeRefQName(e.getNode(), "type");
  +                    if (eType != null && eType.equals(e.getQName()))
  +                        resolve = false;
  +                }
  +                // Other Special Case:
  +                // If the names are already different, no mangling is needed.
  +                if (resolve) {
  +                    resolve = false;  // Assume false
  +                    String name = null;
  +                    for (int i = 0; i < v.size() && !resolve; ++i) {
  +                        SymTabEntry entry = (SymTabEntry) v.elementAt(i);
  +                         if (entry instanceof MessageEntry ||
  +                             entry instanceof BindingEntry) {
  +                             ; // Don't process these
  +                         } else if (name== null) {
  +                             name = entry.getName();
  +                         } else if (name.equals(entry.getName())) {
  +                             resolve = true;  // Need to do resolution
  +                         } 
  +
                       }
  -                    else if (entry instanceof ServiceEntry) {
  -                        entry.setName(entry.getName() + "_Service");
  +                }
  +
  +                    
  +                // Full Mangle if resolution is necessary.
  +                if (resolve) {
  +                    boolean firstType = true;
  +                    for (int i = 0; i < v.size(); ++i) {
  +                        SymTabEntry entry = (SymTabEntry) v.elementAt(i);
  +                        if (entry instanceof ElementType) {
  +                            entry.setName(mangleName(entry.getName() , "_ElemType"));
  +                        }
  +                        else if (entry instanceof Type) {
  +                            // Search all other types for java names that match this one.
  +                            // The sameJavaClass method returns true if the java names
are
  +                            // the same (ignores [] ).
  +                            if (firstType) {
  +                                firstType = false;
  +                                Vector types = symbolTable.getTypes();
  +                                for (int j = 0; j < types.size(); ++j) {
  +                                    Type type = (Type) types.elementAt(j);
  +                                    if (type != entry && 
  +                                        !(type instanceof ElementType) &&
  +                                        type.getBaseType() == null &&
  +                                        sameJavaClass(((Type)entry).getName(), type.getName()))
{
  +                                        v.add(type);  
  +                                    }
  +                                }
  +                            }
  +                            entry.setName(mangleName(entry.getName() , "_Type"));
  +                        }
  +                        else if (entry instanceof PortTypeEntry) {
  +                            entry.setName(mangleName(entry.getName() , "_Port"));
  +                        }
  +                        else if (entry instanceof ServiceEntry) {
  +                            entry.setName(mangleName(entry.getName() , "_Service"));
  +                        }
  +                        // else if (entry instanceof MessageEntry) {
  +                        //     we don't care about messages
  +                        // }
  +                        // else if (entry instanceof BindingEntry) {
  +                        //     since files generated from bindings all append strings to
the name,
  +                        //     we don't care about bindings
  +                        // }
                       }
  -                    // else if (entry instanceof MessageEntry) {
  -                    //     we don't care about messages
  -                    // }
  -                    // else if (entry instanceof BindingEntry) {
  -                    //     since files generated from bindings all append strings to the
name,
  -                    //     we don't care about bindings
  -                    // }
                   }
               }
           }
       } // resolveNameClashes
  +
  +    /**
  +     * Change the indicated type name into a mangled form using the mangle string.
  +     */
  +    private String mangleName(String name, String mangle) {
  +        int index = name.indexOf("[");
  +        if (index >= 0) {
  +            String pre = name.substring(0, index);
  +            String post = name.substring(index);
  +            return pre + mangle + post;
  +        }
  +        else
  +            return name + mangle;
  +    }
  +
  +    /**
  +     * Returns true if same java class, ignore []                                 
  +     */
  +    private boolean sameJavaClass(String one, String two) {     
  +        int index1 = one.indexOf("[");
  +        int index2 = two.indexOf("[");
  +        if (index1 > 0)
  +            one = one.substring(0, index1);
  +        if (index2 > 0)
  +            two = two.substring(0, index2);
  +        return one.equals(two);
  +    }
   
       /**
        * If a binding's type is not TYPE_SOAP, then we don't use that binding's portType.
  
  
  
  1.6       +5 -1      xml-axis/java/src/org/apache/axis/wsdl/SchemaUtils.java
  
  Index: SchemaUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/SchemaUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SchemaUtils.java	2001/12/07 20:13:08	1.5
  +++ SchemaUtils.java	2001/12/08 04:23:38	1.6
  @@ -176,11 +176,15 @@
                           Node elementNode = elements.item(i);
                           QName nodeName = Utils.getNodeNameQName(elementNode);
                           QName nodeType = Utils.getNodeTypeRefQName(elementNode);
  +                        boolean typeAttr = false;
  +                        if (Utils.getNodeTypeRefQName(elementNode, "type") != null)
  +                            typeAttr = true;
                           if (nodeType == null) { // The element may use an anonymous type
                               nodeType = nodeName;
  +                            typeAttr = true;
                           }
   
  -                        Type Type = (Type) symbolTable.getTypeEntry(nodeType);
  +                        Type Type = (Type) symbolTable.getTypeEntry(nodeType, !typeAttr);
                           if (Type != null) {
                               v.add(Type);
                               v.add(nodeName.getLocalPart());
  
  
  
  1.21      +42 -7     xml-axis/java/src/org/apache/axis/wsdl/SymbolTable.java
  
  Index: SymbolTable.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/SymbolTable.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- SymbolTable.java	2001/12/07 20:13:08	1.20
  +++ SymbolTable.java	2001/12/08 04:23:38	1.21
  @@ -345,13 +345,21 @@
               // ultimate ref'd type
               QName refQName = Utils.getNodeTypeRefQName(node);
               if (refQName != null) {
  +                // Discover whether type is from a type= or ref=/element=
  +                boolean typeAttr = false;
  +                if (Utils.getNodeTypeRefQName(node, "type") != null)
  +                    typeAttr = true;
  +
                   Type refType = null;
                   while (refQName != null) {
  -                    refType = getTypeEntry(refQName);
  +                    refType = getTypeEntry(refQName, !typeAttr);
                       refQName = null;
                       if (refType != null &&
                           refType.getNode() != null) {
                           refQName = Utils.getNodeTypeRefQName(refType.getNode());
  +                        typeAttr = false;
  +                        if (Utils.getNodeTypeRefQName(node, "type") != null)
  +                            typeAttr = true;
                           // A 'collection' type has a node that refers to itself.
                           // so we need to break out of the loop to avoid an infinite loop.
                           if (refQName != null && refQName.equals(refType.getQName()))
  @@ -359,7 +367,7 @@
                       }                         
                   }
                   // Create a type from the referenced type
  -                if (!belowSchemaLevel) {
  +                if (!belowSchemaLevel && refType != null) {
                       symbolTablePut(new ElementType(qName, refType, node));
                   }
   
  @@ -404,10 +412,19 @@
           // Get the QName of the node's type attribute value
           QName qName = Utils.getNodeTypeRefQName(node);
           if (qName != null) {
  +
  +            // Discover whether type is from a type= or ref=/element=
  +            boolean typeAttr = false;
  +            if (Utils.getNodeTypeRefQName(node, "type") != null)
  +                typeAttr = true;
  +
  +            // Get Type or ElementType depending on whether type attr was used.
  +            Type type = getTypeEntry(qName, !typeAttr);
               String javaName = getJavaName(qName);
   
  -            Type type = getTypeEntry(qName);
  -            if (type == null) {
  +            // A symbol table entry is only created if type= and the type is not
  +            // found
  +            if (type == null && typeAttr) {
                   // Type not defined, add a base java type or a refdType
                   if (debug) {
                       System.out.println("Create Type From Ref:" + qName);
  @@ -417,7 +434,7 @@
                       symbolTablePut(new BaseJavaType(qName));
                   else if (javaName.indexOf("[") > 0)
                       symbolTablePut(new CollectionType(qName, javaName, node));
  -                else
  +                else 
                       symbolTablePut(new RefdType(qName, javaName));
               } else {
                   // Type exists, update shouldEmit flag if necessary
  @@ -881,7 +898,12 @@
               if (entry instanceof ElementType) {
                   QName referentName = Utils.getNodeTypeRefQName(entry.getNode());
                   if (referentName != null) {
  -                    Type referent = getTypeEntry(referentName);
  +                    // Discover whether type is from a type= or ref=/element=
  +                    boolean typeAttr = false;
  +                    if (Utils.getNodeTypeRefQName(entry.getNode(), "type") != null)
  +                        typeAttr = true;
  +
  +                    Type referent = getTypeEntry(referentName, !typeAttr);
                       if (referent != null) {
                           setTypeReferences(referent, doc);
                       }
  @@ -1065,7 +1087,7 @@
       } // setServiceReferences
   
       /**
  -     * Put the given SymTabEntry into the symbol table, if appropriate.  If 
  +     * Put the given SymTabEntry into the symbol table, if appropriate.  
        */
       private void symbolTablePut(SymTabEntry entry) throws IOException {
           QName name = entry.getQName();
  @@ -1146,6 +1168,19 @@
               return null;
           }
       } // get
  +
  +
  +    /**
  +     * Get the type entry for the given qname.
  +     * @param qname
  +     * @param wantElementType boolean that indicates type or element (for type= or ref=)
  +     */
  +    public Type getTypeEntry(QName qname, boolean wantElementType) {
  +        if (wantElementType) {
  +            return getElementTypeEntry(qname);
  +        } else
  +            return getTypeEntry(qname);
  +    } // getTypeEntry
   
       /**
        * Get the non-ElementType TypeEntry with the given QName.  If it doesn't exist, return
null.
  
  
  
  1.5       +4 -1      xml-axis/java/test/clash/AirportWeather.xml
  
  Index: AirportWeather.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/clash/AirportWeather.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AirportWeather.xml	2001/12/06 21:24:14	1.4
  +++ AirportWeather.xml	2001/12/08 04:23:38	1.5
  @@ -30,7 +30,10 @@
         </xsd:all>
       </xsd:complexType>
   
  -    <xsd:element name="SameForTypeAndElement" ref="xsd1:SameForTypeAndElement"/>
  +    <!-- This is clearly bad wsdl since the ref= is refering to itself!  -->
  +    <!-- <xsd:element name="SameForTypeAndElement" ref="xsd1:SameForTypeAndElement"/>
-->
  +    <!-- Changed to use type= -->
  +    <xsd:element name="SameForTypeAndElement" type="xsd1:SameForTypeAndElement"/>
   
     </xsd:schema>
   </types>
  
  
  
  1.1                  xml-axis/java/test/refattr/RefTestServiceTestCase.java
  
  Index: RefTestServiceTestCase.java
  ===================================================================
  /**
   * RefTestServiceTestCase.java
   *
   * This file was auto-generated from WSDL
   * by the Apache Axis Wsdl2java emitter.
   */
  
  package test.refattr;
  
  public class RefTestServiceTestCase extends junit.framework.TestCase {
      public RefTestServiceTestCase(String name) {
          super(name);
      }
  
      public void testRefTest() {
          test.refattr.RefTest binding = new RefTestService().getRefTest();
          
          // The following declarations are used to verify that unmangled classes
          // are generated by Wsdl2Java (not a mangled class like Phone_Type).
          Info info = new Info();
          Phone phone = new Phone();
          Enum  enum  = Enum.fromValue("one");
          info.setEnum(enum);
          Forward forward  = new Forward();
          NoMangle noMangle  = new NoMangle();
          
          // The following code ensures that mangling occurred for the Mangle class
          Mangle_Type mangle_type = new Mangle_Type();
          Mangle_ElemType mangle_elem_type = new Mangle_ElemType();
          try {
              Class cls = Class.forName("test.refattr.Mangle");
              assertTrue("Found unmangled class test.refattr.Mangle", false);
          } catch (Exception e) {
              // Okay expect to get an exception
          }
  
          assertTrue("binding is null", binding != null);
          try {
              binding.test(info);
          } catch (java.rmi.RemoteException re) {
              throw new junit.framework.AssertionFailedError("Remote Exception caught: " +
re );
          }
      }
  }
  
  
  
  
  1.1                  xml-axis/java/test/refattr/refattr.wsdl
  
  Index: refattr.wsdl
  ===================================================================
  <?xml version="1.0" ?>
  
  <definitions 
      name="ref types test"
      targetNamespace="ref.types.test"
      xmlns:tns="ref.types.test"
      xmlns:typens="ref.types"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns="http://schemas.xmlsoap.org/wsdl/">
  
    <!-- type defs -->
    <types>
      <xsd:schema 
          targetNamespace="ref.types"
          xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  
        <xsd:simpleType name="enum">
          <xsd:restriction base="xsd:string">
            <xsd:enumeration value="one"/>                      
            <xsd:enumeration value="two"/>                    
            <xsd:enumeration value="three"/>                    
          </xsd:restriction>
        </xsd:simpleType>
  
        <xsd:complexType name="phone">
          <xsd:all>
            <xsd:element name="areaCode" type="xsd:int"/>
            <xsd:element name="exchange" type="xsd:string"/>
            <xsd:element name="number" type="xsd:string"/>
          </xsd:all>
        </xsd:complexType>
  
        <xsd:complexType name="example">
          <xsd:all>
            <xsd:element name="address" type="soapenc:string"/>
          </xsd:all>
        </xsd:complexType>
  
        <!-- element has the same name as the type.  This is allowed by xlm schema -->
        <!-- note that the Phone element is a collection of Phone types -->
        <!-- no mangling should occur since the same underlying java type is used -->
        <xsd:element name="phone" type="typens:phone" maxOccurs="unbounded"/>
  
        <!-- enum element which is the same as the enum type -->
        <!-- no mangling should occur since the same java type is used -->
        <xsd:element name="enum" type="typens:enum"/>
  
        <!-- The following are illegal.  Should not generate anything. But should not cause
abend -->
        <xsd:element name="self"  ref="typens:self" />
        <xsd:element name="foo"   ref="typens:undefined_element" />
  
        <!-- This is a 'forward use' of a type.  Not sure if this is legal, but we currently
accept it -->
        <xsd:element name="forward"  type="typens:forward" />
        <xsd:complexType name="forward">
          <xsd:all>
            <xsd:element name="address" type="soapenc:string"/>
          </xsd:all>
        </xsd:complexType>
  
        <!-- The following have same qname but different java types (NoMangle and Example).
-->
        <!--  No mangling should occur -->
        <xsd:complexType name="noMangle">
          <xsd:all>
            <xsd:element name="address" type="soapenc:string"/>
          </xsd:all>
        </xsd:complexType>
        <xsd:element name="noMangle" type="typens:example" />
  
        <!-- The following two have same qname and same java names (for different java
types). -->
        <!--  angling should occur -->
        <!-- Note the use of the 'mangle collection' in info..which should be properly
mangled -->
        <xsd:complexType name="mangle">
          <xsd:all>
            <xsd:element name="one" type="soapenc:string"/>
          </xsd:all>
        </xsd:complexType>
        <xsd:element name="mangle" >
          <xsd:complexType>
            <xsd:all>
              <xsd:element name="two" type="soapenc:string"/>
            </xsd:all>
          </xsd:complexType>
        </xsd:element >
  
        <xsd:complexType name="info">
          <xsd:all> 
            <!-- This is a reference to phone.  It should be a collection since the
                phone element has the unbounded attribute -->
            <xsd:element ref="typens:phone"/>
            <xsd:element ref="typens:enum"/>
            <xsd:element name="forward" type="typens:forward"/>
            <xsd:element ref="typens:noMangle"/>
            <xsd:element name="noMangle2" type="typens:noMangle"/>
            <xsd:element ref="typens:mangle"/>
            <!-- The following better be Mangle_Type[], not Mangle[] -->
            <xsd:element name="mangle2" type="typens:mangle" maxOccurs="unbounded" />
          </xsd:all>
        </xsd:complexType>
  
      </xsd:schema>
    </types>
  
    <!-- message declns -->
    <message name="empty" />
    <message name="message">
      <part name="arg" type="typens:info" />
    </message>
  
    <!-- port type declns -->
    <portType name="RefTest">
      <operation name="test">
        <input message="tns:message"/>
        <output message="tns:empty"/>
      </operation>
    </portType>
  
    <!-- binding declns -->
    <binding name="RefTestBinding" type="tns:RefTest">
      <soap:binding
          style="rpc"
          transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="test">
        <soap:operation soapAction=""/>
        <input>
          <soap:body
              use="encoded"
              namespace=""
              encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </input>
        <output>
          <soap:body
              use="encoded"
              namespace=""
              encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </output>
      </operation>
    </binding>
  
    <!-- service decln -->
    <service name="RefTestService">
      <port name="RefTest" binding="tns:RefTestBinding">
        <soap:address location="http://localhost:8080/axis/services/RefTest"/>
      </port>
    </service>
  
  </definitions>
  
  
  
  
  1.42      +12 -0     xml-axis/java/test/wsdl/Wsdl2javaTestSuite.xml
  
  Index: Wsdl2javaTestSuite.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/Wsdl2javaTestSuite.xml,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- Wsdl2javaTestSuite.xml	2001/12/07 18:32:44	1.41
  +++ Wsdl2javaTestSuite.xml	2001/12/08 04:23:38	1.42
  @@ -50,6 +50,18 @@
           <mapping namespace="urn:MultiRefTest2" package="test.multiref"/>
       </wsdl2java>
   
  +    <!-- MultiRef Test -->
  +    <wsdl2java url="test/refattr/refattr.wsdl"
  +               output="build/work"
  +               deployscope="session"
  +               skeleton="yes"
  +               noimports="no"
  +               verbose="no"
  +               testcase="no">
  +        <mapping namespace="ref.types.test" package="test.refattr"/>
  +        <mapping namespace="ref.types" package="test.refattr"/>
  +    </wsdl2java>
  +
       <!-- Sequence Test -->
       <!-- Generate Java From WSDL -->
       <wsdl2java url="test/sequence/SequenceTest.wsdl"
  
  
  

Mime
View raw message