scheu       02/03/19 15:29:29

  Modified:    java/src/org/apache/axis/wsdl/toJava
                        JavaComplexTypeWriter.java JavaTypeWriter.java
                        SchemaUtils.java SymbolTable.java Utils.java
               java/test/wsdl/types VerifyTestCase.java
  Log:
  Problem:
  --------
  Simple types of the form:
  
   <simpleType name="simple">
     <restriction base="xsd:string" />
   </simpleType>
  
  are currently mapped as references to an existing java class
  (java.lang.String in the case above).
  
  This has several undesirable side effect of serializing
  all Strings as the type "simple" !
  
  Solution:
  ---------
  The solution is to generate bean classes (via JavaComplexTypeWriter)
  for the simpleType constructs.
  
  The emitted beans will be the same style as the classes emitted for
  complexType constructs with simpleContent (which is the reason
  why JavaComplexTypeWriter is used).
  
  In the future, these simpleType emitted classes will be useful
  for implementing facet restriction code.
  
  Details:
  --------
    1) Changed the SchemaUtils:getComplexElementDeclarations to
       getContainedElementDeclarations since it is used to
       get the "value" element for a simpleType.
  
       The change also makes the reference count processing and
       nested processing the same for simpleTypes and complexTypes
       ...a good thing.
  
    2) Made minor changes to JavaComplexTypeWriter.  (The
       name of this class should be changed to JavaBeanWriter.)
  
    3) Minor changes to the SymbolTable processing to
       remove the old processing of simpleTypes.
  
    4) Minor testcase changes.
  
  Revision  Changes    Path
  1.25      +18 -16    
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaComplexTypeWriter.java
  
  Index: JavaComplexTypeWriter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaComplexTypeWriter.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- JavaComplexTypeWriter.java        19 Mar 2002 20:15:28 -0000      1.24
  +++ JavaComplexTypeWriter.java        19 Mar 2002 23:29:28 -0000      1.25
  @@ -1,4 +1,4 @@
  -/*
  + /*
    * The Apache Software License, Version 1.1
    *
    *
  @@ -111,21 +111,23 @@
   
           // We are only interested in the java names of the types, so create a names 
list
           Vector names = new Vector();
  -        for (int i = 0; i < elements.size(); i++) {
  -            ElementDecl elem = (ElementDecl)elements.get(i);
  -            TypeEntry type = elem.getType();
  -            String elemName = elem.getName().getLocalPart();
  -            String javaName = Utils.xmlNameToJava(elemName);
  -            if (!javaName.equals(elemName)) {
  -                // If we did some mangling, make sure we'll write out the XML
  -                // the correct way.
  -                if (elementMappings == null)
  -                    elementMappings = new HashMap();
  +        if (elements != null) {
  +            for (int i = 0; i < elements.size(); i++) {
  +                ElementDecl elem = (ElementDecl)elements.get(i);
  +                TypeEntry type = elem.getType();
  +                String elemName = elem.getName().getLocalPart();
  +                String javaName = Utils.xmlNameToJava(elemName);
  +                if (!javaName.equals(elemName)) {
  +                    // If we did some mangling, make sure we'll write out the XML
  +                    // the correct way.
  +                    if (elementMappings == null)
  +                        elementMappings = new HashMap();
   
  -                elementMappings.put(javaName, elem.getName());
  +                    elementMappings.put(javaName, elem.getName());
  +                }
  +                names.add(type.getName());
  +                names.add(javaName);
               }
  -            names.add(type.getName());
  -            names.add(javaName);
           }
           // add the attributes to the names list (which will be bean elements too)
           if (attributes != null) {
  @@ -148,7 +150,7 @@
                   valueType = (String) names.get(i);
               pw.print("    private " + names.get(i) + " " + variable + ";");
               // label the attribute fields.
  -            if (i >= elements.size())
  +            if (elements == null || i >= (elements.size()*2))
                   pw.println("  // attribute");
               else
                   pw.println();
  @@ -208,7 +210,7 @@
               // like the reasonable approach to take for collection types.
               // (It may be more efficient to handle this with an ArrayList...but
               // for the initial support it was easier to use an actual array.) 
  -            if (j < elements.size()) {
  +            if (elements != null && j < elements.size()) {
                   ElementDecl elem = (ElementDecl)elements.get(j);
                   if (elem.getType().getQName().getLocalPart().indexOf("[") > 0) {
                       String compName = typeName.substring(0, 
typeName.lastIndexOf("["));
  
  
  
  1.7       +25 -16    
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaTypeWriter.java
  
  Index: JavaTypeWriter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaTypeWriter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JavaTypeWriter.java       19 Mar 2002 20:15:28 -0000      1.6
  +++ JavaTypeWriter.java       19 Mar 2002 23:29:28 -0000      1.7
  @@ -51,7 +51,7 @@
    * individuals on behalf of the Apache Software Foundation.  For more
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
  - */
  + */ 
   package org.apache.axis.wsdl.toJava;
   
   import java.io.IOException;
  @@ -84,32 +84,41 @@
               SymbolTable symbolTable) {
           if (type.isReferenced() && !type.isOnlyLiteralReferenced()) {
   
  -            // Determine what sort of type this is and instantiate the appropriate 
Writer.
  +            // Determine what sort of type this is and instantiate 
  +            // the appropriate Writer.
               Node node = type.getNode();
   
               // If it's an array, don't emit a class
               if (!type.getName().endsWith("[]")) {
   
                   // Generate the proper class for either "complex" or "enumeration" 
types
  -                Vector v = SchemaUtils.getComplexElementDeclarations(
  +                Vector v = SchemaUtils.getEnumerationBaseAndValues(
                           node, symbolTable);
                   if (v != null) {
  -                    typeWriter = new 
  -                            JavaComplexTypeWriter(emitter, 
  -                                                  type, 
  -                                                  v,
  -                                                  
SchemaUtils.getComplexElementExtensionBase(
  -                                                          node, symbolTable), 
  -                                                  
SchemaUtils.getComplexElementAttributes(
  -                                                          node, 
  -                                                          symbolTable));
  +                    typeWriter = new JavaEnumTypeWriter(emitter, type, v);
                   }
                   else {
  -                    v = SchemaUtils.getEnumerationBaseAndValues(
  -                            node, symbolTable);
  -                    if (v != null) {
  -                        typeWriter = new JavaEnumTypeWriter(emitter, type, v);
  +                    TypeEntry base = SchemaUtils.getComplexElementExtensionBase(
  +                       node, symbolTable);
  +                    if (base == null) {
  +                        QName baseQName = SchemaUtils.getSimpleTypeBase(
  +                           node, symbolTable);
  +                        if (baseQName != null) {
  +                            base = symbolTable.getType(baseQName);
  +                        }
                       }
  +
  +                    typeWriter = new 
  +                        JavaComplexTypeWriter(
  +                            emitter, 
  +                            type, 
  +                            SchemaUtils.getContainedElementDeclarations(
  +                                node, 
  +                                symbolTable),
  +                            base,
  +                            SchemaUtils.getContainedAttributeTypes(
  +                                 node, 
  +                                 symbolTable));
                   }
               }
   
  
  
  
  1.16      +35 -17    xml-axis/java/src/org/apache/axis/wsdl/toJava/SchemaUtils.java
  
  Index: SchemaUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/SchemaUtils.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SchemaUtils.java  19 Mar 2002 20:15:28 -0000      1.15
  +++ SchemaUtils.java  19 Mar 2002 23:29:28 -0000      1.16
  @@ -82,14 +82,19 @@
   public class SchemaUtils {
   
       /**
  -     * If the specified node represents a supported JAX-RPC complexType/element,
  -     * a Vector is returned which contains ElementDecls for the child
  -     * elements.
  -     * 
  -     * If the specified node is not a supported JAX-RPC complexType/element
  -     * null is returned.
  +     * If the specified node represents a supported JAX-RPC complexType or 
  +     * simpleType, a Vector is returned which contains ElementDecls for the 
  +     * child element names. 
  +     * If the element is a simpleType, an ElementDecls is built representing
  +     * the restricted type with the special name "value".
  +     * If the element is a complexType which has simpleContent, an ElementDecl
  +     * is built representing the extended type with the special name "value".
  +     * This method does not return attribute names and types
  +     * (use the getContainedAttributeTypes)
  +     * If the specified node is not a supported 
  +     * JAX-RPC complexType/simpleType/element null is returned.
        */
  -    public static Vector getComplexElementDeclarations(Node node, SymbolTable 
symbolTable) {
  +    public static Vector getContainedElementDeclarations(Node node, SymbolTable 
symbolTable) {
           if (node == null) {
               return null;
           }
  @@ -112,7 +117,7 @@
               }
           }
   
  -        // Expecting a schema complexType
  +        // Expecting a schema complexType or simpleType
           nodeKind = Utils.getNodeQName(node);
           if (nodeKind != null &&
               nodeKind.getLocalPart().equals("complexType") &&
  @@ -158,8 +163,7 @@
                                                             "base");
                           
                           // Return an element declaration with a fixed name
  -                        // ("value") and the correct type.
  -                        
  +                        // ("value") and the correct type.                        
                           Vector v = new Vector();
                           ElementDecl elem = new ElementDecl();
                           elem.setType(symbolTable.getTypeEntry(extendsType, false));
  @@ -215,12 +219,26 @@
                   }
                   return v;
               }
  +        } else {
  +            // This may be a simpleType, return the type with the name "value"
  +            QName simpleQName = getSimpleTypeBase(node, symbolTable);
  +            if (simpleQName != null) {
  +                TypeEntry simpleType = symbolTable.getType(simpleQName);
  +                if (simpleType != null) {
  +                    Vector v = new Vector();
  +                    ElementDecl elem = new ElementDecl();
  +                    elem.setType(simpleType);
  +                    elem.setName(new javax.xml.rpc.namespace.QName("", "value"));
  +                    v.add(elem);
  +                    return v;
  +                }
  +            }
           }
           return null;
       }
   
       /**
  -     * Invoked by getComplexElementTypesAndNames to get the child element types
  +     * Invoked by getContainedElementDeclarations to get the child element types
        * and child element names underneath a Choice Node
        */
       private static Vector processChoiceNode(Node choiceNode, 
  @@ -250,7 +268,7 @@
       }
   
       /**
  -     * Invoked by getComplexElementTypesAndNames to get the child element types
  +     * Invoked by getContainedElementDeclarations to get the child element types
        * and child element names underneath a Sequence Node
        */
       private static Vector processSequenceNode(Node sequenceNode, 
  @@ -280,7 +298,7 @@
       }
   
       /**
  -     * Invoked by getComplexElementTypesAndNames to get the child element types
  +     * Invoked by getContainedElementDeclarations to get the child element types
        * and child element names underneath a group node.
        * (Currently the code only supports a defined group it does not
        * support a group that references a previously defined group)
  @@ -305,7 +323,7 @@
       }
   
       /**
  -     * Invoked by getComplexElementTypesAndNames to get the child element types
  +     * Invoked by getContainedElementDeclarations to get the child element types
        * and child element names underneath an all node.
        */
       private static Vector processAllNode(Node allNode, SymbolTable symbolTable) {
  @@ -329,7 +347,7 @@
   
   
       /**
  -     * Invoked by getComplexElementTypesAndNames to get the child element type
  +     * Invoked by getContainedElementDeclarations to get the child element type
        * and child element name for a child element node.
        *
        * If the specified node represents a supported JAX-RPC child element,
  @@ -1019,8 +1037,8 @@
        * </complexType>
        * 
        */ 
  -    public static Vector getComplexElementAttributes(Node node, 
  -                                                     SymbolTable symbolTable) 
  +    public static Vector getContainedAttributeTypes(Node node, 
  +                                                    SymbolTable symbolTable) 
       {
           Vector v = null;    // return value
           
  
  
  
  1.47      +4 -8      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.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- SymbolTable.java  19 Mar 2002 20:15:29 -0000      1.46
  +++ SymbolTable.java  19 Mar 2002 23:29:28 -0000      1.47
  @@ -645,11 +645,10 @@
                   IntHolder numDims = new IntHolder();
                   numDims.value = 0;
                   QName arrayEQName = SchemaUtils.getArrayElementQName(node, numDims);
  -                QName simpleQName = SchemaUtils.getSimpleTypeBase(node, this);
   
  -                if (arrayEQName != null || simpleQName != null) {
  -                    // Get the TypeEntry for the array element/simple type
  -                    refQName = (arrayEQName != null ? arrayEQName : simpleQName);
  +                if (arrayEQName != null) {
  +                    // Get the TypeEntry for the array element type
  +                    refQName = arrayEQName;
                       TypeEntry refType = getTypeEntry(refQName, false);
                       if (refType == null) {
                           // Not defined yet, add one
  @@ -677,9 +676,6 @@
                           defType = new DefinedType(qName, refType, node, dims);
                       }
                       if (defType != null) {
  -                        if (simpleQName != null) {
  -                            defType.setSimpleType(true);
  -                        }
                           symbolTablePut(defType);
                       }
                   }
  @@ -1164,7 +1160,7 @@
   
               // Get the nested type entries.
               Vector vTypes =
  -                    SchemaUtils.getComplexElementDeclarations(node, this);
  +                    SchemaUtils.getContainedElementDeclarations(node, this);
   
               if (vTypes != null) {
                   // add the elements in this list
  
  
  
  1.22      +2 -2      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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Utils.java        19 Mar 2002 20:15:29 -0000      1.21
  +++ Utils.java        19 Mar 2002 23:29:28 -0000      1.22
  @@ -616,7 +616,7 @@
       private static void getNestedTypes(
               Node type, HashSet types, SymbolTable symbolTable) {
           // Process types declared in this type
  -        Vector v = SchemaUtils.getComplexElementDeclarations(type, symbolTable);
  +        Vector v = SchemaUtils.getContainedElementDeclarations(type, symbolTable);
           if (v != null) {
               for (int i = 0; i < v.size(); i++) {
                   ElementDecl elem = (ElementDecl)v.get(i);
  @@ -629,7 +629,7 @@
               }
           }
           // Process attributes declared in this type
  -        v = SchemaUtils.getComplexElementAttributes(type, symbolTable);
  +        v = SchemaUtils.getContainedAttributeTypes(type, symbolTable);
           if (v != null) {
               for (int i = 0; i < v.size(); i+=2) {
                   if (!types.contains(v.get(i))) {
  
  
  
  1.15      +4 -2      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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- VerifyTestCase.java       11 Mar 2002 16:25:32 -0000      1.14
  +++ VerifyTestCase.java       19 Mar 2002 23:29:29 -0000      1.15
  @@ -55,6 +55,8 @@
   import test.wsdl.types.comprehensive_types.EnumShort;
   import test.wsdl.types.comprehensive_types.EnumString;
   import test.wsdl.types.comprehensive_types.StockQuote;
  +import test.wsdl.types.comprehensive_types.Simple;
  +import test.wsdl.types.comprehensive_types.SimpleFwd;
   import test.wsdl.types.comprehensive_types.Time;
   import test.wsdl.types.comprehensive_types.StringParameter;
   import test.wsdl.types.comprehensive_types2.A;
  @@ -233,7 +235,7 @@
           StringParameter sp = new StringParameter("sweet!");
           sp.setDescription("Pass this as an element and an attribute...wow!");
   
  -        elemWComplex.setOne( "one");
  +        elemWComplex.setOne( new Simple("one"));
           elemWComplex.setTwo( new QName[] {new QName("two")});
           elemWComplex.setThree( new Enum[] {Enum.three});
           elemWComplex.setEnum1( EnumString.value1);
  @@ -268,7 +270,7 @@
           }
           StockQuote stockQuote = new StockQuote();
           stockQuote.setTime(new Time());
  -        stockQuote.setChange("5");
  +        stockQuote.setChange(new SimpleFwd("5"));
           stockQuote.setPctchange("100%");
           stockQuote.setBid("9");
           stockQuote.setAsk("11");
  
  
  


Reply via email to