axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bu...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/wsdl Utils.java TypeFactory.java Type.java
Date Tue, 02 Oct 2001 18:37:42 GMT
butek       01/10/02 11:37:42

  Added:       java/src/org/apache/axis/wsdl Utils.java TypeFactory.java
                        Type.java
  Log:
  Submitted by:  Rich Scheuerle.
  
  Split XML schema type processing from Emitter.java into Type.java,
  TypeFactory.java, and Utils.java.
  
  Revision  Changes    Path
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/Utils.java
  
  Index: Utils.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * 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;
  
  import java.util.HashMap;
  import java.util.Iterator;
  
  import org.w3c.dom.Attr;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  import javax.wsdl.QName;
  /**
   * This class contains static utility methods for the emitter.                         
  
   *
   * @author Rich Scheuerle  (scheu@us.ibm.com)
   */
  public class Utils {
  
      /**
       * Capitalize the given name.
       */
      public static String capitalize(String name) {
          char start = name.charAt(0);
      
          if (Character.isLowerCase(start)) {
              start = Character.toUpperCase(start);
              return start + name.substring(1);
          }
          return name;
      } // capitalize 
    
      /**
       * Convenience method to convert local name to Java name
       */
      public static String getJavaName(String localName) {
          return capitalize(localName);
      }
  
      /**
       * Given a node, return the value of the given attribute.
       * If the attribute does not exist, searching continues through ancestor nodes until
found.
       * This method is useful for finding attributes that pertain to a group of contained
       * nodes (i.e. xlmns, xmlns:tns, targetNamespace, name)
       */
      public static String getScopedAttribute(Node node, String attr) {
          if (node == null) {
              return null;
          }
  
          String nameValue = null;
      
          Node attrNode = node.getAttributes().getNamedItem(attr);
          if (attrNode != null) {
              return attrNode.getNodeValue();
          }
          else {
              return getScopedAttribute(node.getParentNode(), attr);
          }
      }
    
      /**
       * Given a node, return the value of the given attribute.
       * Returns null if the attribute is not found
       */
      public static String getAttribute(Node node, String attr) {
          if (node == null) {
              return null;
          }
  
          String nameValue = null;
      
          Node attrNode = node.getAttributes().getNamedItem(attr);
          if (attrNode != null) {
              return attrNode.getNodeValue();
          }
          else {
              return null;
          }
      }
  
      /**
       * An xml element may have a name.
       * For example &lt.element name="foo" type="b:bar"&gt.
       * has the name "element".  This routine gets the full QName of the element.
       */
      public static QName getNodeQName(Node node) {
          if (node == null) {
              return null;
          }
  
          String localName = node.getLocalName();
          if (localName == null) {
              return null;
          }
          String namespace = node.getNamespaceURI();
      
          return (new QName(namespace, localName));
      }
  
      /**
       * XML nodes may have a name attribute.
       * For example &lt.element name="foo" type="b:bar"&gt.
       * has the name attribute value "foo".  This routine gets the QName of the name attribute
value.
       */
      public static QName getNodeNameQName(Node node) {
          if (node == null) {
              return null;
          }
          // This routine may be called for complexType elements.  In some cases,
          // the complexType may be anonymous, which is why the getScopedAttribute 
          // method is used.
          String localName = getScopedAttribute(node, "name");
          if (localName == null)
              return null;
  
          String namespace = getScopedAttribute(node, "targetNamespace");
          return (new QName(namespace, localName));
      }
  
      /**
       * XML nodes may have a type 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 attribute
value.
       */
      public static QName getNodeTypeQName(Node node) {
          return getNodeTypeQName(node, "type");
      }
  
      public static QName getNodeTypeQName(Node node, String typeAttrName) {
          if (node == null) {
              return null;
          }
          String fullName = getAttribute(node, typeAttrName);
          if (fullName == null) {
              return null;
          }
          String localName = fullName.substring(fullName.lastIndexOf(":")+1);
          String namespace = null;
          // Associate the namespace prefix with a namespace
          if (fullName.length() == localName.length()) {
             namespace = getScopedAttribute(node, "xmlns");  // Get namespace for unqualified
reference
          }
          else {
             namespace = getScopedAttribute(node, "xmlns:" + fullName.substring(0, fullName.lastIndexOf(":")));
          }
          return (new QName(namespace, localName));
      }
  
  
      /**
       * Return true if the indicated string is the schema namespace
       */
    public static boolean isSchemaNS(String s) {
      return (s.equals("http://www.w3.org/2001/XMLSchema")
              || s.equals("http://www.w3.org/1999/XMLSchema"));
    }
    
      /**
       * Return true if the indicated string is the schema namespace
       */
      public static boolean isWsdlNS(String s) {
          return (s.equals("http://schemas.xmlsoap.org/wsdl/"));
      }
  
      /**
       * Return true if the indicated string is the soap wsdl namespace
       */
      public static boolean isSoapWsdlNS(String s) {
          return (s.equals("http://schemas.xmlsoap.org/wsdl/soap/"));
      }
  
      /**
       * Return true if the indicated string is the soap encoding namespace
       */
      public static boolean isSoapEncodingNS(String s) {
          return (s.equals("http://www.w3.org/2001/06/soap-encoding"));
      }
  }
  
  
  
  
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/TypeFactory.java
  
  Index: TypeFactory.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * 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;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Vector;
  
  import org.w3c.dom.Attr;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  import javax.wsdl.QName;
  /**
   * This factory creates Type objects for the types supported by the WSDL2Java emitter.
   * The factory creates the Types by analyzing the XML Document.  The Type encapsulates
   * the QName, Java Name and defining Node for each Type. 
   *
   * @author Rich Scheuerle  (scheu@us.ibm.com)
   */
  public class TypeFactory {
  
      private HashMap types;                  // All Types        
      private HashMap mapNamespaceToPackage;  // Mapping from Namespace to Java Package 
  
      /**
       * Create an Emit Type Factory
       */
      public TypeFactory() { 
          types = new HashMap();
          mapNamespaceToPackage = new HashMap();
      }
  
      /**
       * Invoke this method to associate a namespace URI with a particular Java Package
       */
      public void map (String namespace, String pkg) {
          mapNamespaceToPackage.put(namespace, pkg);
      } 
  
      /**
       * Invoke this method from the Emitter prior to emitting any code.
       * All of the supported Types are identified and placed in the types HashMap.
       */
      public void buildTypes(Document doc) {
          addTypes(doc, false);
      }
  
      /**
       * Access all of the emit types.                                      
       */
      public HashMap getTypes() {
          return types;
      }
  
      /**
       * Get the Type for the given QName                               
       */
      public Type getType(QName qName) {
          return (Type) types.get(qName);
      }
  
      /**     
       * Dump Types for debugging                                       
       */
      public void dump() {
          Iterator i = types.values().iterator();
          while (i.hasNext()) {
              Type et = (Type) i.next();
              System.out.println("");
              System.out.println("QName: " + et.getQName());
              System.out.println("JName: " + et.getJavaName());
              if (et.getNode() != null) {
                  System.out.println("Node: " + et.getNode());
              }
          }
      }
  
      /**     
       * If the specified node represents a supported JAX-RPC complexType,
       * a Vector is returned which contains the child element types and
       * child element names.  The even indices are the element types (Types) and
       * the odd indices are the corresponding names (Strings).
       * If the specified node is not a supported JAX-RPC complexType,
       * null is returned.
       */
      public Vector getComplexElementTypesAndNames(Node node) {
          if (node == null) {
              return null;
          }
  
          // Get the node kind, expecting a schema complexType
          QName nodeKind = Utils.getNodeQName(node);
          if (nodeKind != null &&
              nodeKind.getLocalPart().equals("complexType") &&
              Utils.isSchemaNS(nodeKind.getNamespaceURI())) {
        
              // Under the complexType there should be a sequence or all group node.
              // (There may be other #text nodes, which we will ignore).  
              NodeList children = node.getChildNodes();
              Node groupNode = null;
              for (int j = 0; j < children.getLength() && groupNode == null; j++)
{
                  QName groupKind = Utils.getNodeQName(children.item(j));
                  if (groupKind != null &&
                      (groupKind.getLocalPart().equals("sequence") ||
                       groupKind.getLocalPart().equals("all")) &&
                      Utils.isSchemaNS(groupKind.getNamespaceURI())) 
                      groupNode = children.item(j);
              } 
        
              if (groupNode != null) {
  
                  // Process each of the element nodes under the group node
                  Vector v = new Vector();
                  NodeList elements = children.item(1).getChildNodes();
                  for (int i=0; i < elements.getLength(); i++) {
                      QName elementKind = Utils.getNodeQName(elements.item(i));
                      if (elementKind != null &&
                          elementKind.getLocalPart().equals("element") &&
                          Utils.isSchemaNS(elementKind.getNamespaceURI())) {
                
                          // Get the name and type qnames.
                          // The name of the element is the local part of the name's qname.
                          // The type qname is used to locate the Type, which is then
                          // used to retrieve the proper java name of the type.
                          Node elementNode = elements.item(i);
                          QName nodeName = Utils.getNodeNameQName(elementNode);
                          QName nodeType = Utils.getNodeTypeQName(elementNode);
                          if (nodeType == null) { // The element may use an anonymous type
                              nodeType = nodeName;
                          }
          
                          Type Type = (Type) types.get(nodeType);
                          if (Type != null) {
                              v.add(Type);
                              v.add(nodeName.getLocalPart());
                          }
                      }
                  }
                  return v;
              }
          }
          return null;
      } 
  
      /**     
       * If the specified node represents a supported JAX-RPC enumeration,
       * a Vector is returned which contains the base type and the enumeration values.
       * The first element in the vector is the base type (an Type). 
       * Subsequent elements are values (Strings).
       * If this is not an enumeration, null is returned.
       */
      public Vector getEnumerationBaseAndValues(Node node) {
          if (node == null) {
              return null;
          }
  
          // Get the node kind, expecting a schema simpleType
          QName nodeKind = Utils.getNodeQName(node);
          if (nodeKind != null &&
              nodeKind.getLocalPart().equals("simpleType") &&
              Utils.isSchemaNS(nodeKind.getNamespaceURI())) {
        
              // Under the simpleType there should be a restriction.
              // (There may be other #text nodes, which we will ignore).  
              NodeList children = node.getChildNodes();
              Node restrictionNode = null;
              for (int j = 0; j < children.getLength() && restrictionNode == null;
j++) {
                  QName restrictionKind = Utils.getNodeQName(children.item(j));
                  if (restrictionKind != null &&
                      restrictionKind.getLocalPart().equals("restriction") &&
                      Utils.isSchemaNS(restrictionKind.getNamespaceURI())) 
                      restrictionNode = children.item(j);
              } 
        
              // The restriction node indicates the type being restricted 
              // (the base attribute contains this type).
              // The base type must be a built-in type...and we only think
              // this makes sense for string.
              Type baseEType = null;
              if (restrictionNode != null) {
                  QName baseType = Utils.getNodeTypeQName(restrictionNode, "base");
                  baseEType = getType(baseType);
                  if (baseEType != null && baseEType.getBaseType() == null &&
                      baseEType.getJavaLocalName().equals("String")) {
                      baseEType = null;
                  }
              }
  
              // Process the enumeration elements underneath the restriction node
              if (baseEType != null) {
  
                  Vector v = new Vector();
                  v.add(baseEType);
                  NodeList enums = children.item(1).getChildNodes();
                  for (int i=0; i < enums.getLength(); i++) {
                      QName enumKind = Utils.getNodeQName(enums.item(i));
                      if (enumKind != null &&
                          enumKind.getLocalPart().equals("enumeration") &&
                          Utils.isSchemaNS(enumKind.getNamespaceURI())) {
                
                          // Put the enum value in the vector.
                          Node enumNode = enums.item(i);
                          String value = Utils.getAttribute(enumNode, "value");
                          if (value != null) {
                              v.add(value);
                          }
                      }
                  }
                  return v;
              }
          }
          return null;
      } 
  
      /**
       * Utility method which walks the Document and creates Types.
       * The inner parameter indicates that we are nested inside a complexType
       * (which is the only context where we need to investigate elements).
       */
      private void addTypes(Node node, boolean inner) {
          if (node == null) {
              return;
          }
          // Get the kind of node (complexType, wsdl:part, etc.)
          QName nodeKind = Utils.getNodeQName(node);
  
          
          if (nodeKind != null) {
              if (nodeKind.getLocalPart().equals("complexType") &&
                  Utils.isSchemaNS(nodeKind.getNamespaceURI())) {
          
                  // This is a definition of a complex type.
                  // create the type and indicate within complexType
                  createTypeFromDef(node);
                  inner = true;  
              } 
              if (nodeKind.getLocalPart().equals("simpleType") &&
                  Utils.isSchemaNS(nodeKind.getNamespaceURI())) {
          
                  // This is a definition of a simple type, which could be an enum
                  // Create the type.
                  createTypeFromDef(node);
              } 
              else if (nodeKind.getLocalPart().equals("element") &&
                     Utils.isSchemaNS(nodeKind.getNamespaceURI())) {
          
                  // This is an element.  Currently we only process the
                  // elements that are inside a complex type.  This may need
                  // to be changed if we ever support "ref" attributes.
                  // If the type is specified, create an Type from the
                  // reference.  Otherwise this is an anonymous type which
                  // will be picked up as we proceed further down the tree.
                  if (inner) {
                      if (Utils.getAttribute(node, "type") != null) {
                          createTypeFromRef(node);
                      }
                  }
              }
              else if (nodeKind.getLocalPart().equals("part") &&
                       Utils.isWsdlNS(nodeKind.getNamespaceURI())) {
          
                  // This is a wsdl part.  Create an Type from the reference
                  createTypeFromRef(node);
              }  
          } 
          // Recurse through children nodes    
          NodeList children = node.getChildNodes();
          for (int i = 0; i < children.getLength(); i++) {
              addTypes(children.item(i), inner);
          }
      }
  
      /**
       * Create an Type from the indicated node, which defines a supported type.
       */
      private void createTypeFromDef(Node node) {
          // Get the QName of the node's name attribute value
          QName qName = Utils.getNodeNameQName(node);
          if (qName != null) {
              String javaName = getJavaName(qName);
              // Since this is a defining context, force this Type into the 
              // hash map and supply the defining node.
              types.put(qName, new Type(qName, javaName, node));
          }
      }
  
      /**
       * Create an Type from the indicated node, which references a supported type.
       */
      private void createTypeFromRef(Node node) {
          // Get the QName of the node's type attribute value
          QName qName = Utils.getNodeTypeQName(node); 
          if (qName != null) {
              String javaName = getJavaName(qName);
              // An Type for this type may already have been encountered 
              // via another reference or defining context.  Also note that if 
              // the Type represents a Base type, the Type will change
              // java name to the appropriate java base name.
              if (types.get(qName) == null) {
                  types.put(qName, new Type(qName, javaName, null));
              }
          }
      }
  
  
      /**     
       * Get the Package name for the specified namespace                   
       */
      private String getPackage(String namespace) {
          return (String) mapNamespaceToPackage.get(namespace);
      }
  
      /**     
       * Get the Package name for the specified QName                       
       */
      private String getPackage(QName qName) {
          return getPackage(qName.getNamespaceURI());
      }
  
      /**     
       * Convert the specified QName into a full Java Name.                 
       */
      private String getJavaName(QName qName) {
          String javaName = Utils.getJavaName(qName.getLocalPart());                     

          String pkg = getPackage(qName.getNamespaceURI());
          String fullJavaName = javaName;
          if (pkg != null) {
             fullJavaName = pkg + "." + javaName;
          }
          return fullJavaName;
      }
  
  }
  
  
  
  
  
  
  
  
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/Type.java
  
  Index: Type.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * 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;
  
  
  import org.w3c.dom.Attr;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  import javax.wsdl.QName;
  
  /**
   * This class represents a type that is supported by the WSDL2Java emitter.
   * A Type has a QName representing its XML name and a Java Name, which
   * is its full java name.  The Type may also have a Node, which locates
   * the definition of the emit type in the xml.  
   * An Type is created by the TypeFactory object.
   *
   * @author Rich Scheuerle  (scheu@us.ibm.com)
   */
  public class Type {
  
      private QName  qName;        // QName of the element type
      private String jName;        // Name of the Java Mapping (Class or primitive)
      private Node   node;         // Element node  
      private boolean isBaseType;  // Indicates if represented by a java primitive or util
class
  
      /**
       * Create an Emit Type with 
       */
      public Type(QName pqName, String pjName, Node pnode) {
          qName = pqName;
          node  = pnode;
          // If the qName represents a base type, we override the 
          // java name with the name of the base java name.
          jName = initBaseType();
          if (jName == null) {
              jName = pjName;
              isBaseType = false;
          } else {
              isBaseType = true;
          }
      }
  
      /**
       * Query QName
       */
      public QName getQName() {
          return qName;
      }
  
      /**
       * Query Java Mapping Name
       */
      public String getJavaName() {
          return jName;
      }
  
      /**
       * Query Java Local Name
       */
      public String getJavaLocalName() {
          return jName.substring(jName.lastIndexOf('.')+1);
      }
  
      /**
       * Query Java Package Name
       */
      public String getJavaPackageName() {
          if (jName.lastIndexOf('.') > 0) {
              return jName.substring(0, jName.lastIndexOf('.'));
          }
          else {
              return "";
          }
      }
  
      /**
       * Query Java Mapping Name
       */
      public Node getNode() {
          return node;
      }
  
      /**
       * Query whether a Node defining the type exists.
       */
      public boolean isDefined() {
          return (node != null);
      }
  
      /**
       * Returns the Java Base Type Name.
       * For example if the Type represents a schema integer, "int" is returned.
       * If this is a user defined type, null is returned.
       */
      public String getBaseType() {
          if (isBaseType) {
              return jName;
          }
          else {
              return null;
          }
      }
  
      /**
       * Private method which returns the appropriate java type for each base type supported.
       */
      private String initBaseType() {
          String localName = qName.getLocalPart();
          if (Utils.isSchemaNS(qName.getNamespaceURI())) {
              if (localName.equals("string"))
                  return "java.lang.String";
              else if (localName.equals("integer"))
                  return "int";
              else if (localName.equals("int"))
                  return "int";
              else if (localName.equals("long"))
                  return "long";
              else if (localName.equals("short"))
                  return "short";
              else if (localName.equals("decimal"))
                  return "java.math.BigDecimal";
              else if (localName.equals("float"))
                  return "float";
              else if (localName.equals("double"))
                  return "double";
              else if (localName.equals("boolean"))
                  return "boolean";
              else if (localName.equals("byte"))
                  return "byte";
              else if (localName.equals("QName"))
                  return "org.apache.axis.rpc.namespace.QName";
              else if (localName.equals("dateTime"))
                  return "java.util.Date";
              else if (localName.equals("base64Binary"))
                  return "byte[]";
              else if (localName.equals("date"))
                  return "java.util.Date";
              else if (localName.equals("void"))
                  return "void";
          }
          else if (Utils.isSoapEncodingNS(qName.getNamespaceURI())) {
              if (localName.equals("string"))
                  return "java.lang.String";
              else if (localName.equals("int"))
                  return "int";
              else if (localName.equals("short"))
                  return "short";
              else if (localName.equals("decimal"))
                  return "java.math.BigDecimal";
              else if (localName.equals("float"))
                  return "float";
              else if (localName.equals("double"))
                  return "double";
              else if (localName.equals("boolean"))
                  return "boolean";
          }
          return null;
      }
  }
  
  
  
  
  
  
  

Mime
View raw message