Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.tuscany.sca.binding.ws.wsdlgen;
 
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
 

Version:
$Rev: 963624 $ $Date: 2010-07-13 10:12:08 +0100 (Tue, 13 Jul 2010) $
 
 public class Interface2WSDLGenerator {
     private static final Logger logger = Logger.getLogger(Interface2WSDLGenerator.class.getName());
     private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
     private static final String SCHEMA_NAME = "schema";
     private static final QName SCHEMA_QNAME = new QName();
     private static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
     
     private static final String ANYTYPE_NAME = "anyType";
     private static final QName ANYTYPE_QNAME = new QName();
 
 
     private WSDLFactory factory;
    private boolean requiresSOAP12;
    private ModelResolver resolver;
    private XSDFactory xsdFactory;
    private Monitor monitor;
    public Interface2WSDLGenerator(boolean requiresSOAP12,
                                   ModelResolver resolver,
                                   DataBindingExtensionPoint dataBindings,
                                   XSDFactory xsdFactory,
                                   DocumentBuilderFactory documentBuilderFactory,
                                   Monitor monitorthrows WSDLException {
        super();
        this. = requiresSOAP12
        this. = resolver;
        this. = documentBuilderFactory;
         = new WSDLDefinitionGenerator(requiresSOAP12);
        this. = dataBindings;
        this. = xsdFactory;
        this. = monitor;
        this. = WSDLFactory.newInstance();
    }

    
Log a warning message.

Parameters:
problem
    private static void logWarning(Problem problem) {
        Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getResourceBundleName());
        if (problemLogger != null){
            problemLogger.logp(.problem.getSourceClassName(), nullproblem.getMessageId(), problem.getMessageParams());
        } else {
            .severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getResourceBundleName());
        }
    }

    
Report a warning.

Parameters:
message
binding
parameters
    private void warning(String messageInterface interfazeString... messageParameters) {
        Problem problem = .createProblem(this.getClass().getName(), "wsdlgen-validation-messages".interfazemessage, (Object[])messageParameters);
        if ( != null) {
            .problem(problem);
        } else {
            logWarning(problem);
        }
    }

    
Report a fatal error.

Parameters:
message
binding
parameters
    private void fatal(String messageInterface interfazeString... messageParameters) {
        Problem problem = .createProblem(this.getClass().getName(), "wsdlgen-validation-messages".interfazemessage, (Object[])messageParameters);
        throw new WSDLGenerationException(problem.toString(), nullproblem);
    }
    
    private XMLTypeHelper getTypeHelper(DataType typeMap<StringXMLTypeHelperhelpers) {
        if (type == null) {
            return null;
        }
        String db = type.getDataBinding();
        if (db == null) {
            return null;
        }
        if ("java:array".equals(db)) {
            DataType dt = (DataType)type.getLogical();
            db = dt.getDataBinding();
        }
        return helpers.get(db);
    }
    
    private boolean inputTypesCompatible(DataType wrapperTypeDataType<List<DataType>> inputTypeMap<StringXMLTypeHelperhelpers) {
        XMLTypeHelper wrapperHelper = getTypeHelper(wrapperTypehelpers);
        for (DataType dt : inputType.getLogical()) {
            if (getTypeHelper(dthelpers) != wrapperHelper) {
                return false;
            }
        }
        return true;
    }
    
    private boolean outputTypeCompatible(DataType wrapperTypeDataType outputTypeMap<StringXMLTypeHelperhelpers) {
        if (getTypeHelper(outputTypehelpers) != getTypeHelper(wrapperTypehelpers)) {
            return false;
        } else {
            return true;
        }
    }
    
    private void addDataType(Map<XMLTypeHelperList<DataType>> mapDataType typeMap<StringXMLTypeHelperhelpers) {
        if (type == null) {
            return;
        }
        String db = type.getDataBinding();
        if (db == null) {
            return;
        }
        if ("java:array".equals(db)) {
            DataType dt = (DataType)type.getLogical();
            db = dt.getDataBinding();
        }
        XMLTypeHelper helper = helpers.get(db);
        List<DataTypetypes = map.get(helper);
        if (types == null) {
            types = new ArrayList<DataType>();
            map.put(helpertypes);
        }
        types.add(type);
    }
    
    private Map<XMLTypeHelperList<DataType>> getDataTypes(Interface intfboolean useWrapperMap<StringXMLTypeHelperhelpers) {
        Map<XMLTypeHelperList<DataType>> dataTypes = new HashMap<XMLTypeHelperList<DataType>>();
        for (Operation op : intf.getOperations()) {
            WrapperInfo wrapper = op.getWrapper();
            DataType dt1 = null;
            boolean useInputWrapper = useWrapper & wrapper != null;
            if (useInputWrapper) {
                dt1 = wrapper.getInputWrapperType();
                useInputWrapper &= inputTypesCompatible(dt1op.getInputType(), helpers);
            }
            if (useInputWrapper) {
                addDataType(dataTypesdt1helpers);
            } else {
                for (DataType dt : op.getInputType().getLogical()) {
                    addDataType(dataTypesdthelpers);
                }
            }
            
            DataType dt2 = null;
            boolean useOutputWrapper = useWrapper & wrapper != null;
            if (useOutputWrapper) {
                dt2 = wrapper.getOutputWrapperType();
                useOutputWrapper &= outputTypeCompatible(dt2op.getOutputType(), helpers);
            }
            if (useOutputWrapper) {
                addDataType(dataTypesdt2helpers);
            } else {
                dt2 = op.getOutputType();
                addDataType(dataTypesdt2helpers);
            }
            
            for (DataType<DataTypedt3 : op.getFaultTypes()) {
                DataType dt4 = dt3.getLogical();
                addDataType(dataTypesdt4helpers);
            }
        }
        // Adding classes referenced by @XmlSeeAlso in the java interface
        if (intf instanceof JavaInterface) {
            JavaInterface javaInterface = (JavaInterface)intf;
            Class<?>[] seeAlso = getSeeAlso(javaInterface.getJavaClass());
            if (seeAlso != null) {
                for (Class<?> cls : seeAlso) {
                    DataType dt = new DataTypeImpl<XMLType>(.cls.);
                    addDataType(dataTypesdthelpers);
                }
            }
            seeAlso = getSeeAlso(javaInterface.getCallbackClass());
            if (seeAlso != null) {
                for (Class<?> cls : seeAlso) {
                    DataType dt = new DataTypeImpl<XMLType>(.cls.);
                    addDataType(dataTypesdthelpers);
                }
            }
        }
        return dataTypes;
    }
    
    private static Class<?>[] getSeeAlso(Class<?> interfaze) {
        if (interfaze == null) {
            return null;
        }
        XmlSeeAlso seeAlso = interfaze.getAnnotation(XmlSeeAlso.class);
        if (seeAlso == null) {
            return null;
        } else {
            return seeAlso.value();
        }
    }
    public Definition generate(Interface interfazeWSDLDefinition wsdlDefinitionthrows WSDLException {
        if (interfaze == null) {
            return null;
        }
        if (interfaze instanceof WSDLInterface) {
            return ((WSDLInterface)interfaze).getWsdlDefinition().getDefinition();
        }
        JavaInterface iface = (JavaInterface)interfaze;
        if (!interfaze.isRemotable()) {
            fatal("InterfaceNotRemotable"interfazeiface.getName());
        }
        QName name = getQName(iface);
        Definition definition = .newDefinition();
        if () {
            definition.addNamespace("SOAP12""http://schemas.xmlsoap.org/wsdl/soap12/");
        } else {
            definition.addNamespace("SOAP""http://schemas.xmlsoap.org/wsdl/soap/");
        }
        definition.addNamespace("wsdl""http://schemas.xmlsoap.org/wsdl/");
        definition.addNamespace("xs");
        String namespaceURI = name.getNamespaceURI();
        definition.setTargetNamespace(namespaceURI);
        definition.setQName(new QName(namespaceURIname.getLocalPart() + "Service"name.getPrefix()));
        definition.addNamespace(name.getPrefix(), namespaceURI);
        PortType portType = definition.createPortType();
        portType.setQName(name);
        Binding binding = .createBinding(definitionportType);
        Map<StringXMLTypeHelperhelpers = new HashMap<StringXMLTypeHelper>();
        Map<QNameList<ElementInfo>> wrappers = new HashMap<QNameList<ElementInfo>>();
        for (Operation op : interfaze.getOperations()) {
            javax.wsdl.Operation operation = generateOperation(definitionophelperswrappers);
            portType.addOperation(operation);
            String action = ((JavaOperation)op).getAction();
            if ((action == null || "".equals(action)) && !op.isWrapperStyle() && op.getWrapper() == null) {
                // Bare style
                action = "urn:" + op.getName();
            }
            BindingOperation bindingOp = .createBindingOperation(definitionoperationaction);
            binding.addBindingOperation(bindingOp);
        }
        portType.setUndefined(false);
        definition.addPortType(portType);
        binding.setUndefined(false);
        definition.addBinding(binding);
        wsdlDefinition.setBinding(binding);
        // call each helper in turn to populate the wsdl.types element
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); 
        for (Map.Entry<XMLTypeHelperList<DataType>> engetDataTypes(interfazefalsehelpers).entrySet()) {
            XMLTypeHelper helper = en.getKey();
            if (helper == null) {
                continue;
            }
            List<XSDefinitionxsDefinitions = helper.getSchemaDefinitions(en.getValue());
            for (XSDefinition xsDefxsDefinitions) {
                addSchemaExtension(xsDefschemaCollectionwsdlDefinitiondefinition);
            }
        }
        // remove global wrapper elements with schema definitions from generation list
        for (QName wrapperNamenew HashSet<QName>(wrappers.keySet())) {
            if (wsdlDefinition.getXmlSchemaElement(wrapperName) != null) {
                wrappers.remove(wrapperName);
            }
        }
        // generate schema elements for wrappers that aren't defined in the schemas
        if (wrappers.size() > 0) {
            int i = 0;
            int index = 0;
            Map<StringXSDefinitionwrapperXSDs = new HashMap<StringXSDefinition>();
            Map<ElementMap<StringString>> prefixMaps = new HashMap<ElementMap<StringString>>();
            for (Map.Entry<QNameList<ElementInfo>> entrywrappers.entrySet()) {
                String targetNS = entry.getKey().getNamespaceURI();
                Document schemaDoc = null;
                Element schema = null;
                XSDefinition xsDef = wrapperXSDs.get(targetNS);
                if (xsDef != null) {
                    schemaDoc = xsDef.getDocument();
                    schema = schemaDoc.getDocumentElement();
                } else {
                    schemaDoc = createDocument();
                    schema = schemaDoc.createElementNS("xs:schema");
                    // The elementFormDefault should be set to unqualified, see TUSCANY-2388
                    schema.setAttribute("elementFormDefault""unqualified");
                    schema.setAttribute("attributeFormDefault""qualified");
                    schema.setAttribute("targetNamespace"targetNS);
                    schema.setAttributeNS("xmlns:xs");
                    schemaDoc.appendChild(schema);
                    Schema schemaExt = createSchemaExt(definition);
                    schemaExt.setElement(schema);
                    prefixMaps.put(schemanew HashMap<StringString>());
                    xsDef = .createXSDefinition();
                    xsDef.setUnresolved(true);
                    xsDef.setNamespace(targetNS);
                    xsDef.setDocument(schemaDoc);
                    // TUSCANY-2465: Set the system id to avoid schema conflict
                    xsDef.setLocation(URI.create("xsd_" + index + ".xsd"));
                    index++;
                    wrapperXSDs.put(targetNSxsDef);
                }
                Element wrapper = schemaDoc.createElementNS("xs:element");
                schema.appendChild(wrapper);
                wrapper.setAttribute("name"entry.getKey().getLocalPart());
                if (entry.getValue().size() == 1 && entry.getValue().get(0).getQName() == null) {
                    // special case for global fault element
                    QName typeName = entry.getValue().get(0).getType().getQName();
                    String nsURI = typeName.getNamespaceURI();
                    if ("".equals(nsURI)) {
                        wrapper.setAttribute("type"typeName.getLocalPart());
                        addSchemaImport(schema""schemaDoc);
                    } else if (targetNS.equals(nsURI)) {
                        wrapper.setAttribute("type"typeName.getLocalPart());
                    } else if (.equals(nsURI)) {
                        wrapper.setAttribute("type""xs:" + typeName.getLocalPart());
                    } else {
                        Map<StringStringprefixMap = prefixMaps.get(schema);
                        String prefix = prefixMap.get(nsURI);
                        if (prefix == null) {
                            prefix = "ns" + i++;
                            prefixMap.put(nsURIprefix);
                            schema.setAttributeNS("xmlns:" + prefixnsURI);
                            addSchemaImport(schemansURIschemaDoc);
                        }
                        wrapper.setAttribute("type"prefix + ":" + typeName.getLocalPart());
                    }                    
                } else {
                    // normal wrapper containing type definition inline
                    Element complexType = schemaDoc.createElementNS("xs:complexType");
                    wrapper.appendChild(complexType);
                    if (entry.getValue().size() > 0) {
                        Element sequence = schemaDoc.createElementNS("xs:sequence");
                        complexType.appendChild(sequence);
                        for (ElementInfo elemententry.getValue()) {
                            Element xsElement = schemaDoc.createElementNS("xs:element"); 
                            if (element.isMany()) {
                                xsElement.setAttribute("maxOccurs""unbounded");
                            }
                            xsElement.setAttribute("minOccurs""0");
                            xsElement.setAttribute("name"element.getQName().getLocalPart());
                            if (element.isNillable()) {
                                xsElement.setAttribute("nillable""true");
                            }
                            QName typeName = element.getType().getQName();
                            String nsURI = typeName.getNamespaceURI();
                            if ("".equals(nsURI)) {
                                xsElement.setAttribute("type"typeName.getLocalPart());
                                addSchemaImport(schema""schemaDoc);
                            } else if (.equals(nsURI)) {
                                xsElement.setAttribute("type""xs:" + typeName.getLocalPart());
                            } else {
                                Map<StringStringprefixMap = prefixMaps.get(schema);
                                String prefix = prefixMap.get(nsURI);
                                if (prefix == null) {
                                    if (targetNS.equals(nsURI)) {
									    prefix = "tns";
else {
                                        prefix = "ns" + i++;
                                        addSchemaImport(schemansURIschemaDoc);
									}
                                    prefixMap.put(nsURIprefix);
                                    schema.setAttributeNS("xmlns:" + prefixnsURI);
                                }
                                xsElement.setAttribute("type"prefix + ":" + typeName.getLocalPart());
                            }
                            sequence.appendChild(xsElement);
                        }
                    }
                }
            }
 
            // resolve XSDefinitions containing generated wrappers
            for (XSDefinition xsDefwrapperXSDs.values()) {
                loadXSD(schemaCollectionxsDef);
                wsdlDefinition.getXmlSchemas().add(xsDef);
            }
        }
        return definition;
    }
    private static void addSchemaImport(Element schemaString nsURIDocument schemaDoc) {
        Element imp = schemaDoc.createElementNS("xs:import");
        if (!"".equals(nsURI)) {
            imp.setAttribute("namespace"nsURI);
        }
        // Scan all xs:import elements to match namespace
        NodeList childNodes = schema.getElementsByTagNameNS("import");
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            if (childNode instanceof Element) {
                String ns = ((Element)childNode).getAttributeNS("namespace");
                if (nsURI.equals(ns)) {
                    // The xs:import with the same namespace has been declared
                    return;
                }
            }
        }
        // Try to find the first node after the import elements
        Node firstNodeAfterImport = null;
        if (childNodes.getLength() > 0) {
            firstNodeAfterImport = childNodes.item(childNodes.getLength() - 1).getNextSibling();
        } else {
            firstNodeAfterImport = schema.getFirstChild();
        }
        if (firstNodeAfterImport == null) {
            schema.appendChild(imp);
        } else {
            schema.insertBefore(impfirstNodeAfterImport);
        }
    }
    private void addSchemaExtension(XSDefinition xsDef,
                                    XmlSchemaCollection schemaCollection,
                                    WSDLDefinition wsdlDefinition,
                                    Definition definitionthrows WSDLException {
        if (xsDef.getAggregatedDefinitions() != null) {
            for (XSDefinition xsdxsDef.getAggregatedDefinitions()) {
                addSchemaExtension(xsdschemaCollectionwsdlDefinitiondefinition);
            }
        } else {
            String nsURI = xsDef.getNamespace();
            Document document = xsDef.getDocument();
            if (document == null) {
                try {
                    NamespaceMap prefixMap = new NamespaceMap();
                    prefixMap.add("xs");
                    prefixMap.add("tns"nsURI);
                    XmlSchema schemaDef = xsDef.getSchema();
                    schemaDef.setNamespaceContext(prefixMap);
                    Document[] docs = schemaDef.getAllSchemas();
                    document = docs[docs.length-1];
                    document.setDocumentURI(xsDef.getLocation().toString());
                    xsDef.setDocument(document);
                } catch (XmlSchemaException e) {
                    throw new RuntimeException(e);
                }
            }
            loadXSD(schemaCollectionxsDef);
            wsdlDefinition.getXmlSchemas().add(xsDef);
            Element schema = document.getDocumentElement();
            Schema schemaExt = createSchemaExt(definition);
            schemaExt.setDocumentBaseURI(document.getDocumentURI());
            schemaExt.setElement(schema);
        }
    }
    private static void loadXSD(XmlSchemaCollection schemaCollectionXSDefinition definition) {
        if (definition.getSchema() != null) {
            return;
        }
        if (definition.getDocument() != null) {
            String uri = null;
            if (definition.getLocation() != null) {
                uri = definition.getLocation().toString();
            }
            XmlSchema schema = schemaCollection.read(definition.getDocument(), urinull);
            if (definition.getSchemaCollection() == null) {
                definition.setSchemaCollection(schemaCollection);
            }
            if (definition.getSchema() == null) {
                definition.setSchema(schema);
            }
        }
    }
    public Schema createSchemaExt(Definition definitionthrows WSDLException {
        Types types = definition.getTypes();
        if (types == null) {
            types = definition.createTypes();
            definition.setTypes(types);
        }
        Schema schemaExt = createSchema(definition);
        types.addExtensibilityElement(schemaExt);
        return schemaExt;
    }
    public Schema createSchema(Definition definitionthrows WSDLException {
        return (Schema)definition.getExtensionRegistry().createExtension(Types.class);
    }
    public Document createDocument() {
        Document document;
        try {
            if ( == null) {
                 = DocumentBuilderFactory.newInstance();
                .setNamespaceAware(true);
            }
            document = .newDocumentBuilder().newDocument();
        } catch (ParserConfigurationException ex) {
            throw new WSDLGenerationException(ex);
         }
        // document.setDocumentURI("http://");
        return document;
    }
    protected QName getQName(Interface interfaze) {
        JavaInterface iface = (JavaInterface)interfaze;
        QName qname = iface.getQName();
        if (qname != null) {
            return qname;
        } else {
            Class<?> javaClass = iface.getJavaClass();
            return new QName(JavaXMLMapper.getNamespace(javaClass), javaClass.getSimpleName(), "tns");
        }
    }
    public javax.wsdl.Operation generateOperation(Definition definition,
                                                  Operation op,
                                                  Map<StringXMLTypeHelperhelpers,
                                                  Map<QNameList<ElementInfo>> wrappers)
                                              throws WSDLException {
        javax.wsdl.Operation operation = definition.createOperation();
        operation.setName(op.getName());
        operation.setUndefined(false);
        Input input = definition.createInput();
        Message inputMsg = definition.createMessage();
        String namespaceURI = definition.getQName().getNamespaceURI();
        QName inputMsgName = new QName(namespaceURIop.getName());
        inputMsg.setQName(inputMsgName);
        inputMsg.setUndefined(false);
        definition.addMessage(inputMsg);
        List<ElementInfoelements = null;
        // FIXME: By default, java interface is mapped to doc-lit-wrapper style WSDL
        if (op.getWrapper() != null) {
            // Generate doc-lit-wrapper style
            inputMsg.addPart(generateWrapperPart(definitionophelperswrapperstrue));
        } else {
            // Bare style
            int i = 0;
            for (DataType d : op.getInputType().getLogical()) {
                inputMsg.addPart(generatePart(definitiond"arg" + i));
                elements = new ArrayList<ElementInfo>();
                ElementInfo element = getElementInfo(d.getPhysical(), dnullhelpers);
                elements.add(element);
                QName elementName = ((XMLType)d.getLogical()).getElementName();
                wrappers.put(elementNameelements);
                i++;
            }
        }
        input.setMessage(inputMsg);
        operation.setInput(input);
        if (!op.isNonBlocking()) {
            Output output = definition.createOutput();
            Message outputMsg = definition.createMessage();
            QName outputMsgName = new QName(namespaceURIop.getName() + "Response");
            outputMsg.setQName(outputMsgName);
            outputMsg.setUndefined(false);
            definition.addMessage(outputMsg);
            if (op.getWrapper() != null) {
                outputMsg.addPart(generateWrapperPart(definitionophelperswrappersfalse));
            } else {
                DataType outputType = op.getOutputType();
                if (outputType != null) {
                    outputMsg.addPart(generatePart(definitionoutputType"return"));
                    elements = new ArrayList<ElementInfo>();
                    ElementInfo element = getElementInfo(outputType.getPhysical(), outputTypenullhelpers);
                    elements.add(element);
                    QName elementName = ((XMLType)outputType.getLogical()).getElementName();
                    wrappers.put(elementNameelements);
                }
            }
            output.setMessage(outputMsg);
            operation.setOutput(output);
            operation.setStyle(.);
        } else {
            operation.setStyle(.);
        }
        for (DataType<DataTypefaultTypeop.getFaultTypes()) {
            Fault fault = definition.createFault();
            QName faultName = ((XMLType)faultType.getLogical().getLogical()).getElementName();
            fault.setName(faultName.getLocalPart());
            Message faultMsg = definition.getMessage(faultName);
            if (faultMsg == null) {
                faultMsg = definition.createMessage();
                faultMsg.setQName(faultName);
                faultMsg.setUndefined(false);
                definition.addMessage(faultMsg);
                faultMsg.addPart(generatePart(definitionfaultType.getLogical(), faultName.getLocalPart()));
            }
            fault.setMessage(faultMsg);
            operation.addFault(fault);
            if (faultType.getLogical().getPhysical() != faultType.getPhysical()) {
                // create special wrapper for type indirection to real fault bean
                DataType logical = faultType.getLogical();
                elements = new ArrayList<ElementInfo>();
                elements.add(getElementInfo(logical.getPhysical(), logicalnullhelpers));
             } else {
                // convert synthesized fault bean to a wrapper type
                for (DataType<XMLTypepropDTop.getFaultBeans().get(faultName)) {
                    XMLType logical = propDT.getLogical();
                    elements = new ArrayList<ElementInfo>();
                    elements.add(getElementInfo(propDT.getPhysical(), propDTlogical.getElementName(), helpers));
                }
            }
            wrappers.put(faultNameelements);
        }
        operation.setUndefined(false);
        return operation;
    }
    public Part generatePart(Definition definitionDataType argString partName) {
        Part part = definition.createPart();
        part.setName(partName);
        if (arg != null && arg.getLogical() instanceof XMLType) {
            XMLType xmlType = (XMLType)arg.getLogical();
            QName elementName = xmlType.getElementName();
            part.setElementName(elementName);
            addNamespace(definitionelementName);
            if (xmlType.getElementName() == null) {
                QName typeName = xmlType.getTypeName();
                part.setTypeName(typeName);
                addNamespace(definitiontypeName);
            }
        }
        return part;
    }
    public Part generateWrapperPart(Definition definition,
                                    Operation operation,
                                    Map<StringXMLTypeHelperhelpers
                                    Map<QNameList<ElementInfo>> wrappers,
                                    boolean inputthrows WSDLException {
        Part part = definition.createPart();
        String partName = input ? operation.getName() : (operation.getName() + "Response");
        part.setName(partName);
        WrapperInfo opWrapper = operation.getWrapper();
        if (opWrapper != null) {
            ElementInfo elementInfo =
                input ? opWrapper.getInputWrapperElement() : opWrapper.getOutputWrapperElement();
            List<ElementInfoelements =
                input ? opWrapper.getInputChildElements() : opWrapper.getOutputChildElements();
            QName wrapperName = elementInfo.getQName();
            part.setElementName(wrapperName);
            addNamespace(definitionwrapperName);
            wrappers.put(wrapperNameelements);
            // FIXME: [rfeng] Ideally, we should try to register the wrappers only. But we are
            // expriencing the problem that we cannot handle XSD imports 
            /*
            Class<?> wrapperClass = input ? opWrapper.getInputWrapperClass() : opWrapper.getOutputWrapperClass();
            DataType wrapperDT = input ? opWrapper.getInputWrapperType() : opWrapper.getOutputWrapperType();
            if (wrapperClass != null) {
                getElementInfo(wrapperClass, wrapperDT, wrapperName, helpers);
                return part;
            }
            */
            Method method = ((JavaOperation)operation).getJavaMethod();
            if (input) {
                Class<?>[] paramTypes = method.getParameterTypes();
                for (int i = 0; i < paramTypes.lengthi++) {
                    DataType dataType = operation.getInputType().getLogical().get(i);
                    elements.set(igetElementInfo(paramTypes[i], dataTypeelements.get(i).getQName(), helpers));
                }
            } else {
                Class<?> returnType = method.getReturnType();
                if (returnType != .) {
                    DataType dataType = operation.getOutputType();
                    elements.set(0, getElementInfo(returnTypedataTypeelements.get(0).getQName(), helpers));
                }
            }
        }
        return part;
    }
    private ElementInfo getElementInfo(Class javaType,
                                       DataType dataType,
                                       QName name,
                                       Map<StringXMLTypeHelperhelpers) {
        String db = dataType.getDataBinding();
        while ("java:array".equals(db)) {
            dataType = (DataType)dataType.getLogical();
            db = dataType.getDataBinding();
        }
        XMLTypeHelper helper = helpers.get(db);
        if (helper == null) {
            DataBinding dataBinding = .getDataBinding(db);
            if (dataBinding == null) {
                QName element = name;
                if (element == null || dataType.getLogical() instanceof XMLType) {
                    XMLType xmlType = (XMLType)dataType.getLogical();
                    if (xmlType.getElementName() != null) {
                        element = xmlType.getElementName();
                    }
                }
                return new ElementInfo(elementnew TypeInfo(falsenull));
                // throw new ServiceRuntimeException("No data binding for " + db);
            }
            helper = dataBinding.getXMLTypeHelper();
            if (helper == null) {
                // Default to JAXB
                helper = helpers.get(.);
                if (helper == null) {
                    helper = .getDataBinding(.).getXMLTypeHelper();
                    helpers.put(.helper);
                }
            }
            helpers.put(dbhelper);
        }
        // TUSCANY-3616 - don't revert a byte[] to a byte type but retain the mapping to base64Binary
        //                which is carried in the dataType and the original javaType
        TypeInfo typeInfo = null;
        ElementInfo element = null;
        if (byte[].class == javaType){
            typeInfo = helper.getTypeInfo(javaTypedataType.getLogical());
            element = new ElementInfo(nametypeInfo);
            element.setMany(false);
        } else {
            typeInfo = helper.getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaTypedataType.getLogical());
            element = new ElementInfo(nametypeInfo);
            element.setMany(javaType.isArray());
        }
        element.setNillable(!javaType.isPrimitive());
        return element;
    }
    private static void addNamespace(Definition definitionQName name) {
        String namespace = name.getNamespaceURI();
        if (definition.getPrefix(namespace) == null) {
            definition.addNamespace("ns" + definition.getNamespaces().size(), namespace);
        }
    }
    /*
    // currently not using the next three methods
    public XmlSchemaType getXmlSchemaType(DataType type) {
        return null;
    }
    // FIXME: WE need to add databinding-specific Java2XSD generation
    public Element generateXSD(DataType dataType) {
        DataBinding dataBinding = dataBindings.getDataBinding(dataType.getDataBinding());
        if (dataBinding != null) {
            // return dataBinding.generateSchema(dataType);
        }
        return null;
    }
    public void generateWrapperElements(Operation op) {
        XmlSchemaCollection collection = new XmlSchemaCollection();
        String ns = getQName(op.getInterface()).getNamespaceURI();
        XmlSchema schema = new XmlSchema(ns, collection);
        schema.setAttributeFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
        schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
        XmlSchemaElement inputElement = new XmlSchemaElement();
        inputElement.setQName(new QName(ns, op.getName()));
        XmlSchemaComplexType inputType = new XmlSchemaComplexType(schema);
        inputType.setName("");
        XmlSchemaSequence inputSeq = new XmlSchemaSequence();
        inputType.setParticle(inputSeq);
        List<DataType> argTypes = op.getInputType().getLogical();
        for (DataType argType : argTypes) {
            XmlSchemaElement child = new XmlSchemaElement();
            Object logical = argType.getLogical();
            if (logical instanceof XMLType) {
                child.setName(((XMLType)logical).getElementName().getLocalPart());
                XmlSchemaType type = getXmlSchemaType(argType);
                child.setType(type);
            }
            inputSeq.getItems().add(child);
        }
        inputElement.setType(inputType);
        XmlSchemaElement outputElement = new XmlSchemaElement();
        outputElement.setQName(new QName(ns, op.getName() + "Response"));
        XmlSchemaComplexType outputType = new XmlSchemaComplexType(schema);
        outputType.setName("");
        XmlSchemaSequence outputSeq = new XmlSchemaSequence();
        outputType.setParticle(outputSeq);
        DataType returnType = op.getOutputType();
        XmlSchemaElement child = new XmlSchemaElement();
        Object logical = returnType.getLogical();
        if (logical instanceof XMLType) {
            child.setName(((XMLType)logical).getElementName().getLocalPart());
            XmlSchemaType type = getXmlSchemaType(returnType);
            child.setType(type);
        }
        outputSeq.getItems().add(child);
        outputElement.setType(outputType);
        schema.getElements().add(inputElement.getQName(), inputElement);
        schema.getElements().add(outputElement.getQName(), outputElement);
    }
    */
    public WSDLFactory getFactory() {
        return ;
    }
    public void setFactory(WSDLFactory factory) {
        this. = factory;
    }