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/src/org/apache/axis/wsdl Emitter.java SchemaUtils.java SymbolTable.java Utils.java
Date Fri, 07 Dec 2001 20:13:08 GMT
scheu       01/12/07 12:13:08

  Modified:    java/src/org/apache/axis/wsdl Emitter.java SchemaUtils.java
                        SymbolTable.java Utils.java
  Log:
  Added initial support for 'collection types'
  
    <element name="foo_collection" type="bar" maxOccurs="unbounded" />
  
  A "bar[1,unbounded]" QName/Type is entered into the symbol table for the
  above node.  The first indice is the minOccurs value and the second is
  the maxOccurs value.
  
  Initially the "collection Type" is mapped to a java array.
  JAX-RPC needs to define the true way of handling these cases.
  
  I also added some bug fixes.
  
  Revision  Changes    Path
  1.113     +1 -1      xml-axis/java/src/org/apache/axis/wsdl/Emitter.java
  
  Index: Emitter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Emitter.java,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -r1.112 -r1.113
  --- Emitter.java	2001/12/06 13:47:31	1.112
  +++ Emitter.java	2001/12/07 20:13:08	1.113
  @@ -147,7 +147,7 @@
               }
           }
   
  -        symbolTable = new SymbolTable(namespaces, bGenerateImports);
  +        symbolTable = new SymbolTable(namespaces, bGenerateImports, bDebug);
           symbolTable.add(def, doc);
           writerFactory.writerPass(def, symbolTable);
           if (bDebug) {
  
  
  
  1.5       +40 -6     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SchemaUtils.java	2001/12/06 23:12:34	1.4
  +++ SchemaUtils.java	2001/12/07 20:13:08	1.5
  @@ -355,14 +355,47 @@
        * forms, then return the qname repesenting the element type of the array.
        */
       public static QName getArrayElementQName(Node node) {
  -        QName qName = getArrayElementQName_JAXRPC(node);
  -        if (qName != null)
  -            return qName;
  -        // qName = getArrayElementQName_nonJAXRPC(node);
  +        QName qName = getCollectionElementQName(node);
  +        if (qName == null)
  +            qName = getArrayElementQName_JAXRPC(node);
  +        // if (qName == null)
  +        //   qName = getArrayElementQName_nonJAXRPC(node);
           return qName;
       }
   
       /**
  +     * If the specified node represents an element that refernces a collection
  +     * then return the qname repesenting the element type of the collection.
  +     *
  +     *  <xsd:element name="alias" type="xsd:string" maxOccurs="unbounded"/>
  +     *
  +     */
  +    private static QName getCollectionElementQName(Node node) {
  +        if (node == null) {
  +            return null;
  +        }
  +
  +        // If the node kind is an element, dive get its type.
  +        QName nodeKind = Utils.getNodeQName(node);
  +        if (nodeKind != null &&
  +            nodeKind.getLocalPart().equals("element") &&
  +            Utils.isSchemaNS(nodeKind.getNamespaceURI())) {
  +
  +            // Get the qName of just the type.
  +            // The compare it against the full type of the node, which
  +            // takes into account maxOccurs and could return a collection type.
  +            // If different, return just the type (which is the collection element type).
  +            QName justTypeQName = Utils.getNodeTypeRefQName(node, "type");
  +            if (justTypeQName != null) {
  +                QName fullTypeQName = Utils.getNodeTypeRefQName(node);
  +                if (justTypeQName != fullTypeQName)
  +                    return justTypeQName;
  +            }
  +        }
  +        return null;
  +    }
  +
  +    /**
        * If the specified node represents an array encoding of one of the following
        * forms, then return the qname repesenting the element type of the array.
        *
  @@ -531,7 +564,8 @@
                       String maxOccursValue = Utils.getAttribute(elementNode, "maxOccurs");
                       if (maxOccursValue != null &&
                           maxOccursValue.equalsIgnoreCase("unbounded")) {
  -                        return Utils.getNodeTypeRefQName(elementNode);
  +                        // Get the QName of just the type
  +                        return Utils.getNodeTypeRefQName(elementNode, "type");
                       }
                   }
               }
  @@ -624,7 +658,7 @@
                   String maxOccursValue = Utils.getAttribute(elementNode, "maxOccurs");
                   if (maxOccursValue != null &&
                       maxOccursValue.equalsIgnoreCase("unbounded")) {
  -                    return Utils.getNodeTypeRefQName(elementNode);
  +                    return Utils.getNodeTypeRefQName(elementNode, "type");
                   }
               }
           }
  
  
  
  1.20      +25 -1     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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SymbolTable.java	2001/12/06 21:24:14	1.19
  +++ SymbolTable.java	2001/12/07 20:13:08	1.20
  @@ -124,12 +124,15 @@
       // A list of the Type elements in the symbol table
       private Vector types = new Vector();
   
  +    private boolean debug = false;
  +
       /**
        * Construct a symbol table with the given Namespaces.
        */
  -    public SymbolTable(Namespaces namespaces, boolean addImports) {
  +    public SymbolTable(Namespaces namespaces, boolean addImports, boolean debug) {
           this.namespaces = namespaces;
           this.addImports = addImports;
  +        this.debug = debug;
       } // ctor
   
       /**
  @@ -332,6 +335,10 @@
           // Get the QName of the node's name attribute value
           QName qName = Utils.getNodeNameQName(node);
           if (qName != null) {
  +            if (debug) {
  +                System.out.println("Create Type From Def:" + qName);
  +            }
  +
               map(qName.getNamespaceURI());
   
               // If the node has a type or ref attribute, get the 
  @@ -345,6 +352,10 @@
                       if (refType != null &&
                           refType.getNode() != null) {
                           refQName = Utils.getNodeTypeRefQName(refType.getNode());
  +                        // 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()))
  +                            refQName = null;
                       }                         
                   }
                   // Create a type from the referenced type
  @@ -398,9 +409,14 @@
               Type type = getTypeEntry(qName);
               if (type == null) {
                   // Type not defined, add a base java type or a refdType
  +                if (debug) {
  +                    System.out.println("Create Type From Ref:" + qName);
  +                }
                   String baseJavaName = Utils.getBaseJavaName(qName);
                   if (baseJavaName != null)
                       symbolTablePut(new BaseJavaType(qName));
  +                else if (javaName.indexOf("[") > 0)
  +                    symbolTablePut(new CollectionType(qName, javaName, node));
                   else
                       symbolTablePut(new RefdType(qName, javaName));
               } else {
  @@ -420,6 +436,14 @@
        * Convert the specified QName into a full Java Name.
        */
       public String getJavaName(QName qName) {
  +
  +        // If this is one of our special 'collection' qnames.
  +        // get the element type and append []
  +        if (qName.getLocalPart().indexOf("[") > 0) {
  +            String localPart = qName.getLocalPart().substring(0,qName.getLocalPart().indexOf("["));
  +            QName eQName = new QName(qName.getNamespaceURI(), localPart);
  +            return getJavaName(eQName) + "[]";
  +        }
   
           // Handle the special "java" namespace for types
           if (qName.getNamespaceURI().equalsIgnoreCase("java")) {
  
  
  
  1.24      +43 -1     xml-axis/java/src/org/apache/axis/wsdl/Utils.java
  
  Index: Utils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Utils.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Utils.java	2001/12/07 18:32:43	1.23
  +++ Utils.java	2001/12/07 20:13:08	1.24
  @@ -291,12 +291,42 @@
       /**
        * XML nodes may have a type/ref attribute.
        * For example &lt.element name="foo" type="b:bar"&gt.
  -     * has the type attribute value "b:bar".  This routine gets the QName of the type/ref
attribute value.
  +     * has the type attribute value "b:bar". 
  +     * This routine gets the QName of the type/ref attribute value.
  +     *
  +     * Note: If the "minOccurs" and "maxOccurs" are set such that the 
  +     * type is a collection of "types", then an artificial qname is
  +     * returned to represent the collection.
  +     * 
  +     * If you want the QName for just the "type" without analyzing 
  +     * minOccurs/maxOccurs then use:
  +     *    getNodeTypeRefQName(node, "type")
        */
       public static QName getNodeTypeRefQName(Node node) {
           if (node == null) return null;
   
           QName qName= getNodeTypeRefQName(node, "type");
  +
  +        // If the node has "type" and "maxOccurs" then the type is really
  +        // a collection.  There is qname in the wsdl which we can use to represent
  +        // the collection, so we need to invent one.
  +        // The local part of the qname is changed to <local>[minOccurs, maxOccurs]
  +        if (qName != null) {
  +            String maxOccursValue = getAttribute(node, "maxOccurs");
  +            String minOccursValue = getAttribute(node, "minOccurs");
  +            if (maxOccursValue == null) {
  +                maxOccursValue = "1";
  +            }
  +            if (minOccursValue == null) {
  +                minOccursValue = "1";
  +            }
  +            if (!maxOccursValue.equals("1") || !minOccursValue.equals("1")) {
  +                String localPart = qName.getLocalPart();
  +                localPart += "[" + minOccursValue + "," + maxOccursValue + "]";
  +                qName.setLocalPart(localPart);
  +            }
  +        }
  +
           if (qName == null) {
               qName = getNodeTypeRefQName(node, "ref");
           }
  @@ -580,6 +610,18 @@
                   getNestedTypes(extendType.getNode(), types, symbolTable);
               }
           }
  +
  +        // Process array element types
  +        QName elementQName = SchemaUtils.getArrayElementQName(type);
  +        Type elementType = symbolTable.getTypeEntry(elementQName);
  +        if (elementType != null) {
  +            if (!types.contains(elementType)) {
  +                types.add(elementType);
  +                getNestedTypes(elementType.getNode(), types, symbolTable);
  +            }
  +        }
  +        
  +        
   
       } // getNestedTypes
   
  
  
  

Mime
View raw message