private Type createTypeInfo()

in src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java [597:899]


    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.isPrimitiveType(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('['))
        { 
            // An array...
            
            // Get referenced type
            if (null == type.getRefType() || null == type.getRefType().getQName())
                throw new WrapperFault("Array type found without a Ref type: " + type.getQName());
            
            
            // TODO not sure what we should do if array references an element following commented code is not correct 
	        //  if (type.getRefType().getRefType() != null) 	 
	        //     qn = type.getRefType().getRefType().getQName();
            QName qn = type.getRefType().getQName();
            
            // If referenced type is primitive, we are done...
            if (CUtils.isPrimitiveType(qn))
                return null;
            
            // Create array 
            QName newqn;
            if (useCounter)
            {
                newqn = CUtils.getArrayQNameForType(qn);
                if (newqn == null)
                    newqn = new QName(type.getQName().getNamespaceURI(), CUtils.sanitizeString(qn.getLocalPart()) + "_Array" + typeCounter++);      
            }
            else
                newqn = new QName(type.getQName().getNamespaceURI(), CUtils.sanitizeString(qn.getLocalPart()) + "_Array");
            
            // type is a inbuilt type or an already created type?
            typedata = c_typeMap.getType(newqn);
            if (typedata != null)
            {
                if (typedata.isArray())
                {
                    if (c_verbose && !CUtils.isPrimitiveType(type.getQName()))
                        System.out.println("Type not created, already exists: " + type.getQName());
                    
                    return typedata;
                }
                else
                {
                    // There is a type with the _Array suffix in WSDL that was already processed.
                    // If an array type was not already created, create one with different name.
                    QName arrayQName = CUtils.getArrayQNameForType(qn);
                    if (arrayQName == null)
                    {
                        do 
                        {
                            newqn = new QName(type.getQName().getNamespaceURI(), CUtils.sanitizeString(qn.getLocalPart())  + "_Array" + typeCounter++);
                            typedata = c_typeMap.getType(newqn);
                        }
                        while (typedata != null && !typedata.isArray());
                        
                        if (typedata == null)
                        {
                            if (c_verbose)
                                System.out.println("Type clash, change type name to : " + newqn);
                        }
                        else 
                        {
                            if (c_verbose && !CUtils.isPrimitiveType(type.getQName()))
                                System.out.println("Type not created, already exists: " + type.getQName());
                            
                            return typedata;                            
                        }
                    }
                    else
                    {
                        if (c_verbose)
                            System.out.println("Type not created, already exists: " + type.getQName());
                        
                        return c_typeMap.getType(arrayQName);
                    }
                }
            }            
            
            typedata = new Type(newqn, newqn.getLocalPart());
            CUtils.addArrayType(qn, newqn);
            
            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 (!typedata.isArray())
                {                
                    if (c_verbose && !CUtils.isPrimitiveType(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);
        
        // 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());
                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());
                    attr.setType(newSecondaryType);
                    typedata.addRelatedType(newSecondaryType);
                }
                typedata.addAttributes(attributes);
            }
        }
        else if (type instanceof CollectionType)
        {
            typedata.setArray(true);

            newSecondaryType = createTypeInfo(type.getRefType().getQName());
            typedata.addRelatedType(newSecondaryType);
            typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, type.getQName()));
        }
        else
        {
            //is this a SOAPEnc array type    
            QName arrayType = CSchemaUtils.getArrayComponentQName(node,new IntHolder(0),c_symbolTable);
            if (arrayType != null)
            {
                typedata.setArray(true);

                newSecondaryType = createTypeInfo(arrayType);
                typedata.addRelatedType(newSecondaryType);
                typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, new QName("item")));
            }
            else if ((arrayType = CSchemaUtils.getCollectionComponentQName(node)) != null)
            {
                typedata.setArray(true);

                newSecondaryType = createTypeInfo(arrayType);
                typedata.addRelatedType(newSecondaryType);
                typedata.setTypeNameForElementName(new CElementDecl(newSecondaryType, new QName("item")));
            }
            //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();
                            }
                            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.isPrimitiveType(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;
    }