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/types ComprehensiveTypes.wsdl VerifyTestCase.java
Date Wed, 20 Mar 2002 20:53:57 GMT
scheu       02/03/20 12:53:57

  Modified:    java/src/org/apache/axis/wsdl/toJava JavaStubWriter.java
                        SymbolTable.java Utils.java
               java/test/wsdl/types ComprehensiveTypes.wsdl
                        VerifyTestCase.java
  Log:
  Cool changes to more fully support derived type usage!
  
  Changes made to support:
     1) Marking derived types as referenced if base type is referenced.
     2) Missing type attribute (and no other type info) should be accepted as an xsd:anyType.
     3) Mark all types as referenced if anyType is referenced.
  
  Details:
     1) Added Utils.getDerivedTypes method that gets the derived types of
        the indicated TypeEntry type. If the indicated type is an xsd:anyType, then
        all the TypeEntries in the symbol table are returned.  I also
        added some code to getDerivedTypes and getNestedTypes to check the size
        of the current set versus the size of the symbol table.  Obviously if the
        sizes are the same, no more processing needs to be performed.
  
     2) Changed Utils.getNestedTypes to use a TypeEntry parameters instead of a Node parameters.
        Also added a derivedFlag parameter.  If this flag is set, the nested and
        derived types are returned.
  
     3) Changed setTypeReferences to consider derived types.
  
     4) Changed Utils.getNodeTypeRefQName to handle defaulting of type attribute
        on an element/attribute.
  
     5) Changed comprehensive test to test these new features.
  
  Revision  Changes    Path
  1.48      +4 -5      xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
  
  Index: JavaStubWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- JavaStubWriter.java	19 Mar 2002 20:15:28 -0000	1.47
  +++ JavaStubWriter.java	20 Mar 2002 20:53:56 -0000	1.48
  @@ -313,16 +313,15 @@
               firstPassTypes.addAll(getTypesInOperation(op));
           }
   
  -        // Extract those types which are complex types.
  +        // Add all the types nested and derived from the types
  +        // in the first pass.
           Iterator i = firstPassTypes.iterator();
           while (i.hasNext()) {
               TypeEntry type = (TypeEntry) i.next();
               if (!types.contains(type)) {
                   types.add(type);
  -                if ((type.getNode() != null) && type.getBaseType() == null) {
  -                    types.addAll(
  -                            Utils.getNestedTypes(type.getNode(), symbolTable));
  -                }
  +                types.addAll(
  +                   Utils.getNestedTypes(type, symbolTable, true));
               }
           }
           return types;
  
  
  
  1.49      +13 -4     xml-axis/java/src/org/apache/axis/wsdl/toJava/SymbolTable.java
  
  Index: SymbolTable.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/SymbolTable.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- SymbolTable.java	20 Mar 2002 13:36:47 -0000	1.48
  +++ SymbolTable.java	20 Mar 2002 20:53:56 -0000	1.49
  @@ -540,8 +540,8 @@
               else if (isXSD && localPart.equals("element")) {
                   // If the element has a type/ref attribute, create
                   // a Type representing the referenced type.
  -                if (Utils.getAttribute(node, "type") != null ||
  -                    Utils.getAttribute(node, "ref") != null) {
  +                if (Utils.getNodeTypeRefQName(node, "type") != null ||
  +                    Utils.getNodeTypeRefQName(node, "ref") != null) {
                       createTypeFromRef(node);
                   }
   
  @@ -561,7 +561,7 @@
               else if (isXSD && localPart.equals("attribute")) {
                   // If the attribute has a type/ref attribute, create
                   // a Type representing the referenced type.
  -                if (Utils.getAttribute(node, "type") != null) {
  +                if (Utils.getNodeTypeRefQName(node, "type") != null) {
                       createTypeFromRef(node);
                   }
   
  @@ -1340,6 +1340,9 @@
       /**
        * Set each SymTabEntry's isReferenced flag.  The default is false.  If no other symbol
        * references this symbol, then leave it false, otherwise set it to true.
  +     * (An exception to the rule is that derived types are set as referenced if 
  +     * their base type is referenced.  This is necessary to support generation and
  +     * registration of derived types.)
        */
       private void setReferences(Definition def, Document doc) {
           Map stuff = def.getServices();
  @@ -1401,6 +1404,12 @@
       private void setTypeReferences(TypeEntry entry, Document doc,
               boolean literal) {
   
  +        // Check to see if already processed.
  +        if ((entry.isReferenced() && !literal) ||
  +            (entry.isOnlyLiteralReferenced() && literal)) {
  +            return;
  +        }
  +
           if (wrapped) {
               // If this type is ONLY referenced from a literal usage in a binding,
               // then isOnlyLiteralReferenced should return true.
  @@ -1443,7 +1452,7 @@
               }
           }
   
  -        HashSet nestedTypes = Utils.getNestedTypes(node, this);
  +        HashSet nestedTypes = Utils.getNestedTypes(entry, this, true);
           Iterator it = nestedTypes.iterator();
           while (it.hasNext()) {
               TypeEntry nestedType = (TypeEntry) it.next();
  
  
  
  1.23      +111 -16   xml-axis/java/src/org/apache/axis/wsdl/toJava/Utils.java
  
  Index: Utils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/Utils.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Utils.java	19 Mar 2002 23:29:28 -0000	1.22
  +++ Utils.java	20 Mar 2002 20:53:56 -0000	1.23
  @@ -68,6 +68,7 @@
   import java.util.HashSet;
   import java.util.StringTokenizer;
   import java.util.Vector;
  +import java.util.Iterator;
   
   import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.Constants;      
  @@ -361,6 +362,26 @@
               return null;
           }
           String prefixedName = getAttribute(node, typeAttrName);
  +
  +        // The type attribute defaults to xsd:anyType if there
  +        // are no other conflicting attributes and no anonymous type.
  +        if (prefixedName == null &&
  +            typeAttrName.equals("type")) {
  +            if (getAttribute(node, "ref") == null &&
  +                getAttribute(node, "base") == null && 
  +                getAttribute(node, "element") == null &&
  +                SchemaUtils.getElementAnonQName(node) == null) {
  +                QName nodeName = getNodeQName(node);
  +                if (nodeName != null &&
  +                    Constants.isSchemaXSD(nodeName.getNamespaceURI()) &&
  +                    (nodeName.getLocalPart().equals("element") ||
  +                     nodeName.getLocalPart().equals("attribute"))) {
  +                    return getWSDLQName(Constants.XSD_ANYTYPE);
  +                }
  +            }              
  +        }
  +         
  +        // Return null if not found
           if (prefixedName == null) {
               return null;
           }
  @@ -602,46 +623,123 @@
   
   
       /**
  +     * This method returns a set of all types that are derived
  +     * from this type via an extension of a complexType
  +     */
  +    public static HashSet getDerivedTypes(TypeEntry type, SymbolTable symbolTable) {
  +        HashSet types = new HashSet();
  +        if (type != null && type.getNode() != null) {
  +            getDerivedTypes(type, types, symbolTable);
  +        } else if (Constants.isSchemaXSD(type.getQName().getNamespaceURI()) &&
  +                   type.getQName().getLocalPart().equals("anyType")) {
  +            // All types are derived from anyType
  +            types.addAll(symbolTable.getTypes());
  +        }
  +        return types;
  +    } // getNestedTypes
  +
  +    private static void getDerivedTypes(
  +            TypeEntry type, HashSet types, SymbolTable symbolTable) {
  +
  +        // If all types are in the set, return
  +        if (types.size() == symbolTable.getTypes().size()) {
  +            return;
  +        }
  +
  +        // Search the dictionary for derived types of type
  +        Vector allTypes = symbolTable.getTypes();
  +        Iterator it = allTypes.iterator();
  +        while(it.hasNext()) {
  +            TypeEntry derivedType = (TypeEntry) it.next();
  +            if (derivedType instanceof DefinedType &&
  +                derivedType.getNode() != null &&
  +                !types.contains(derivedType) &&
  +                SchemaUtils.getComplexElementExtensionBase(
  +                   derivedType.getNode(),
  +                   symbolTable) == type) {
  +                types.add(derivedType);
  +                getDerivedTypes(derivedType, types, symbolTable);
  +            }
  +        }
  +    } // getDerivedTypes
  +
  +    /**
        * This method returns a set of all the nested types.
        * Nested types are types declared within this TypeEntry (or descendents)
        * plus any extended types and the extended type nested types
        * The elements of the returned HashSet are Types.
  +     * @param type is the type entry to consider
  +     * @param symbolTable is the symbolTable
  +     * @param derivedFlag should be set if all dependendent derived types should also be

  +     * returned.
        */
  -    public static HashSet getNestedTypes(Node type, SymbolTable symbolTable) {
  +    public static HashSet getNestedTypes(TypeEntry type, SymbolTable symbolTable, 
  +                                         boolean derivedFlag) {
           HashSet types = new HashSet();
  -        getNestedTypes(type, types, symbolTable);
  +        getNestedTypes(type, types, symbolTable, derivedFlag);
           return types;
       } // getNestedTypes
   
       private static void getNestedTypes(
  -            Node type, HashSet types, SymbolTable symbolTable) {
  +            TypeEntry type, HashSet types, SymbolTable symbolTable, 
  +            boolean derivedFlag) {
  +
  +        if (type == null) {
  +            return;
  +        }
  +        
  +        // If all types are in the set, return
  +        if (types.size() == symbolTable.getTypes().size()) {
  +            return;
  +        }
  +        
  +        // Process types derived from this type
  +        if (derivedFlag) {
  +            HashSet derivedTypes = getDerivedTypes(type, symbolTable);
  +            Iterator it = derivedTypes.iterator();
  +            while(it.hasNext()) {
  +                TypeEntry derivedType = (TypeEntry) it.next();
  +                if (!types.contains(derivedType)) {
  +                    types.add(derivedType);
  +                    getNestedTypes(derivedType, types, symbolTable, derivedFlag);
  +                }
  +            }
  +        }
  +        
  +        // Continue only if the node exists
  +        if(type.getNode() == null) {
  +            return;
  +        }
  +        Node node = type.getNode();
  +
           // Process types declared in this type
  -        Vector v = SchemaUtils.getContainedElementDeclarations(type, symbolTable);
  +        Vector v = SchemaUtils.getContainedElementDeclarations(node, symbolTable);
           if (v != null) {
               for (int i = 0; i < v.size(); i++) {
                   ElementDecl elem = (ElementDecl)v.get(i);
                   if (!types.contains(elem.getType())) {
                       types.add(elem.getType());
  -                    getNestedTypes(elem.getType().getNode(), 
  +                    getNestedTypes(elem.getType(), 
                                      types, 
  -                                   symbolTable);
  +                                   symbolTable, derivedFlag);
                   }
               }
           }
  +
           // Process attributes declared in this type
  -        v = SchemaUtils.getContainedAttributeTypes(type, symbolTable);
  +        v = SchemaUtils.getContainedAttributeTypes(node, symbolTable);
           if (v != null) {
               for (int i = 0; i < v.size(); i+=2) {
                   if (!types.contains(v.get(i))) {
                       types.add(v.get(i));
                       getNestedTypes(
  -                            ((TypeEntry) v.get(i)).getNode(), types, symbolTable);
  +                            ((TypeEntry) v.get(i)), types, symbolTable, derivedFlag);
                   }
               }
           }
           
           // Get the anonymous type of the element
  -        QName anonQName = SchemaUtils.getElementAnonQName(type);
  +        QName anonQName = SchemaUtils.getElementAnonQName(node);
           if (anonQName != null) {
               TypeEntry anonType = symbolTable.getType(anonQName);
               if (anonType != null && !types.contains(anonType)) {
  @@ -650,26 +748,23 @@
           }
   
           // Process extended types
  -        TypeEntry extendType = SchemaUtils.getComplexElementExtensionBase(type, symbolTable);
  +        TypeEntry extendType = SchemaUtils.getComplexElementExtensionBase(node, symbolTable);
           if (extendType != null) {
               if (!types.contains(extendType)) {
                   types.add(extendType);
  -                getNestedTypes(extendType.getNode(), types, symbolTable);
  +                getNestedTypes(extendType, types, symbolTable, derivedFlag);
               }
           }
   
           // Process array element types
  -        QName elementQName = SchemaUtils.getArrayElementQName(type, new IntHolder(0));
  +        QName elementQName = SchemaUtils.getArrayElementQName(node, new IntHolder(0));
           TypeEntry elementType = symbolTable.getType(elementQName);
           if (elementType != null) {
               if (!types.contains(elementType)) {
                   types.add(elementType);
  -                getNestedTypes(elementType.getNode(), types, symbolTable);
  +                getNestedTypes(elementType, types, symbolTable, derivedFlag);
               }
           }
  -        
  -        
  -
       } // getNestedTypes
   
       /**
  
  
  
  1.20      +20 -0     xml-axis/java/test/wsdl/types/ComprehensiveTypes.wsdl
  
  Index: ComprehensiveTypes.wsdl
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/types/ComprehensiveTypes.wsdl,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ComprehensiveTypes.wsdl	11 Mar 2002 16:25:32 -0000	1.19
  +++ ComprehensiveTypes.wsdl	20 Mar 2002 20:53:57 -0000	1.20
  @@ -157,6 +157,26 @@
         </xsd:complexType>
         <xsd:element name="Cat" nillable="true" type="typens:Cat"/>
   
  +      <!-- Even though PersionCat is not directly referenced, it should
  +      be generated and registered because its base class (Cat) is referenced -->
  +      <xsd:complexType name="PersionCat">
  +        <xsd:complexContent>
  +          <xsd:extension base="typens:Cat">
  +            <xsd:all>
  +              <xsd:element name="Color" type="xsd:string"/>
  +              <xsd:element name="Toy" /> <!-- Defaults to xsd:anyType -->
  +            </xsd:all>
  +          </xsd:extension>
  +        </xsd:complexContent>
  +      </xsd:complexType>
  +
  +      <!-- Even though Yarn is not directly referenced, it should
  +      be generated and registered because the Toy above is an anyType -->
  +      <xsd:complexType name="Yarn">
  +         <xsd:all>
  +           <xsd:element name="Color" type="xsd:string"/>
  +         </xsd:all>
  +      </xsd:complexType>
   
         <!-- The following test all of the valid enum basic types -->
         <xsd:simpleType name="enumString">
  
  
  
  1.16      +19 -0     xml-axis/java/test/wsdl/types/VerifyTestCase.java
  
  Index: VerifyTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/types/VerifyTestCase.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- VerifyTestCase.java	19 Mar 2002 23:29:29 -0000	1.15
  +++ VerifyTestCase.java	20 Mar 2002 20:53:57 -0000	1.16
  @@ -37,6 +37,8 @@
   import test.wsdl.types.comprehensive_types.ArrayMHolder;
   import test.wsdl.types.comprehensive_types.Cat;
   import test.wsdl.types.comprehensive_types.CatHolder;
  +import test.wsdl.types.comprehensive_types.PersionCat;
  +import test.wsdl.types.comprehensive_types.Yarn;
   import test.wsdl.types.comprehensive_types.ComplexAll;
   import test.wsdl.types.comprehensive_types.ComplexAllHolder;
   import test.wsdl.types.comprehensive_types.ComplexSequence;
  @@ -312,6 +314,12 @@
           }
           Cat cat = new Cat();
           cat.setPurr("meow");
  +        PersionCat persion = new PersionCat();
  +        Yarn yarn = new Yarn();
  +        yarn.setColor("green");
  +        persion.setPurr("meow meow");
  +        persion.setColor("blue");
  +        persion.setToy(yarn); 
           try {
               binding.animalIn(cat);
           } catch (java.rmi.RemoteException re) {
  @@ -344,6 +352,17 @@
           } catch (java.rmi.RemoteException re) {
               throw new junit.framework.AssertionFailedError("Remote Exception caught: "
+ re );
           }
  +        try {
  +            binding.catIn(persion);
  +        } catch (java.rmi.RemoteException re) {
  +            throw new junit.framework.AssertionFailedError("Remote Exception caught: "
+ re );
  +        }
  +        try {
  +            binding.catInout(new CatHolder(persion));
  +        } catch (java.rmi.RemoteException re) {
  +            throw new junit.framework.AssertionFailedError("Remote Exception caught: "
+ re );
  +        }
  +
           try {
               BooleanHolder bh = new BooleanHolder(true);
               boolean actual = binding.methodBoolean(true, bh);
  
  
  

Mime
View raw message