Package org.apache.yoko.tools.processors.wsdl

Source Code of org.apache.yoko.tools.processors.wsdl.WSDLToCorbaHelper

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.yoko.tools.processors.wsdl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.wsdl.Binding;
import javax.wsdl.Definition;
import javax.wsdl.Part;

import javax.xml.namespace.QName;

import org.apache.cxf.common.logging.LogUtils;
import org.apache.schemas.yoko.bindings.corba.CaseType;
import org.apache.schemas.yoko.bindings.corba.Enum;
import org.apache.schemas.yoko.bindings.corba.Enumerator;
import org.apache.schemas.yoko.bindings.corba.MemberType;
import org.apache.schemas.yoko.bindings.corba.Struct;
import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
import org.apache.schemas.yoko.bindings.corba.Union;
import org.apache.schemas.yoko.bindings.corba.Unionbranch;

import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaAll;
import org.apache.ws.commons.schema.XmlSchemaAnnotation;
import org.apache.ws.commons.schema.XmlSchemaAttribute;
import org.apache.ws.commons.schema.XmlSchemaChoice;
import org.apache.ws.commons.schema.XmlSchemaComplexContent;
import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
import org.apache.ws.commons.schema.XmlSchemaComplexType;
import org.apache.ws.commons.schema.XmlSchemaElement;
import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
import org.apache.ws.commons.schema.XmlSchemaFacet;
import org.apache.ws.commons.schema.XmlSchemaLengthFacet;
import org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet;
import org.apache.ws.commons.schema.XmlSchemaParticle;
import org.apache.ws.commons.schema.XmlSchemaSequence;
import org.apache.ws.commons.schema.XmlSchemaSimpleContent;
import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
import org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction;
import org.apache.ws.commons.schema.XmlSchemaSimpleType;
import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
import org.apache.ws.commons.schema.XmlSchemaType;
import org.apache.yoko.tools.common.CorbaPrimitiveMap;
import org.apache.yoko.tools.common.ReferenceConstants;
import org.apache.yoko.wsdl.CorbaConstants;
import org.apache.yoko.wsdl.CorbaTypeImpl;
import org.apache.yoko.wsdl.W3CConstants;

public class WSDLToCorbaHelper {

    public static final String REPO_STRING = "IDL:";
    public static final String IDL_VERSION = ":1.0";

    protected static final Logger LOG = LogUtils.getL7dLogger(WSDLToCorbaHelper.class);
    protected static final String DISCRIMINATORTYPES[]
        = new String[] {"long", "short", "boolean", "char"};
    protected static final Set<String> SUPPORTEDDISTYPES =
        new TreeSet<String>(Arrays.asList(DISCRIMINATORTYPES));

    protected static final CorbaPrimitiveMap CORBAPRIMITIVEMAP = new CorbaPrimitiveMap();

    String idlNamespace;
    XmlSchema xmlSchemaType;
    List<XmlSchema> xmlSchemaList;
    TypeMappingType typeMappingType;
    Definition def;

    public void setXMLSchema(XmlSchema schema) {
        xmlSchemaType = schema;
    }

    public void setTypeMap(TypeMappingType map) {
        typeMappingType = map;
    }

    public void setIdlNamespace(String ns) {
        idlNamespace = ns;
    }

    public String getIdlNamespace() {
        return idlNamespace;
    }

    public void setXMLSchemaList(List<XmlSchema> list) {
        xmlSchemaList = list;
    }
   
    public List<XmlSchema> getXMLSchemaList() {
        return xmlSchemaList;
    }

    public void setWsdlDefinition(Definition defn) {
        def = defn;
    }

    public CorbaTypeImpl convertSchemaToCorbaType(XmlSchemaType stype,
                                                  QName defaultName,
                                                  XmlSchemaType parent,
                                                  XmlSchemaAnnotation annotation,
                                                  boolean anonymous)
        throws Exception {
        CorbaTypeImpl corbaTypeImpl = null;
        if (!isAddressingNamespace(stype.getQName())) {
            // need to determine if its a primitive type.
            if (stype.getBaseSchemaType() != null) {
                corbaTypeImpl = processPrimitiveType(stype.getQName());
            }

            if (stype instanceof XmlSchemaComplexType) {
                return corbaTypeImpl = processComplexType((XmlSchemaComplexType)stype,
                                                          defaultName, annotation, anonymous);
            } else if (stype instanceof XmlSchemaSimpleType) {           
                return corbaTypeImpl = processSimpleType((XmlSchemaSimpleType)stype,
                                                         defaultName, anonymous);
            else if (xmlSchemaType.getElementByName(stype.getQName()) != null) {
                XmlSchemaElement el = xmlSchemaType.getElementByName(stype.getQName());
                return corbaTypeImpl = processElementType(el, defaultName);
            } else {
                throw new Exception("Couldn't convert schema " + stype.getQName() + " to corba type");
            }
        }
        return corbaTypeImpl;
    }

    protected List processContainerAsMembers(XmlSchemaParticle particle,
                                             QName defaultName,
                                             QName schemaTypeName)
        throws Exception {
        List<MemberType> members = new ArrayList<MemberType>();

        Iterator iterL = null;
        if (particle instanceof XmlSchemaSequence) {
            XmlSchemaSequence scontainer = (XmlSchemaSequence)particle;
            iterL = scontainer.getItems().getIterator();
        } else if (particle instanceof XmlSchemaChoice) {
            XmlSchemaChoice scontainer = (XmlSchemaChoice)particle;
            iterL = scontainer.getItems().getIterator();
        } else if (particle instanceof XmlSchemaAll) {
            XmlSchemaAll acontainer = (XmlSchemaAll)particle;
            iterL = acontainer.getItems().getIterator();
        }

        while (iterL.hasNext()) {
            XmlSchemaParticle container = (XmlSchemaParticle)iterL.next();
           
            if (container instanceof XmlSchemaSequence) {
                XmlSchemaSequence sequence = (XmlSchemaSequence)container;
                CorbaTypeImpl memberType = processSequenceType(sequence, defaultName, schemaTypeName);
                QName typeName = memberType.getQName();
                if (memberType instanceof Struct) {
                    memberType.setQName(null);                 
                    if (memberType != null && !isDuplicate(memberType)) {
                        typeMappingType.getStructOrExceptionOrUnion().add(memberType);
                    }                   
                }
               
                MemberType member = new MemberType();
                member.setName(memberType.getName() + "_f");
                member.setIdltype(typeName);
                members.add(member);

            } else if (container instanceof XmlSchemaChoice) {
                XmlSchemaChoice choice = (XmlSchemaChoice)container;
                CorbaTypeImpl corbatype = processChoice(choice, defaultName, schemaTypeName);
                MemberType member = new MemberType();
                member.setName(corbatype.getQName().getLocalPart());
                member.setIdltype(corbatype.getQName());
                members.add(member);
            } else if (container instanceof XmlSchemaAll) {
                XmlSchemaAll all = (XmlSchemaAll)container;
                CorbaTypeImpl corbatype = processAllType(all, defaultName, schemaTypeName);
                MemberType member = new MemberType();
                member.setName(corbatype.getQName().getLocalPart());
                member.setIdltype(corbatype.getQName());
                members.add(member);
            } else if (container instanceof XmlSchemaElement) {
                XmlSchemaElement element = (XmlSchemaElement)container;
                CorbaTypeImpl corbatype = processLocalElement(element);

                if (corbatype != null) {
                    MemberType member;
                    String memberName = element.getQName().getLocalPart();
                    member = new MemberType();
                    member.setName(memberName);
                    member.setIdltype(corbatype.getQName());
                    members.add(member);
                } else {
                    String msg = "Unsupported Element Found in CORBA Binding Generation:"
                                 + element.getQName();
                    LOG.log(Level.WARNING, msg.toString());
                }
            }
        }
        return members;
    }
   
    private CorbaTypeImpl processChoice(XmlSchemaChoice choice,
                                        QName defaultName,
                                        QName schemaTypeName)
        throws Exception {       
        QName choicename = null;

        if (schemaTypeName == null) {
            choicename = createQNameCorbaNamespace(defaultName.getLocalPart());
        } else {
            choicename = createQNameCorbaNamespace(schemaTypeName.getLocalPart());
        }
        choicename = checkPrefix(choicename);

        CorbaTypeImpl corbatype = createUnion(choicename, choice, defaultName, schemaTypeName);
        String repoId = REPO_STRING + corbatype.getQName().getLocalPart().replace('.', '/')
            + IDL_VERSION;
        ((Union)corbatype).setRepositoryID(repoId);                               

        if (!(choice.getMaxOccurs() == 1) || !(choice.getMinOccurs() == 1)) {
            QName name = createQNameTargetNamespace(corbatype.getQName().getLocalPart() + "Array");
            CorbaTypeImpl arrayType =
                createArray(name, corbatype.getQName(), corbatype.getQName(),
                    choice.getMaxOccurs(), choice.getMinOccurs(), false);
           
            if (arrayType != null) {
                arrayType.setQName(null);               
                if (!isDuplicate(arrayType)) {
                    typeMappingType.getStructOrExceptionOrUnion().add(arrayType);
                }
            }
        }
        return corbatype;
    }
   
    private CorbaTypeImpl processLocalElement(XmlSchemaElement element) throws Exception {
        CorbaTypeImpl membertype = new CorbaTypeImpl();
        CorbaTypeImpl memtype = new CorbaTypeImpl();

        QName memName = null;
        if (element.isNillable()) {

            CorbaTypeImpl elemtype = convertSchemaToCorbaType(element.getSchemaType(), element.getQName(),
                                                              element.getSchemaType(), null, true);
            QName name = createQNameTargetNamespace(elemtype.getQName().getLocalPart() + "_nil");
            QName elName = checkPrefix(element.getQName());
            if (elName ==  null) {
                elName = createQNameTargetNamespace(element.getQName().getLocalPart());
            }
            memtype = createNillableUnion(name, elName,
                                          elemtype.getQName());
            memName = createQNameCorbaNamespace(memtype.getQName().getLocalPart());
                                   
            if (memtype != null) {                         
                memtype.setQName(null);
                if (!isDuplicate(memtype)) {
                    typeMappingType.getStructOrExceptionOrUnion().add(memtype);
                }
            }
            membertype.setQName(memName);
            membertype.setName(memtype.getName());
            membertype.setType(memtype.getType());
           
        } else {
            // Need TO DO
            // Need to check if its referencing a type first refname=""
            //if (element.getRefName()
            if (element.getSchemaType() != null) {
                XmlSchemaType st = element.getSchemaType();
                boolean anonymous = WSDLTypes.isAnonymous(st.getName());           
                membertype = convertSchemaToCorbaType(st, element.getQName(), st, null, anonymous);
            } else {               
                if (element.getSchemaTypeName() != null) {
                    QName name = checkPrefix(element.getSchemaTypeName());
                    membertype = getLocalType(name);                   
                }
            }
        }

        if (!(element.getMaxOccurs() == 1) || !(element.getMinOccurs() == 1)) {
            QName name = createQNameCorbaNamespace(getModulePrefix(membertype)
                                                    + element.getQName().getLocalPart() + "Array");
           
            // workaround for now - sent bug to WSCommons - the elements
            // QName should have its namespace included.
            QName schemaName = element.getQName();
            if (schemaName.getNamespaceURI().equals("")) {
                schemaName = new QName(xmlSchemaList.get(0).getTargetNamespace(),
                                       schemaName.getLocalPart());               
            }
           
            CorbaTypeImpl arraytype = null;
            if (memName != null) {
                arraytype = createArray(name, schemaName, memName,
                                        element.getMaxOccurs(), element.getMinOccurs(), false);
            } else {
                arraytype = createArray(name, schemaName, membertype.getQName(),
                                        element.getMaxOccurs(), element.getMinOccurs(), false);
            }
                       
            membertype.setName(arraytype.getName());
            membertype.setQName(arraytype.getQName());
            membertype.setType(arraytype.getType());
                       
            if (arraytype != null) {               
                arraytype.setQName(null);
                if (!isDuplicate(arraytype)) {
                    typeMappingType.getStructOrExceptionOrUnion().add(arraytype);              
                }               
            }                  
        }
        return membertype;
    }

   
    public XmlSchemaType getSchemaType(QName name) throws Exception {               
        XmlSchemaType type = null;
        Iterator i = xmlSchemaList.iterator();
        while (i.hasNext()) {
            XmlSchema xmlSchema = (XmlSchema)i.next();     
            String nspace = xmlSchema.getTargetNamespace();
            QName tname = createQName(nspace, name.getLocalPart(), "xsd");
            type = findSchemaType(tname);                           
            if (type != null) {
                break;
            }
        }      
        return type;
    }
         
    private String getModulePrefix(CorbaTypeImpl type) {
        String name = type.getQName().getLocalPart();
        int dotPos = name.lastIndexOf(".");
        return dotPos == -1 ? "" : name.substring(0, dotPos + 1);
    }

   
    protected CorbaTypeImpl processSequenceType(XmlSchemaSequence seq,
                                                QName defaultName, QName schemaTypeName)
        throws Exception {
        CorbaTypeImpl type = null;
        QName seqName = null;
        if (schemaTypeName == null) {
            seqName = createQNameCorbaNamespace(defaultName.getLocalPart() + "SequenceStruct");       
        } else {       
            seqName = createQNameCorbaNamespace(schemaTypeName.getLocalPart() + "SequenceStruct");
        }
       
        schemaTypeName = checkPrefix(schemaTypeName);
        Struct struct = new Struct();      
        struct.setName(seqName.getLocalPart());
        struct.setQName(seqName);
        struct.setRepositoryID(REPO_STRING + seqName.getLocalPart().replace('.', '/') + IDL_VERSION);
        struct.setType(schemaTypeName);
       
        List members = processContainerAsMembers(seq, defaultName, schemaTypeName);
        for (Iterator iterator = members.iterator(); iterator.hasNext();) {
            MemberType memberType = (MemberType)iterator.next();
            struct.getMember().add(memberType);           
        }       
       
        type = struct;
                             
        if (!"1".equals(seq.getMaxOccurs()) || !"1".equals(seq.getMinOccurs())) {
            QName name = createQNameTargetNamespace(type.getQName().getLocalPart() + "Array");           
            CorbaTypeImpl atype = createArray(name, type.getQName(), type.getQName(),
                                           seq.getMaxOccurs(), seq.getMinOccurs(), false);
           
            if (atype != null) {
                atype.setQName(null);              
                if (!isDuplicate(atype)) {
                    typeMappingType.getStructOrExceptionOrUnion().add(atype);              
                }
            }
        }
       
        if ((type instanceof Struct) && (struct.getMember().size() == 0)) {
            String msgStr = "Cannot create CORBA Struct" + struct.getName()
                            + "from container with no members";
            org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(
                                      msgStr, LOG);
            throw new Exception(msg.toString());
        }       
               
        return type;
    }
   
   
    protected CorbaTypeImpl processAllType(XmlSchemaAll seq, QName defaultName,
                                           QName schematypeName) throws Exception {
        QName allName = null;
        Struct type = null;

        if (schematypeName == null) {
            allName = createQNameCorbaNamespace(defaultName.getLocalPart() + "AllStruct");
        } else {
            allName = createQNameCorbaNamespace(schematypeName.getLocalPart() + "AllStruct");
        }

        type = new Struct();
        type.setName(allName.getLocalPart());
        type.setQName(allName);
        type.setType(schematypeName);
       
        List members = processContainerAsMembers(seq, defaultName, schematypeName);
        for (Iterator iterator = members.iterator(); iterator.hasNext();) {
            MemberType memberType = (MemberType)iterator.next();
            type.getMember().add(memberType);
        }
               
        String repoId = REPO_STRING + type.getQName().getLocalPart().replace('.', '/') + IDL_VERSION;
        type.setRepositoryID(repoId);
        return type;
    }
   
    private CorbaTypeImpl processPrimitiveType(QName typeName) {
        QName qName = createQNameXmlSchemaNamespace(typeName.getLocalPart());       
        CorbaTypeImpl corbatype = (CorbaTypeImpl)CORBAPRIMITIVEMAP.get(qName);
        if (corbatype == null) {
            //REVISIT, bravi, not an ideal way to add the fixed & octet type to the typemap.
            CorbaTypeImpl type = null;
            if (typeName.equals(W3CConstants.NT_SCHEMA_DECIMAL)) {
                QName name = new QName(idlNamespace, "fixed_1");
                type = WSDLTypes.getFixedCorbaType(name, typeName, 31, 6);
                corbatype = WSDLTypes.getFixedCorbaType(name, typeName, 31, 6);
            } else if (typeName.equals(W3CConstants.NT_SCHEMA_BASE64)
                       || typeName.equals(W3CConstants.NT_SCHEMA_HBIN)) {
                QName name = new QName(idlNamespace, typeName.getLocalPart() + "Seq");
                type = WSDLTypes.getOctetCorbaType(name, typeName, 0);
                corbatype = WSDLTypes.getOctetCorbaType(name, typeName, 0);
            }
            if (type != null) {
                type.setQName(null);
                if (!isDuplicate(type)) {
                    typeMappingType.getStructOrExceptionOrUnion().add(type);
                }
            }
        }
        return corbatype;
    }

    protected List<MemberType> processAttributesAsMembers(Iterator attrs) throws Exception {
        QName memName = null;
        List <MemberType>members = new ArrayList<MemberType>();

        while (attrs.hasNext()) {
            XmlSchemaAttribute attribute = (XmlSchemaAttribute)attrs.next();
            CorbaTypeImpl membertype = null;

            if (attribute.getUse().getValue().equals("none")
                || attribute.getUse().getValue().equals(W3CConstants.USE_OPTIONAL)) {               
                CorbaTypeImpl attType = null;
                if (attribute.getSchemaType() != null) {                   
                    attType = convertSchemaToCorbaType(attribute.getSchemaType(),
                                                       attribute.getQName(),
                                              attribute.getSchemaType(), null, true);                  
                    if (attType != null) {
                        QName typeName = attType.getQName();
                        attType.setQName(null);          
                        if (!isDuplicate(attType)) {
                            typeMappingType.getStructOrExceptionOrUnion().add(attType);
                        }
                        QName name =  createQNameTargetNamespace(typeName.getLocalPart() + "_nil");
                        membertype = createNillableUnion(name, attribute.getQName(),
                                     createQNameCorbaNamespace(typeName.getLocalPart()));
                    }
                } else {
                    attType = processPrimitiveType(attribute.getSchemaTypeName());
                    //REVISIT, bravi, attType is null for the wsaddr type
                    //{http://www.w3.org/2005/08/addressing}RelationshipTypeOpenEnum
                    if (attType != null) {
                        QName name =  createQNameTargetNamespace(attType.getQName().getLocalPart() + "_nil");
                        membertype = createNillableUnion(name, attribute.getQName(),
                                                         attType.getQName());
                    }

                }
                if (membertype != null) {
                    memName = createQNameCorbaNamespace(membertype.getQName().getLocalPart());
                    membertype.setQName(null);          
                    if (!isDuplicate(membertype)) {
                        typeMappingType.getStructOrExceptionOrUnion().add(membertype);
                    }
                }
            } else {
                if (attribute.getSchemaType() != null) {
                    membertype = convertSchemaToCorbaType(attribute.getSchemaType(), attribute.getQName(),
                                                      attribute.getSchemaType(), null, false);
                } else {
                    membertype = processPrimitiveType(attribute.getSchemaTypeName());
                }
            }

            if (membertype != null) {
                MemberType member;
                String memberName = attribute.getQName().getLocalPart();

                member = new MemberType();
                member.setName(memberName);
                if (memName != null) {
                    member.setIdltype(memName);
                } else {
                    member.setIdltype(membertype.getQName());
                }
                members.add(member);
            } else {
                String msg = "Unsupported Attribute Found in CORBA Binding Generation:"
                    + attribute.getQName();
                LOG.log(Level.WARNING, msg.toString());           
            }
        }

        return members;
    }

   
    private CorbaTypeImpl processElementType(XmlSchemaElement stype, QName defaultName)
        throws Exception {

        QName schematypeName;

        if (stype.getName() == null) {
            schematypeName = defaultName;
        } else {
            schematypeName = createQNameTargetNamespace(stype.getName());
        }

        return convertSchemaToCorbaType(stype.getSchemaType(), schematypeName,
                                        stype.getSchemaType(), null, false);

    }

    private CorbaTypeImpl processSimpleType(XmlSchemaSimpleType stype, QName defaultName,
                                            boolean anonymous)
        throws Exception {

        CorbaTypeImpl corbaTypeImpl = null;
        QName name;
        QName schematypeName = null;
       
        if (stype.getQName() == null) {
            schematypeName = defaultName;
            name = createQNameTargetNamespace(defaultName.getLocalPart() + "Type");
        } else {
            schematypeName = checkPrefix(stype.getQName());
            if (schematypeName == null) {
                schematypeName = stype.getQName();
            }
            name = createQNameCorbaNamespace(schematypeName.getLocalPart());
        }       
       
        if (stype.getContent() instanceof XmlSchemaSimpleTypeRestriction) {
            corbaTypeImpl = processSimpleRestrictionType(stype, name, schematypeName, anonymous);
        } else if (stype.getContent() instanceof XmlSchemaSimpleTypeList) {
            XmlSchemaSimpleTypeList ltype = (XmlSchemaSimpleTypeList)stype.getContent();
            CorbaTypeImpl itemType = null;
            if (ltype.getItemType() != null) {
                itemType = convertSchemaToCorbaType(ltype.getItemType(), name, stype, null, false);
                if (itemType != null) {
                    return WSDLTypes.mapToSequence(name, checkPrefix(schematypeName),
                                                   itemType.getQName(), 0, false);
                }
                return itemType;
            }
            QName ltypeName = createQNameXmlSchemaNamespace(ltype.getItemTypeName().getLocalPart());
            itemType = processPrimitiveType(ltypeName);
            return WSDLTypes.mapToSequence(name, checkPrefix(schematypeName), itemType.getQName(), 0, false);
        } else if (stype.getContent() == null) {
            // elements primitive type
            QName stypeName = createQNameXmlSchemaNamespace(stype.getName());
            corbaTypeImpl = getLocalType(stypeName);           
        } else {
            System.out.println("SimpleType Union Not Supported in CORBA Binding");
        }
        return corbaTypeImpl;
    }
   
    private CorbaTypeImpl processSimpleRestrictionType(XmlSchemaSimpleType stype,
                                                       QName name, QName schematypeName,
                                                       boolean anonymous)
        throws Exception {
        CorbaTypeImpl corbaTypeImpl = null;
   
        // checks if enumeration
        XmlSchemaSimpleTypeRestriction restrictionType = (XmlSchemaSimpleTypeRestriction)stype
            .getContent();
       
        QName baseName = checkPrefix(restrictionType.getBaseTypeName());
       
        String maxLength = null;
        String length = null;

        Iterator i = restrictionType.getFacets().getIterator();
        while (i.hasNext()) {
            XmlSchemaFacet val = (XmlSchemaFacet)i.next();
            if (val instanceof XmlSchemaMaxLengthFacet) {               
                maxLength = val.getValue().toString();
            }
            if (val instanceof XmlSchemaLengthFacet) {
                length = val.getValue().toString();
            }
        }
       
        if (isEnumeration(restrictionType)) {
            corbaTypeImpl = createCorbaEnum(restrictionType, name, schematypeName);
        } else {
            if (restrictionType.getBaseType() != null) {
                corbaTypeImpl = convertSchemaToCorbaType(restrictionType.getBaseType(), schematypeName,
                                                         stype, null, false);
            } else {               
                corbaTypeImpl = processPrimitiveType(baseName);               
                if (corbaTypeImpl == null) {
                    XmlSchemaType schematype = findSchemaType(baseName);
                    corbaTypeImpl = convertSchemaToCorbaType(schematype, schematypeName,
                                                             schematype, null, false);
                }
            }

            if (corbaTypeImpl != null) {
                if (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_STRING)
                    || (baseName.equals(W3CConstants.NT_SCHEMA_STRING))) {               
                    corbaTypeImpl =
                        WSDLTypes.processStringType(corbaTypeImpl, name, maxLength, length);               
                } else if (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_DECIMAL)
                    || (baseName.equals(W3CConstants.NT_SCHEMA_DECIMAL))) {               
                    corbaTypeImpl = WSDLTypes.processDecimalType(restrictionType, name,
                                                             corbaTypeImpl, anonymous);
                } else if ((corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_BASE64))
                    || (baseName.equals(W3CConstants.NT_SCHEMA_BASE64))
                    || (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_HBIN))
                    || (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_HBIN))) {               
                    corbaTypeImpl = WSDLTypes.processBase64Type(corbaTypeImpl,
                                                                name, maxLength, length);         
                }           
            }
        }
       
        return corbaTypeImpl;
    }              
    private CorbaTypeImpl getLocalType(QName qname) {
        return processPrimitiveType(qname);
    }

    private Enum createCorbaEnum(XmlSchemaSimpleTypeRestriction restrictionType, QName name,
                                 QName schematypeName) {
        Enum corbaEnum = new Enum();
        corbaEnum.setType(schematypeName);
        corbaEnum.setName(name.getLocalPart());
        corbaEnum.setQName(name);

        corbaEnum.setRepositoryID(REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION);
        Iterator enums = restrictionType.getFacets().getIterator();

        while (enums.hasNext()) {
            XmlSchemaEnumerationFacet val = (XmlSchemaEnumerationFacet)enums.next();
            Enumerator enumerator = new Enumerator();
            enumerator.setValue(val.getValue().toString());
            corbaEnum.getEnumerator().add(enumerator);
        }
        return corbaEnum;
    }

    private boolean isEnumeration(XmlSchemaSimpleTypeRestriction restriction) {

        if ((restriction == null) || (restriction.getFacets().getCount() == 0)
            || (restriction.getBaseTypeName() == null)) {
            return false;
        }

        Iterator it = restriction.getFacets().getIterator();
        while (it.hasNext()) {
            XmlSchemaFacet facet = (XmlSchemaFacet)it.next();
            if (facet instanceof XmlSchemaEnumerationFacet) {
                return true;
            }
        }
        return false;
    }

   
    protected XmlSchemaType lookUpType(Part part) {
        XmlSchemaType schemaType = null;
       
        Iterator i = xmlSchemaList.iterator();
        while (i.hasNext()) {
            XmlSchema xmlSchema = (XmlSchema)i.next();
       
            if (part.getElementName() != null) {
                XmlSchemaElement schemaElement = xmlSchema.getElementByName(part.getElementName());
                if (schemaElement != null) {
                    schemaType = schemaElement.getSchemaType();
                }
            } else {
                if (part.getTypeName() != null) {
                    schemaType = xmlSchema.getTypeByName(part.getTypeName());
                }
            }
            if (schemaType != null) {
                return schemaType;
            }
        }
           
        return schemaType;
    }
   
    private XmlSchemaType findSchemaType(QName typeName) {
        XmlSchemaType schemaType = null;
       
        Iterator i = xmlSchemaList.iterator();
        while (i.hasNext()) {
            XmlSchema xmlSchema = (XmlSchema)i.next();       
            if (xmlSchema.getElementByName(typeName) != null) {
                XmlSchemaElement schemaElement = xmlSchema.getElementByName(typeName);               
                schemaType = schemaElement.getSchemaType();               
            } else if (xmlSchema.getTypeByName(typeName) != null) {               
                schemaType = xmlSchema.getTypeByName(typeName);               
            }
            if (schemaType != null) {
                return schemaType;
            }
        }           
        return schemaType;
    }
   
    protected boolean isSchemaTypeException(XmlSchemaType stype) {
        boolean exception = false;
        XmlSchemaComplexType complex = null;

        if (stype instanceof XmlSchemaComplexType) {          
            complex = (XmlSchemaComplexType)stype;

            if (!isLiteralArray(complex)  
                && !WSDLTypes.isOMGUnion(complex)
                && !WSDLTypes.isUnion(complex)) {
                exception = true;
            }
        }        
        return exception;
    }

   
    public boolean isLiteralArray(XmlSchemaComplexType type) {
        boolean array = false;

        if ((type.getAttributes().getCount() == 0)
            && (type.getParticle() instanceof XmlSchemaSequence)) {
            XmlSchemaSequence stype = (XmlSchemaSequence)type.getParticle();
                   
            if ((stype.getItems().getCount() == 1)
                && (stype.getItems().getIterator().next() instanceof XmlSchemaElement)) {
                XmlSchemaElement el = (XmlSchemaElement)stype.getItems().getIterator().next();
                if (!(el.getMaxOccurs() == 1)) {
                    // it's a literal array
                    array = true;
                }               
                if (el.getMaxOccurs() == 1 && el.getMinOccurs() == 1) {
                    if (type.getName() != null &&  WSDLTypes.isAnonymous(type.getName())) {               
                        array = true;
                    }
                }
            }
        }
        return array;
    }
   
    /**
     * Create a CORBA Array or Sequence based on min and max Occurs If minOccurs ==
     * maxOccurs == 1 then log warning and return null. Else if minOccurs is
     * equal to maxOccurs then create an Array. Else create a Sequence
     */
    protected CorbaTypeImpl createArray(QName name, QName schematypeName, QName arrayType,
                                        Long maxOccurs, Long minOccurs, boolean anonymous) {
       
        int max = maxOccurs.intValue();
        if (max == -1) {
            return WSDLTypes.mapToSequence(name, schematypeName, arrayType, 0, anonymous);
        }
       
        int min = minOccurs.intValue();       
       
        if (min == max) {
            if (max == 1) {
                if (!anonymous) {
                    String msg = "Couldn't Map to Array:" + name + ":minOccurs="
                        + minOccurs + ":maxOccurs=" + maxOccurs;
                    LOG.log(Level.WARNING, msg.toString());
                    return null;
                } else {
                    return WSDLTypes.mapToArray(name, checkPrefix(schematypeName), arrayType, max, anonymous);
                }
            } else {
                return WSDLTypes.mapToArray(name, checkPrefix(schematypeName), arrayType, max, anonymous);
            }
        } else {
            return WSDLTypes.mapToSequence(name, checkPrefix(schematypeName), arrayType, max, anonymous);
        }
    }

   
    private CorbaTypeImpl processComplexType(XmlSchemaComplexType complex, QName defaultName,
                                             XmlSchemaAnnotation annotation,
                                             boolean anonymous) throws Exception {
        CorbaTypeImpl corbatype = null;
        if (isLiteralArray(complex)) {
            corbatype = processLiteralArray(complex, defaultName, anonymous);
        } else if (WSDLTypes.isOMGUnion(complex)) {
            corbatype = processOMGUnion(complex, defaultName);
        } else if (WSDLTypes.isUnion(complex)) {
            corbatype = processRegularUnion(complex, defaultName);                                          
        } else if (complex.getQName() != null && isIDLObjectType(complex.getQName())) {
            // process it.
            corbatype = WSDLTypes.processObject(def, complex, annotation, checkPrefix(complex.getQName()),
                                                defaultName, idlNamespace);
        } else {
            // Deal the ComplexType as Struct
            corbatype = processStruct(complex, defaultName);
        }
        return corbatype;
    }
   
       
    private CorbaTypeImpl processStruct(XmlSchemaComplexType complex, QName defaultName)
        throws Exception {
        QName name;
        Struct corbaStruct = null;
        QName schematypeName = checkPrefix(complex.getQName());              
        if (schematypeName == null) {
            schematypeName = checkPrefix(defaultName);
            name = checkPrefix(createQNameCorbaNamespace(defaultName.getLocalPart()));           
        } else {
            name = checkPrefix(createQNameCorbaNamespace(schematypeName.getLocalPart()));           
        }

        corbaStruct = new Struct();
        corbaStruct.setName(name.getLocalPart());
        corbaStruct.setQName(name);
        String repoId = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
        corbaStruct.setRepositoryID(repoId);
        corbaStruct.setType(schematypeName);
         
        if (complex.getContentModel() instanceof XmlSchemaSimpleContent) {
            corbaStruct = processSimpleContentStruct((XmlSchemaSimpleContent)complex.getContentModel(),
                                                     defaultName, corbaStruct, schematypeName);
        } else if (complex.getContentModel() instanceof XmlSchemaComplexContent) {
            corbaStruct = processComplexContentStruct((XmlSchemaComplexContent)complex.getContentModel(),
                                                      defaultName, corbaStruct, schematypeName);       
        }
       
        // Process attributes at ComplexType level
        if (complex.getAttributes().getIterator() != null) {
            Iterator iterator = complex.getAttributes().getIterator();
            List attlist2 = processAttributesAsMembers(iterator);
            MemberType member = new MemberType();
            for (int i = 0; i < attlist2.size(); i++) {
                member = (MemberType)attlist2.get(i);
                corbaStruct.getMember().add(member);
            }
        }

        if (complex.getParticle() != null) {
            List members = processContainerAsMembers(complex.getParticle(), defaultName, schematypeName);

            for (Iterator it = members.iterator(); it.hasNext();) {
                MemberType memberType = (MemberType)it.next();
                corbaStruct.getMember().add(memberType);
            }
        }

        return corbaStruct;
    }
       
    protected Struct processSimpleContentStruct(XmlSchemaSimpleContent simpleContent,
                                                QName defaultName, Struct corbaStruct, QName schematypeName)
        throws Exception {       
        XmlSchemaType base = null;       
        List attrMembers = null;
        CorbaTypeImpl basetype = null;

        if (simpleContent.getContent() instanceof XmlSchemaSimpleContentExtension) {       
            XmlSchemaSimpleContentExtension ext =
                (XmlSchemaSimpleContentExtension)simpleContent.getContent();
                       
            if (ext.getBaseTypeName() != null) {
                basetype = processPrimitiveType(ext.getBaseTypeName());
            }
           
            // process  ext types ????                     
            MemberType basemember = new MemberType();
            basemember.setName("_simpleTypeValue");
            basemember.setIdltype(basetype.getType());
            corbaStruct.getMember().add(basemember);
            attrMembers = processAttributesAsMembers(ext.getAttributes().getIterator());
        } else if (simpleContent.getContent() instanceof XmlSchemaSimpleContentRestriction) {
            XmlSchemaSimpleContentRestriction restrict
                = (XmlSchemaSimpleContentRestriction)simpleContent.getContent();
            basetype = convertSchemaToCorbaType(base, base.getQName(), base, null, false);
            base = restrict.getBaseType();
            basetype = convertSchemaToCorbaType(base, base.getQName(), base, null, false);
            MemberType basemember = new MemberType();
            basemember.setName("_simpleTypeValue");
            basemember.setIdltype(basetype.getType());
            corbaStruct.getMember().add(basemember);
            attrMembers = processAttributesAsMembers(restrict.getAttributes().getIterator());
        }

        //Deal with Attributes defined in Extension
        MemberType member = new MemberType();
        for (int i = 0; i < attrMembers.size(); i++) {
            member = (MemberType)attrMembers.get(i);
            corbaStruct.getMember().add(member);
        }

        //Process attributes at ComplexType level
        //List attlist2 = processAttributesAsMembers(simpleContent.unhandledAttributes.);
        //corbaStruct.getMembers().addAll(attlist2);     

        return corbaStruct;
    }
   
    protected Struct processComplexContentStruct(XmlSchemaComplexContent complex, QName defaultName,
                                                 Struct corbaStruct, QName schematypeName)
        throws Exception {       

        if (complex.getContent() instanceof XmlSchemaComplexContentExtension) {
            XmlSchemaComplexContentExtension extype
                = (XmlSchemaComplexContentExtension)complex.getContent();
           
            // Add base as a member of this struct
            MemberType memberType = new MemberType();    
            QName extName = extype.getBaseTypeName();
            memberType.setName(extName.getLocalPart() + "_f");
            if (extName.getLocalPart().equals("anyType")) {
                memberType.setIdltype(processPrimitiveType(extName).getQName());               
            } else {
                memberType.setIdltype(createQNameCorbaNamespace(extName.getLocalPart()));
            }           
            corbaStruct.getMember().add(memberType);
           
            // process attributes at complexContent level
            List attlist1 = processAttributesAsMembers(extype.getAttributes().getIterator());
            MemberType member = new MemberType();
            for (int i = 0; i < attlist1.size(); i++) {
                member = (MemberType)attlist1.get(i);
                corbaStruct.getMember().add(member);
            }
           
            // Process members of Current Type
            if (extype.getParticle() instanceof XmlSchemaChoice) {
                XmlSchemaChoice choice = (XmlSchemaChoice)extype.getParticle();
                MemberType choicemem = processComplexContentStructChoice(choice, schematypeName, defaultName);
                corbaStruct.getMember().add(choicemem);                               
            } else if (extype.getParticle() instanceof  XmlSchemaSequence) {
                XmlSchemaSequence seq = (XmlSchemaSequence)extype.getParticle();
                CorbaTypeImpl seqtype =
                    processSequenceType(seq, defaultName, schematypeName);                              

                if (seqtype != null) {                   
                    MemberType seqmem = new MemberType();
                    seqmem.setName(seqtype.getQName().getLocalPart() + "_f");
                    QName type = createQNameCorbaNamespace(seqtype.getQName().getLocalPart());
                    seqmem.setIdltype(type);
                    corbaStruct.getMember().add(seqmem);
                    if (!isDuplicate(seqtype)) {
                        seqtype.setQName(null);
                        typeMappingType.getStructOrExceptionOrUnion().add(seqtype);
                    }
                } else {                   
                    LOG.log(Level.WARNING, "Couldnt map Sequence inside extension");
                }

            } else if (extype.getParticle() instanceof  XmlSchemaAll) {
                XmlSchemaAll all = (XmlSchemaAll)extype.getParticle();
               
                CorbaTypeImpl alltype = processAllType(all, defaultName, schematypeName);
                if (alltype != null) {
                    MemberType allmem = new MemberType();
                    allmem.setName(alltype.getQName().getLocalPart() + "_f");
                    allmem.setIdltype(alltype.getQName());
                    corbaStruct.getMember().add(allmem);
                    if (!isDuplicate(alltype)) {
                        alltype.setQName(null);
                        typeMappingType.getStructOrExceptionOrUnion().add(alltype);
                    }
                } else {
                    LOG.log(Level.WARNING, "Couldnt map All inside extension");
                }
            }
           
        } else {
            org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(
                               "Restriction inside ComplexContent is not yet Supported.", LOG);
            //throw new Exception(msg.toString());           
            return null;
        }

        return corbaStruct;
    }
   
    protected MemberType processComplexContentStructChoice(XmlSchemaChoice choice,
                                                     QName schematypeName, QName defaultName)
        throws Exception {
        QName choicename = createQNameTargetNamespace(schematypeName.getLocalPart() + "ChoiceType");
        Union choiceunion = createUnion(choicename, choice,
                                        defaultName, schematypeName);

        String repoId = REPO_STRING + choiceunion.getQName().getLocalPart().replace('.', '/')
            + IDL_VERSION;
        choiceunion.setRepositoryID(repoId);                               
       
        MemberType choicemem = new MemberType();
        choicemem.setName(choiceunion.getQName().getLocalPart() + "_f");
        choicemem.setIdltype(createQNameCorbaNamespace(choiceunion.getQName().getLocalPart()));         
       
        if ((choiceunion != null) && (!isDuplicate(choiceunion))) {
            choiceunion.setQName(null);
            typeMappingType.getStructOrExceptionOrUnion().add(choiceunion);
        }
       
        return choicemem;
    }                   
   
    protected CorbaTypeImpl createNillableUnion(QName name, QName schemaType, QName membertype) {       
       
        Union nilUnion = new Union();
        nilUnion.setName(name.getLocalPart());
        nilUnion.setType(schemaType);
        nilUnion.setQName(name);
        nilUnion.setDiscriminator(CorbaConstants.NT_CORBA_BOOLEAN);
        String id = REPO_STRING + nilUnion.getQName().getLocalPart().replace('.', '/') + IDL_VERSION;
        nilUnion.setRepositoryID(id);

        Unionbranch branch = new Unionbranch();
        branch.setName("value");
        branch.setIdltype(membertype);
        branch.setDefault(false);
        CaseType caseType = new CaseType();
        caseType.setLabel("TRUE");
        branch.getCase().add(caseType);
        nilUnion.getUnionbranch().add(branch);      
       
        return nilUnion;
    }
   
    private CorbaTypeImpl processLiteralArray(XmlSchemaComplexType complex, QName defaultName,
                                              boolean anonymous) throws Exception {
        // NEED TO DO   
        QName name;
        QName typeName = null;
        QName schematypeName = checkPrefix(complex.getQName());

        if (schematypeName == null) {
            schematypeName = defaultName;
            name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
            schematypeName = checkPrefix(schematypeName);
            name = checkPrefix(name);
        } else {
            name = createQNameCorbaNamespace(schematypeName.getLocalPart());
            name = checkPrefix(name);
        }

        CorbaTypeImpl arrayType = null;
        XmlSchemaElement arrayEl = null;
        if (complex.getParticle() instanceof XmlSchemaSequence) {
            XmlSchemaSequence seq = (XmlSchemaSequence)complex.getParticle();
           
            Iterator iterator = seq.getItems().getIterator();
            Iterator iter = seq.getItems().getIterator();
            while (iterator.hasNext()) {
                if (iter.next() instanceof XmlSchemaElement) {
                    arrayEl = (XmlSchemaElement)iterator.next();
                    XmlSchemaType atype = arrayEl.getSchemaType();
                    if (atype == null) {
                        atype = getSchemaType(arrayEl.getSchemaTypeName());
                    }
                    arrayType = convertSchemaToCorbaType(atype, arrayEl.getQName(),
                                                         atype, null, true);
                    typeName = arrayType.getQName();
                }
            }
        }

       
        if (arrayEl.isNillable()) {
            QName nilunionname = createQNameTargetNamespace(arrayType.getQName().getLocalPart() + "_nil");
            arrayType = createNillableUnion(nilunionname, arrayEl.getQName(),
                            arrayType.getQName());
            typeName = createQNameCorbaNamespace(arrayType.getQName().getLocalPart());
            if (arrayType != null) {
                arrayType.setQName(null);          
                if (!isDuplicate(arrayType)) {
                    typeMappingType.getStructOrExceptionOrUnion().add(arrayType);
                }
            }
        }
       
        Long maxOccurs = null;
        Long minOccurs = null;
        if (arrayEl != null) {
            maxOccurs = arrayEl.getMaxOccurs();
            minOccurs = arrayEl.getMinOccurs();
        }
       
        return createArray(name, schematypeName,
                           checkPrefix(typeName), maxOccurs, minOccurs, anonymous);    
    }
   
    private CorbaTypeImpl processOMGUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception {
        QName name;
        Union corbaUnion = null;
        QName schematypeName = checkPrefix(complex.getQName());               

        if (schematypeName == null) {
            schematypeName = defaultName;
            name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
        } else {
            name = createQNameCorbaNamespace(schematypeName.getLocalPart());
        }

        corbaUnion = new Union();
        corbaUnion.setName(name.getLocalPart());
        corbaUnion.setQName(name);
        String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
        corbaUnion.setRepositoryID(id);
        corbaUnion.setType(schematypeName);

        XmlSchemaSequence stype = (XmlSchemaSequence)complex.getParticle();
        Iterator it = stype.getItems().getIterator();
        XmlSchemaParticle st1 = (XmlSchemaParticle)it.next();
        XmlSchemaParticle st2 = (XmlSchemaParticle)it.next();
        XmlSchemaElement discEl = null;
        XmlSchemaChoice choice = null;

        if (st1 instanceof XmlSchemaElement) {
            discEl = (XmlSchemaElement)st1;
            choice = (XmlSchemaChoice)st2;
        } else {
            discEl = (XmlSchemaElement)st2;
            choice = (XmlSchemaChoice)st1;
        }

        CorbaTypeImpl disctype = convertSchemaToCorbaType(discEl.getSchemaType(), discEl.getQName(), discEl
            .getSchemaType(), null, false);
        corbaUnion.setDiscriminator(disctype.getQName());

        List fields = processContainerAsMembers(choice, defaultName, schematypeName);

        List<String> caselist = new ArrayList<String>();

        if (disctype instanceof Enum) {
            Enum corbaenum = (Enum)disctype;
            Iterator iterator = corbaenum.getEnumerator().iterator();

            while (iterator.hasNext()) {
                Enumerator enumerator = (Enumerator)iterator.next();
                caselist.add(enumerator.getValue());
            }
        } else if (SUPPORTEDDISTYPES.contains(disctype.getQName().getLocalPart())) {
            if (disctype.getQName().getLocalPart().equals("long")
                || disctype.getQName().getLocalPart().equals("short")) {
                for (int i = 0; i < fields.size(); i++) {
                    caselist.add(Integer.toString(i));
                }
            } else if (disctype.getQName().getLocalPart().equals("char")) {
                for (int i = 0; i < fields.size(); i++) {
                    caselist.add(Integer.toString(i));
                }
            } else if (disctype.getQName().getLocalPart().equals("char")) {
                for (int i = 0; i < fields.size(); i++) {
                    caselist.add(Integer.toString(i));
                }
            } else if (disctype.getQName().getLocalPart().equals("boolean")) {
                if (fields.size() == 2) {
                    caselist.add("TRUE");
                    caselist.add("FALSE");
                } else if (fields.size() == 1) {
                    caselist.add("TRUE");
                } else {
                    String msg = "Discriminator Type doesnt match number of Choices in Union:" + name;
                    LOG.log(Level.WARNING, msg.toString());
                }
            }
        }

        WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);

        return corbaUnion;
    }          

   
    private CorbaTypeImpl processRegularUnion(XmlSchemaComplexType complex,
                                              QName defaultName) throws Exception {
        //NEED TO DO
        QName name = null;
        QName schematypeName = complex.getQName();
       
        if (schematypeName == null) {
            schematypeName = defaultName;
            name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
        } else {
            name = createQNameCorbaNamespace(schematypeName.getLocalPart());
        }

        return createUnion(name, (XmlSchemaChoice)complex.getParticle(), defaultName, schematypeName);       
    }
   
    protected Union createUnion(QName name, XmlSchemaChoice choice, QName defaultName,
                                QName schematypeName)
        throws Exception {
        Union corbaUnion = new Union();
        corbaUnion.setName(name.getLocalPart());
        corbaUnion.setQName(name);       
        corbaUnion.setType(schematypeName);
        String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
        corbaUnion.setRepositoryID(id);

        //Set Integer as Discriminator
        corbaUnion.setDiscriminator(CorbaConstants.NT_CORBA_LONG);

        List fields = processContainerAsMembers(choice, defaultName, schematypeName);

        //Choose an Integer as a Discriminator
        List<String> caselist = new ArrayList<String>();       

        for (int i = 0; i < fields.size(); i++) {
            caselist.add(Integer.toString(i));
        }

        return WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);
    }
                      
    protected boolean isDuplicate(CorbaTypeImpl corbaTypeImpl) {       
        String corbaName = corbaTypeImpl.getName();
        QName corbaType = corbaTypeImpl.getType();
       
        QName primName = createQNameXmlSchemaNamespace(corbaName);
        if ((CorbaTypeImpl)CORBAPRIMITIVEMAP.get(primName) != null) {             
            return true;
        }       
        if (!typeMappingType.getStructOrExceptionOrUnion().isEmpty()) {
            Iterator i = typeMappingType.getStructOrExceptionOrUnion().iterator();
            while (i.hasNext()) {
                CorbaTypeImpl type = (CorbaTypeImpl)i.next();
                if ((corbaName != null) && type.getType() != null && corbaType != null
                    && (corbaName.equals(type.getName()))
                    && (corbaType.getLocalPart().equals(type.getType().getLocalPart()))
                    && (corbaTypeImpl.getClass().getName().equals(type.getClass().getName()))) {
                    return true;
                }
            }
        }
        return false;
    }
   
   
    protected CorbaTypeImpl isDuplicateException(CorbaTypeImpl corbaTypeImpl) {
        CorbaTypeImpl duplicate = null;
        String corbaName = corbaTypeImpl.getName();
        String corbaType = corbaTypeImpl.getType().getLocalPart();
        if (!typeMappingType.getStructOrExceptionOrUnion().isEmpty()) {
            Iterator i = typeMappingType.getStructOrExceptionOrUnion().iterator();
            while (i.hasNext()) {
                CorbaTypeImpl type = (CorbaTypeImpl)i.next();
                if (corbaName.equals(type.getName())
                                     && corbaType.equals(type.getType().getLocalPart())) {                   
                    if (type instanceof Struct) {                       
                        return type;
                    }
                }
            }
        }
        return duplicate;
    }
   
    protected QName checkPrefix(QName schematypeName) {
        QName name = schematypeName;
        if ((name != null) && (name.getPrefix() == null || name.getPrefix().equals(""))) {
            String prefix = def.getPrefix(name.getNamespaceURI());
            if (prefix == null) {
                prefix = xmlSchemaType.getNamespaceContext().getPrefix(name.getNamespaceURI());
            }
            if (prefix != null) {
                return new QName(name.getNamespaceURI(),
                                 name.getLocalPart(),
                                 prefix);
            } else {
                return null;
            }
        }
    
        return name;
    }

    public QName createQNameTargetNamespace(String name) {      
        return new QName(def.getTargetNamespace(), name, def.getPrefix(def.getTargetNamespace()));
    }

    public QName createQNameCorbaNamespace(String name) {
        return new QName(getIdlNamespace(), name, def.getPrefix(getIdlNamespace()));
    }

    public QName createQName(String name, String namespaceName, String prefix) {
        return new QName(name, namespaceName, prefix);
    }
   
    public QName createQNameXmlSchemaNamespace(String name) {
        return new QName(W3CConstants.NU_SCHEMA_XSD, name, W3CConstants.NP_SCHEMA_XSD);
    }

    private boolean isIDLObjectType(QName typeName) {
        if (typeName.equals(ReferenceConstants.REFERENCE_TYPE)
            || typeName.equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            return true;
        }

        return false;
    }
   
    private boolean isAddressingNamespace(QName typeName) {
        if ((typeName != null) && (!isIDLObjectType(typeName))) {
            if (typeName.getNamespaceURI().equals(ReferenceConstants.REFERENCE_NAMESPACE)
                || typeName.getNamespaceURI().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
                return true;
            }
        }
        return false;
    }

    protected static boolean queryBinding(Definition definition, QName bqname) {
        Map bindings = definition.getBindings();
        Iterator i = bindings.values().iterator();
        while (i.hasNext()) {
            Binding binding = (Binding)i.next();
            if (binding.getQName().getLocalPart().equals(bqname.getLocalPart())) {
                return true;
            }
        }
        return false;
    }

}
TOP

Related Classes of org.apache.yoko.tools.processors.wsdl.WSDLToCorbaHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.