You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by na...@apache.org on 2008/08/20 04:02:55 UTC

svn commit: r687222 - in /webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws: WSDL2Ws.java info/WSDLInfo.java

Author: nadiramra
Date: Tue Aug 19 19:02:54 2008
New Revision: 687222

URL: http://svn.apache.org/viewvc?rev=687222&view=rev
Log:
Refactor to put code in proper classes.

Modified:
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java

Modified: webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java?rev=687222&r1=687221&r2=687222&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java (original)
+++ webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java Tue Aug 19 19:02:54 2008
@@ -24,7 +24,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Vector;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
@@ -36,19 +35,11 @@
 import javax.wsdl.PortType;
 import javax.wsdl.Service;
 import javax.xml.namespace.QName;
-import javax.xml.rpc.holders.IntHolder;
-
-// hold off until we use 1.4 or newer axis.jar.
-//import org.apache.axis.constants.Style;
 
 import org.apache.axis.wsdl.symbolTable.BaseType;
 import org.apache.axis.wsdl.symbolTable.BindingEntry;
 import org.apache.axis.wsdl.symbolTable.CElementDecl;
-import org.apache.axis.wsdl.symbolTable.CSchemaUtils;
 import org.apache.axis.wsdl.symbolTable.CContainedAttribute;
-import org.apache.axis.wsdl.symbolTable.CollectionElement;
-import org.apache.axis.wsdl.symbolTable.CollectionType;
-import org.apache.axis.wsdl.symbolTable.DefinedElement;
 import org.apache.axis.wsdl.symbolTable.DefinedType;
 import org.apache.axis.wsdl.symbolTable.Element;
 import org.apache.axis.wsdl.symbolTable.Parameters;
@@ -63,7 +54,6 @@
 import org.apache.axis.wsdl.wsdl2ws.info.WSDLInfo;
 import org.apache.axis.wsdl.wsdl2ws.info.WebServiceContext;
 import org.apache.axis.wsdl.wsdl2ws.info.WrapperInfo;
-import org.w3c.dom.Node;
 
 /**
  * This is the main class for the WSDL2Ws Tool. This class reuses the code in the 
@@ -243,23 +233,7 @@
         // Generate types, populating the type map
         // ==================================================            
         
-        c_typeMap = new TypeMap();
-        
-        Iterator it = c_symbolTable.getTypeIndex().values().iterator();
-        while (it.hasNext())
-        {
-            TypeEntry type = (TypeEntry) it.next();
-            Node node = type.getNode();
-            if (node != null)
-            {
-                if (c_verbose)
-                {
-                    System.out.println( "==>getTypeInfo: Processing type...." + type.getQName());                    
-                }
-                                
-                createTypeInfo(type);
-            }
-        }
+        c_typeMap = c_wsdlInfo.generateTypeMap();
         
         // ==================================================
         // Get service, ports, binding, and port type
@@ -320,7 +294,7 @@
         {
             System.out.println( "Dumping typeMap....");
             
-            it = c_typeMap.getTypes().iterator();
+            Iterator it = c_typeMap.getTypes().iterator();
             while (it.hasNext())
             {
                 System.out.println(it.next());
@@ -789,283 +763,6 @@
         }
     }
 
-
-    /**
-     * Iterates through symbol table, creating types in the typemap.
-     * 
-     * @param typename
-     * @return
-     * @throws WrapperFault
-     */
-    private Type createTypeInfo(QName typename)  throws WrapperFault
-    {
-        TypeEntry type = c_symbolTable.getType(typename);
-        if (type == null)
-        {
-            type = c_symbolTable.getElement(typename);
-            if (type == null)
-            {
-                throw new WrapperFault(
-                    "["
-                        + typename
-                        + "]unexpected condition occurred "
-                        + ".. please inform the axis-dev@apache.org mailing list ASAP");
-            }
-        }
-        return createTypeInfo(type);
-    }
-    
-    /**
-     * Creates a type map entry from a symbol table typeentry. 
-     * 
-     * @param type
-     * @return
-     * @throws WrapperFault
-     */
-    private Type createTypeInfo(TypeEntry type) throws WrapperFault
-    {
-        Type typedata = null;
-        Type newSecondaryType = null;
-        
-        // Do not add types which are not used in the WSDL
-        if (!type.isReferenced())
-            return null;
-        
-        if (c_verbose && !CUtils.isPrimitiveBasicType(type.getQName()))
-            System.out.println("Attempting to create type: " + type.getQName());
-        
-        if (type instanceof CollectionElement)
-        { //an array
-        }
-        else if (type instanceof DefinedElement)
-        { 
-            // if element references another type, process the referenced type
-            if (type.getRefType() != null)
-            {
-                if (c_verbose)
-                    System.out.println("Attempting to create new type from element-ref: " + type.getRefType().getQName());
-                
-                return createTypeInfo(type.getRefType());
-            }
-
-            return null;
-        }
-        
-        if (-1 != type.getQName().getLocalPart().indexOf('['))
-        { 
-            /* it seems that this is an array */
-            if (null == type.getRefType())
-                throw new WrapperFault("Array type found without a Ref type");
-            
-            QName qn = type.getRefType().getQName();
-            if (null == qn)
-                throw new WrapperFault("Array type found without a Ref type");
-            
-            if (CUtils.isBasicType(qn))
-                return null;
-            
-            QName newqn = new QName(type.getQName().getNamespaceURI(), qn.getLocalPart() + "_Array");
-            // type is a inbuilt type or a already created type?
-            typedata = c_typeMap.getType(newqn);
-            if (typedata != null)
-            {
-                if (c_verbose && !CUtils.isPrimitiveBasicType(type.getQName()))
-                    System.out.println("Type not created, already exists: " + type.getQName());
-                
-                return typedata;
-            }            
-            
-            typedata = new Type(newqn, newqn.getLocalPart());
-            
-            if (type.getRefType().getRefType() != null)
-                typedata.setElementType(type.getRefType().getRefType().getQName().getLocalPart());
-            else
-                typedata.setElementType(type.getRefType().getQName().getLocalPart());     
-        }
-        else
-        {
-            // type is a inbuilt type or a already created type?
-            typedata = c_typeMap.getType(type.getQName());
-            if (typedata != null)
-            {
-                if (c_verbose && !CUtils.isPrimitiveBasicType(type.getQName()))
-                    System.out.println("Type not created, already exists: " + type.getQName());
-                
-                return typedata;
-            }
-            
-            typedata = new Type(type.getQName(), type.getQName().getLocalPart());
-        }
-        
-        // Add type to type map
-        if (c_verbose)
-            System.out.println("Created new type: " + typedata.getName());
-        
-        c_typeMap.addType(typedata.getName(), typedata);
-        
-        // work out whether this type will be generated or not 
-        typedata.externalize(isTypeGenerated(type, typedata));
-
-        Node node = type.getNode();
-
-        if (type.isSimpleType())
-        {
-            //check for extended types
-            TypeEntry base = CSchemaUtils.getComplexElementExtensionBase(type.getNode(), c_symbolTable);
-            if (base != null)
-            {
-                String localpart = type.getQName().getLocalPart() + "_value";
-                QName typeName =  new QName(type.getQName().getNamespaceURI(), localpart);
-                newSecondaryType = createTypeInfo(base.getQName());
-                typedata.addRelatedType(newSecondaryType);
-                typedata.setExtensionBaseType(new CElementDecl(newSecondaryType, typeName));
-                if (c_verbose)
-                    System.out.print(
-                        "=====complexType with simpleContent is found : "
-                            + type.getQName().getLocalPart() + "=====\n");
-            }
-            else
-                c_wsdlInfo.setRestrictionBaseAndValues(typedata, node);
-            
-            // There can be attributes in this extended basic type
-            Vector attributes = CSchemaUtils.getContainedAttributeTypes(type.getNode(), c_symbolTable);
-            if (attributes != null)
-            {
-                for (int j = 0; j < attributes.size(); j++)
-                {
-                    CContainedAttribute attr = (CContainedAttribute)attributes.get(j);
-                    newSecondaryType = createTypeInfo(attr.getTypeEntry().getQName());
-                    attr.setType(newSecondaryType);
-                    typedata.addRelatedType(newSecondaryType);
-                }
-                typedata.addAttributes(attributes);
-            }
-        }
-        else if (type instanceof CollectionType)
-        {
-            newSecondaryType = createTypeInfo(type.getRefType().getQName());
-            typedata.addRelatedType(newSecondaryType);
-            typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, type.getQName()));
-            typedata.setArray(true);
-        }
-        else
-        {
-            //is this a SOAPEnc array type    
-            QName arrayType = CSchemaUtils.getArrayComponentQName(node,new IntHolder(0),c_symbolTable);
-            if (arrayType != null)
-            {
-                newSecondaryType = createTypeInfo(arrayType);
-                typedata.addRelatedType(newSecondaryType);
-                typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, new QName("item")));
-                typedata.setArray(true);
-            }
-            else if ((arrayType = CSchemaUtils.getCollectionComponentQName(node)) != null)
-            {
-                newSecondaryType = createTypeInfo(arrayType);
-                typedata.addRelatedType(newSecondaryType);
-                typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, new QName("item")));
-                typedata.setArray(true);
-            }
-            //Note in a array the parameter type is stored as under the name item all the time  
-            else
-            {
-                // get all extended types
-                Vector extendList = new Vector();
-                extendList.add(type);
-                
-                TypeEntry parent = CSchemaUtils.getComplexElementExtensionBase(type.getNode(), c_symbolTable);
-                while (parent != null)
-                {
-                    extendList.add(parent);
-                    parent = CSchemaUtils.getComplexElementExtensionBase(parent.getNode(), c_symbolTable);
-                }
-
-                // Now generate a list of names and types starting with
-                // the oldest parent.  (Attrs are considered before elements).
-                for (int i = extendList.size() - 1; i >= 0; i--)
-                {
-                    TypeEntry te = (TypeEntry) extendList.elementAt(i);
-
-                    //TODO the code require the attributes name at extension base types
-                    //different, the WSDL2Ws do not support it having same name at up and below.
-
-                    // Process the attributes
-                    if (c_verbose)
-                        System.out.println("Processing attributes for type: " + type.getQName());
-
-                    // TODO Need to handle whether attributes are qualified?
-                    Vector attributes = CSchemaUtils.getContainedAttributeTypes(te.getNode(), c_symbolTable);
-                    if (attributes != null)
-                    {
-                        for (int j = 0; j < attributes.size(); j++)
-                        {
-                            CContainedAttribute attr = (CContainedAttribute)attributes.get(j);
-                            newSecondaryType = createTypeInfo(attr.getTypeEntry().getQName());
-                            attr.setType(newSecondaryType);
-                            typedata.addRelatedType(newSecondaryType);
-                        }
-                        typedata.addAttributes(attributes);
-                    }                        
-                    
-                    // Process the elements
-                    if (c_verbose)
-                        System.out.println("Processing elements for type: " + type.getQName());
-                    
-                    Vector elements =  CSchemaUtils.getContainedElementDeclarations(te.getNode(), c_symbolTable);
-                    if (elements != null)
-                    {
-                        // The following will get elementFormDefault for the schema the element is in.
-                        boolean nsQualifyElementDefault = CSchemaUtils.isElementFormDefaultQualified(te.getNode());
-                        
-                        // Now process the elements.
-                        for (int j = 0; j < elements.size(); j++)
-                        {   
-                            CElementDecl elem = (CElementDecl) elements.get(j);
-                            
-                            // Set whether to namespace qualify or not. We only process if not set.
-                            if (!elem.getNsQualified())
-                            {
-                                boolean nsQualifyElement = 
-                                    CSchemaUtils.shouldWeNamespaceQualifyNode(elem.getTypeEntry().getNode(), 
-                                                                              nsQualifyElementDefault);
-                                elem.setNsQualified(nsQualifyElement);
-                            }
-                            
-                            if (elem.getAnyElement())
-                            {
-                                newSecondaryType =  new Type(CUtils.anyTypeQname, CUtils.anyTypeQname.getLocalPart());
-                            }
-                            else
-                            {
-                                QName typeName = elem.getTypeEntry().getQName();
-                                if (typeName.getLocalPart().indexOf('[') > 0)
-                                {
-                                    String localpart =
-                                        typeName.getLocalPart().substring(0, typeName.getLocalPart().indexOf('['));
-                                    
-                                    typeName = new QName(typeName.getNamespaceURI(), localpart);
-                                    
-                                    if (CUtils.isBasicType(typeName))
-                                        newSecondaryType = createTypeInfo(typeName);
-                                    else
-                                        newSecondaryType = createTypeInfo(elem.getTypeEntry());
-                                }
-                                else
-                                    newSecondaryType = createTypeInfo(typeName);
-                            }
-                            
-                            typedata.addRelatedType(newSecondaryType);
-                            elem.setType(newSecondaryType);
-                                                       
-                            typedata.setTypeNameForElementName(elem);
-                        }
-                    }
-                } // for-loop
-            }
-        }
-        return typedata;
-    }
-
     /**
      * Adds faults.
      * 
@@ -1390,30 +1087,6 @@
     }
 
     /**
-     * Work out the various conditions that dictate whether this type will be generated into a new
-     * file or not.
-     * This method is only very partially implemented. 
-     *   
-     * @param type
-     * @param typedata
-     * @return true if the type will not be generated. False otherwise
-     */
-    private boolean isTypeGenerated(TypeEntry type, Type typedata)
-    {
-        // If the referenced type is actually a type that will not get generated because it's
-        //     a base type array then tell other people of this case. Do this to two levels of indirection
-        
-        if(type.getRefType()!=null)
-            if(type.getRefType().getRefType()!=null && type.getRefType().getRefType().isBaseType())
-                return false;
-            
-        if (typedata.isAnonymous())
-            return false;
-        else
-            return true;
-    }
-    
-    /**
      * Resolves name conflict between a method name and a type name. 
      * When doing document-literal, usually the name of the wrapper element is same as the 
      * operation name. 

Modified: webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java?rev=687222&r1=687221&r2=687222&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java (original)
+++ webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java Tue Aug 19 19:02:54 2008
@@ -34,11 +34,17 @@
 import javax.wsdl.extensions.soap.SOAPAddress;
 import javax.xml.namespace.QName;
 import javax.xml.rpc.holders.BooleanHolder;
+import javax.xml.rpc.holders.IntHolder;
 
 import org.apache.axis.Constants;
 import org.apache.axis.wsdl.gen.Parser;
 import org.apache.axis.wsdl.symbolTable.BindingEntry;
+import org.apache.axis.wsdl.symbolTable.CContainedAttribute;
+import org.apache.axis.wsdl.symbolTable.CElementDecl;
 import org.apache.axis.wsdl.symbolTable.CSchemaUtils;
+import org.apache.axis.wsdl.symbolTable.CollectionElement;
+import org.apache.axis.wsdl.symbolTable.CollectionType;
+import org.apache.axis.wsdl.symbolTable.DefinedElement;
 import org.apache.axis.wsdl.symbolTable.SchemaUtils;
 import org.apache.axis.wsdl.symbolTable.ServiceEntry;
 import org.apache.axis.wsdl.symbolTable.SymTabEntry;
@@ -310,6 +316,433 @@
     }
 
     /**
+     * Iterates through the symbol table, generating user-defined types and
+     * storing the types in a hash table.
+     * 
+     * @return
+     * @throws WrapperFault
+     */
+    public TypeMap generateTypeMap() throws WrapperFault
+    {
+        TypeMap typeMap = new TypeMap();
+        if (c_symbolTable ==  null)
+            return typeMap;
+        
+        Iterator it = c_symbolTable.getTypeIndex().values().iterator();
+        while (it.hasNext())
+        {
+            TypeEntry type = (TypeEntry) it.next();
+            Node node = type.getNode();
+            if (node != null)
+            {
+                if (c_verbose)
+                {
+                    System.out.println( "==>getTypeInfo: Processing type...." + type.getQName());                    
+                }
+                                
+                createTypeInfo(type, typeMap);
+            }
+        }
+        
+        return typeMap;
+    }
+  
+    
+    /**
+     * Returns list of Port objects in a service definition based on selection criteria.
+     * 
+     * @param s              service definition.
+     * @param styleDocument  true=return document style; false=return "rpc" style. 
+     *                       This parameter is ignored for REST (HTTP) bindings.
+     * @param soap11         true=return SOAP 1.1 bindings; false=SOAP 1.1 bindings are ignored.
+     * @param soap12         true=return SOAP 1.2 bindings; false=SOAP 1.2 bindings are ignored.
+     * @param rest           true=return HTTP bindings; false=ignore HTTP bindings.
+     * @return               List of ports that match selection criteria.
+     * @throws Exception
+     */
+    private ArrayList getServicePorts(Service s, 
+                                      boolean styleDocument, 
+                                      boolean soap11, 
+                                      boolean soap12, 
+                                      boolean rest) throws Exception
+    {        
+        ArrayList a = new ArrayList();
+        
+        if (s == null)
+            return a;
+
+        Iterator ports = s.getPorts().values().iterator();
+        while (ports.hasNext())
+        {
+            Port p = (Port) ports.next();
+            Binding b = p.getBinding();
+            BindingEntry be = c_symbolTable.getBindingEntry(b.getQName());
+            if (b == null || be == null)
+                throw new WrapperFault("No binding exists for port '" + p.getName() + "'.");
+            
+            if ((be.getBindingType() == BindingEntry.TYPE_SOAP) && (soap11 || soap12))
+            {
+                String style = be.getBindingStyle().getName();
+                if (style == null)
+                    style = "rpc"; // TODO need to revisit.
+                
+                if ((styleDocument && style.equalsIgnoreCase("document"))
+                        || (!styleDocument && style.equalsIgnoreCase("rpc")))
+                {
+                    String ns = Constants.URI_WSDL11_SOAP;
+                    SOAPBinding soapbinding = (SOAPBinding)getExtensibilityElement(b, INSTANCEOF_SOAPBINDING);
+                    if (soapbinding != null && null != soapbinding.getElementType().getNamespaceURI())
+                        ns = soapbinding.getElementType().getNamespaceURI();
+                        
+                    if ((soap11 && ns.equals(Constants.URI_WSDL11_SOAP))
+                            || (soap12 && ns.equals(Constants.URI_WSDL12_SOAP)))
+                            a.add(p);
+                }
+            }
+            else if (rest && (be.getBindingType() == BindingEntry.TYPE_HTTP_GET 
+                                || be.getBindingType() == BindingEntry.TYPE_HTTP_POST))
+            {
+                a.add(p);
+            }
+        }
+        
+        return a;
+    }
+    
+    /**
+     * Collects all the information by the wsdl2ws tool.
+     */
+    private void processWSDLDocument() throws Exception
+    {        
+        // Get target name space of WSDL
+        c_targetNameSpaceOfWSDL = c_symbolTable.getDefinition().getTargetNamespace();
+
+        // Collect services and bindings.           
+        Iterator it = c_symbolTable.getHashMap().values().iterator();
+        while (it.hasNext())
+        {
+            Vector v = (Vector) it.next();
+            for (int i = 0; i < v.size(); ++i)
+            {
+                SymTabEntry entry = (SymTabEntry) v.elementAt(i);
+
+                if (entry instanceof org.apache.axis.wsdl.symbolTable.ServiceEntry)
+                    c_services.add(((ServiceEntry) entry).getService());
+                else if (entry instanceof org.apache.axis.wsdl.symbolTable.BindingEntry)
+                    c_bindings.add(entry);
+            }
+        }
+    }
+    
+    /**
+     * Helper function that returns requested extensibility element.
+     * 
+     * @param e element to retrieve extensibility elements from.
+     * @param clazz instance of class
+     * @return extensibility element.
+     */
+    private static Object getExtensibilityElement(WSDLElement e, int clazz)
+    {
+        if (e != null)
+        {
+            List extElems = e.getExtensibilityElements();
+            if (extElems != null)
+            {
+                Iterator it = extElems.iterator();
+                
+                while (it.hasNext())
+                {
+                    Object o = it.next();
+                    if ((clazz == INSTANCEOF_SOAPBINDING && (o instanceof javax.wsdl.extensions.soap.SOAPBinding))
+                       || (clazz == INSTANCEOF_SOAPADDRESS && (o instanceof javax.wsdl.extensions.soap.SOAPAddress))
+                       || (clazz == INSTANCEOF_SOAPOPERATION && (o instanceof javax.wsdl.extensions.soap.SOAPOperation))
+                       || (clazz == INSTANCEOF_SOAPBODY && (o instanceof javax.wsdl.extensions.soap.SOAPBody)))
+                        return o;
+                }
+            }
+        }
+        
+        return null;
+    }
+    
+
+    /**
+     * Generate a type for the specified QName.
+     * 
+     * @param typename
+     * @return
+     * @throws WrapperFault
+     */
+    private Type createTypeInfo(QName typename, TypeMap typeMap)  throws WrapperFault
+    {
+        TypeEntry type = c_symbolTable.getType(typename);
+        if (type == null)
+        {
+            type = c_symbolTable.getElement(typename);
+            if (type == null)
+            {
+                throw new WrapperFault(
+                    "["
+                        + typename
+                        + "]unexpected condition occurred "
+                        + ".. please inform the axis-dev@apache.org mailing list ASAP");
+            }
+        }
+        return createTypeInfo(type, typeMap);
+    }
+    
+    /**
+     * Creates a type map entry from a symbol table typeentry. 
+     * 
+     * @param type
+     * @return
+     * @throws WrapperFault
+     */
+    private Type createTypeInfo(TypeEntry type, TypeMap typeMap) throws WrapperFault
+    {
+        Type typedata = null;
+        Type newSecondaryType = null;
+        
+        // Do not add types which are not used in the WSDL
+        if (!type.isReferenced())
+            return null;
+        
+        if (c_verbose && !CUtils.isPrimitiveBasicType(type.getQName()))
+            System.out.println("Attempting to create type: " + type.getQName());
+        
+        if (type instanceof CollectionElement)
+        { //an array
+        }
+        else if (type instanceof DefinedElement)
+        { 
+            // if element references another type, process the referenced type
+            if (type.getRefType() != null)
+            {
+                if (c_verbose)
+                    System.out.println("Attempting to create new type from element-ref: " + type.getRefType().getQName());
+                
+                return createTypeInfo(type.getRefType(), typeMap);
+            }
+
+            return null;
+        }
+        
+        if (-1 != type.getQName().getLocalPart().indexOf('['))
+        { 
+            /* it seems that this is an array */
+            if (null == type.getRefType())
+                throw new WrapperFault("Array type found without a Ref type");
+            
+            QName qn = type.getRefType().getQName();
+            if (null == qn)
+                throw new WrapperFault("Array type found without a Ref type");
+            
+            if (CUtils.isBasicType(qn))
+                return null;
+            
+            QName newqn = new QName(type.getQName().getNamespaceURI(), qn.getLocalPart() + "_Array");
+            // type is a inbuilt type or a already created type?
+            typedata = typeMap.getType(newqn);
+            if (typedata != null)
+            {
+                if (c_verbose && !CUtils.isPrimitiveBasicType(type.getQName()))
+                    System.out.println("Type not created, already exists: " + type.getQName());
+                
+                return typedata;
+            }            
+            
+            typedata = new Type(newqn, newqn.getLocalPart());
+            
+            if (type.getRefType().getRefType() != null)
+                typedata.setElementType(type.getRefType().getRefType().getQName().getLocalPart());
+            else
+                typedata.setElementType(type.getRefType().getQName().getLocalPart());     
+        }
+        else
+        {
+            // type is a inbuilt type or a already created type?
+            typedata = typeMap.getType(type.getQName());
+            if (typedata != null)
+            {
+                if (c_verbose && !CUtils.isPrimitiveBasicType(type.getQName()))
+                    System.out.println("Type not created, already exists: " + type.getQName());
+                
+                return typedata;
+            }
+            
+            typedata = new Type(type.getQName(), type.getQName().getLocalPart());
+        }
+        
+        // Add type to type map
+        if (c_verbose)
+            System.out.println("Created new type: " + typedata.getName());
+        
+        typeMap.addType(typedata.getName(), typedata);
+        
+        // TODO revisit...work out whether this type will be generated or not 
+        typedata.externalize(isTypeGenerated(type, typedata));
+
+        Node node = type.getNode();
+
+        if (type.isSimpleType())
+        {
+            //check for extended types
+            TypeEntry base = CSchemaUtils.getComplexElementExtensionBase(type.getNode(), c_symbolTable);
+            if (base != null)
+            {
+                String localpart = type.getQName().getLocalPart() + "_value";
+                QName typeName =  new QName(type.getQName().getNamespaceURI(), localpart);
+                newSecondaryType = createTypeInfo(base.getQName(), typeMap);
+                typedata.addRelatedType(newSecondaryType);
+                typedata.setExtensionBaseType(new CElementDecl(newSecondaryType, typeName));
+                if (c_verbose)
+                    System.out.print(
+                        "=====complexType with simpleContent is found : "
+                            + type.getQName().getLocalPart() + "=====\n");
+            }
+            else
+                setRestrictionBaseAndValues(typedata, node);
+            
+            // There can be attributes in this extended basic type
+            Vector attributes = CSchemaUtils.getContainedAttributeTypes(type.getNode(), c_symbolTable);
+            if (attributes != null)
+            {
+                for (int j = 0; j < attributes.size(); j++)
+                {
+                    CContainedAttribute attr = (CContainedAttribute)attributes.get(j);
+                    newSecondaryType = createTypeInfo(attr.getTypeEntry().getQName(), typeMap);
+                    attr.setType(newSecondaryType);
+                    typedata.addRelatedType(newSecondaryType);
+                }
+                typedata.addAttributes(attributes);
+            }
+        }
+        else if (type instanceof CollectionType)
+        {
+            newSecondaryType = createTypeInfo(type.getRefType().getQName(), typeMap);
+            typedata.addRelatedType(newSecondaryType);
+            typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, type.getQName()));
+            typedata.setArray(true);
+        }
+        else
+        {
+            //is this a SOAPEnc array type    
+            QName arrayType = CSchemaUtils.getArrayComponentQName(node,new IntHolder(0),c_symbolTable);
+            if (arrayType != null)
+            {
+                newSecondaryType = createTypeInfo(arrayType, typeMap);
+                typedata.addRelatedType(newSecondaryType);
+                typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, new QName("item")));
+                typedata.setArray(true);
+            }
+            else if ((arrayType = CSchemaUtils.getCollectionComponentQName(node)) != null)
+            {
+                newSecondaryType = createTypeInfo(arrayType, typeMap);
+                typedata.addRelatedType(newSecondaryType);
+                typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, new QName("item")));
+                typedata.setArray(true);
+            }
+            //Note in a array the parameter type is stored as under the name item all the time  
+            else
+            {
+                // get all extended types
+                Vector extendList = new Vector();
+                extendList.add(type);
+                
+                TypeEntry parent = CSchemaUtils.getComplexElementExtensionBase(type.getNode(), c_symbolTable);
+                while (parent != null)
+                {
+                    extendList.add(parent);
+                    parent = CSchemaUtils.getComplexElementExtensionBase(parent.getNode(), c_symbolTable);
+                }
+
+                // Now generate a list of names and types starting with
+                // the oldest parent.  (Attrs are considered before elements).
+                for (int i = extendList.size() - 1; i >= 0; i--)
+                {
+                    TypeEntry te = (TypeEntry) extendList.elementAt(i);
+
+                    //TODO the code require the attributes name at extension base types
+                    //different, the WSDL2Ws do not support it having same name at up and below.
+
+                    // Process the attributes
+                    if (c_verbose)
+                        System.out.println("Processing attributes for type: " + type.getQName());
+
+                    // TODO Need to handle whether attributes are qualified?
+                    Vector attributes = CSchemaUtils.getContainedAttributeTypes(te.getNode(), c_symbolTable);
+                    if (attributes != null)
+                    {
+                        for (int j = 0; j < attributes.size(); j++)
+                        {
+                            CContainedAttribute attr = (CContainedAttribute)attributes.get(j);
+                            newSecondaryType = createTypeInfo(attr.getTypeEntry().getQName(), typeMap);
+                            attr.setType(newSecondaryType);
+                            typedata.addRelatedType(newSecondaryType);
+                        }
+                        typedata.addAttributes(attributes);
+                    }                        
+                    
+                    // Process the elements
+                    if (c_verbose)
+                        System.out.println("Processing elements for type: " + type.getQName());
+                    
+                    Vector elements =  CSchemaUtils.getContainedElementDeclarations(te.getNode(), c_symbolTable);
+                    if (elements != null)
+                    {
+                        // The following will get elementFormDefault for the schema the element is in.
+                        boolean nsQualifyElementDefault = CSchemaUtils.isElementFormDefaultQualified(te.getNode());
+                        
+                        // Now process the elements.
+                        for (int j = 0; j < elements.size(); j++)
+                        {   
+                            CElementDecl elem = (CElementDecl) elements.get(j);
+                            
+                            // Set whether to namespace qualify or not. We only process if not set.
+                            if (!elem.getNsQualified())
+                            {
+                                boolean nsQualifyElement = 
+                                    CSchemaUtils.shouldWeNamespaceQualifyNode(elem.getTypeEntry().getNode(), 
+                                                                              nsQualifyElementDefault);
+                                elem.setNsQualified(nsQualifyElement);
+                            }
+                            
+                            if (elem.getAnyElement())
+                            {
+                                newSecondaryType =  new Type(CUtils.anyTypeQname, CUtils.anyTypeQname.getLocalPart());
+                            }
+                            else
+                            {
+                                QName typeName = elem.getTypeEntry().getQName();
+                                if (typeName.getLocalPart().indexOf('[') > 0)
+                                {
+                                    String localpart =
+                                        typeName.getLocalPart().substring(0, typeName.getLocalPart().indexOf('['));
+                                    
+                                    typeName = new QName(typeName.getNamespaceURI(), localpart);
+                                    
+                                    if (CUtils.isBasicType(typeName))
+                                        newSecondaryType = createTypeInfo(typeName, typeMap);
+                                    else
+                                        newSecondaryType = createTypeInfo(elem.getTypeEntry(), typeMap);
+                                }
+                                else
+                                    newSecondaryType = createTypeInfo(typeName, typeMap);
+                            }
+                            
+                            typedata.addRelatedType(newSecondaryType);
+                            elem.setType(newSecondaryType);
+                                                       
+                            typedata.setTypeNameForElementName(elem);
+                        }
+                    }
+                } // for-loop
+            }
+        }
+        return typedata;
+    }    
+    
+    /**
      * If the specified node represents a supported JAX-RPC restriction,
      * a Vector is returned which contains the base type and the values (enumerations etc).
      * The first element in the vector is the base type (an TypeEntry).
@@ -317,7 +750,7 @@
      * NEEDS WORK - CURRENTLY THE ONLY THING WE DO IS GENERATE ENUMERATOR CONSTANTS AND CREATE
      * AN EMPTY RESTRICTOR FUNCTION WHEN DOING CODE GENERATION STEP.
      */
-    public void setRestrictionBaseAndValues(Type typedata, Node node) 
+    private void setRestrictionBaseAndValues(Type typedata, Node node) 
     {
         if (node == null)
             return;
@@ -515,122 +948,29 @@
             }
         }
         return;
-    }        
+    }      
     
     /**
-     * Returns list of Port objects in a service definition based on selection criteria.
-     * 
-     * @param s              service definition.
-     * @param styleDocument  true=return document style; false=return "rpc" style. 
-     *                       This parameter is ignored for REST (HTTP) bindings.
-     * @param soap11         true=return SOAP 1.1 bindings; false=SOAP 1.1 bindings are ignored.
-     * @param soap12         true=return SOAP 1.2 bindings; false=SOAP 1.2 bindings are ignored.
-     * @param rest           true=return HTTP bindings; false=ignore HTTP bindings.
-     * @return               List of ports that match selection criteria.
-     * @throws Exception
+     * Work out the various conditions that dictate whether this type will be generated into a new
+     * file or not.
+     * This method is only very partially implemented. 
+     *   
+     * @param type
+     * @param typedata
+     * @return true if the type will not be generated. False otherwise
      */
-    private ArrayList getServicePorts(Service s, 
-                                      boolean styleDocument, 
-                                      boolean soap11, 
-                                      boolean soap12, 
-                                      boolean rest) throws Exception
-    {        
-        ArrayList a = new ArrayList();
-        
-        if (s == null)
-            return a;
-
-        Iterator ports = s.getPorts().values().iterator();
-        while (ports.hasNext())
-        {
-            Port p = (Port) ports.next();
-            Binding b = p.getBinding();
-            BindingEntry be = c_symbolTable.getBindingEntry(b.getQName());
-            if (b == null || be == null)
-                throw new WrapperFault("No binding exists for port '" + p.getName() + "'.");
-            
-            if ((be.getBindingType() == BindingEntry.TYPE_SOAP) && (soap11 || soap12))
-            {
-                String style = be.getBindingStyle().getName();
-                if (style == null)
-                    style = "rpc"; // TODO need to revisit.
-                
-                if ((styleDocument && style.equalsIgnoreCase("document"))
-                        || (!styleDocument && style.equalsIgnoreCase("rpc")))
-                {
-                    String ns = Constants.URI_WSDL11_SOAP;
-                    SOAPBinding soapbinding = (SOAPBinding)getExtensibilityElement(b, INSTANCEOF_SOAPBINDING);
-                    if (soapbinding != null && null != soapbinding.getElementType().getNamespaceURI())
-                        ns = soapbinding.getElementType().getNamespaceURI();
-                        
-                    if ((soap11 && ns.equals(Constants.URI_WSDL11_SOAP))
-                            || (soap12 && ns.equals(Constants.URI_WSDL12_SOAP)))
-                            a.add(p);
-                }
-            }
-            else if (rest && (be.getBindingType() == BindingEntry.TYPE_HTTP_GET 
-                                || be.getBindingType() == BindingEntry.TYPE_HTTP_POST))
-            {
-                a.add(p);
-            }
-        }
-        
-        return a;
-    }
-    
-    /**
-     * Collects all the information by the wsdl2ws tool.
-     */
-    private void processWSDLDocument() throws Exception
-    {        
-        // Get target name space of WSDL
-        c_targetNameSpaceOfWSDL = c_symbolTable.getDefinition().getTargetNamespace();
-
-        // Collect services and bindings.           
-        Iterator it = c_symbolTable.getHashMap().values().iterator();
-        while (it.hasNext())
-        {
-            Vector v = (Vector) it.next();
-            for (int i = 0; i < v.size(); ++i)
-            {
-                SymTabEntry entry = (SymTabEntry) v.elementAt(i);
-
-                if (entry instanceof org.apache.axis.wsdl.symbolTable.ServiceEntry)
-                    c_services.add(((ServiceEntry) entry).getService());
-                else if (entry instanceof org.apache.axis.wsdl.symbolTable.BindingEntry)
-                    c_bindings.add(entry);
-            }
-        }
-    }
-    
-    /**
-     * Helper function that returns requested extensibility element.
-     * 
-     * @param e element to retrieve extensibility elements from.
-     * @param clazz instance of class
-     * @return extensibility element.
-     */
-    private static Object getExtensibilityElement(WSDLElement e, int clazz)
+    private boolean isTypeGenerated(TypeEntry type, Type typedata)
     {
-        if (e != null)
-        {
-            List extElems = e.getExtensibilityElements();
-            if (extElems != null)
-            {
-                Iterator it = extElems.iterator();
-                
-                while (it.hasNext())
-                {
-                    Object o = it.next();
-                    if ((clazz == INSTANCEOF_SOAPBINDING && (o instanceof javax.wsdl.extensions.soap.SOAPBinding))
-                       || (clazz == INSTANCEOF_SOAPADDRESS && (o instanceof javax.wsdl.extensions.soap.SOAPAddress))
-                       || (clazz == INSTANCEOF_SOAPOPERATION && (o instanceof javax.wsdl.extensions.soap.SOAPOperation))
-                       || (clazz == INSTANCEOF_SOAPBODY && (o instanceof javax.wsdl.extensions.soap.SOAPBody)))
-                        return o;
-                }
-            }
-        }
+        // If the referenced type is actually a type that will not get generated because it's
+        //     a base type array then tell other people of this case. Do this to two levels of indirection
         
-        return null;
+        if(type.getRefType()!=null)
+            if(type.getRefType().getRefType()!=null && type.getRefType().getRefType().isBaseType())
+                return false;
+            
+        if (typedata.isAnonymous())
+            return false;
+        else
+            return true;
     }
 }