Example usage for org.w3c.dom Document createElementNS

List of usage examples for org.w3c.dom Document createElementNS

Introduction

In this page you can find the example usage for org.w3c.dom Document createElementNS.

Prototype

public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException;

Source Link

Document

Creates an element of the given qualified name and namespace URI.

Usage

From source file:org.alfresco.web.forms.XSLTRenderingEngine.java

/**
 * Adds the specified parameters to the xsl template as variables within the 
 * alfresco namespace.//w  ww .  j  a v  a 2s  . c om
 *
 * @param model the variables to place within the xsl template
 * @param xslTemplate the xsl template
 */
protected void addParameters(final Map<QName, Object> model, final Document xslTemplate) {
    final Element docEl = xslTemplate.getDocumentElement();
    final String XSL_NS = docEl.getNamespaceURI();
    final String XSL_NS_PREFIX = docEl.getPrefix();

    for (Map.Entry<QName, Object> e : model.entrySet()) {
        if (RenderingEngine.ROOT_NAMESPACE.equals(e.getKey())) {
            continue;
        }
        final Element el = xslTemplate.createElementNS(XSL_NS, XSL_NS_PREFIX + ":variable");
        el.setAttribute("name", e.getKey().toPrefixString());
        final Object o = e.getValue();
        if (o instanceof String || o instanceof Number || o instanceof Boolean) {
            el.appendChild(xslTemplate.createTextNode(o.toString()));
            docEl.insertBefore(el, docEl.getFirstChild());
        }
    }
}

From source file:org.apache.axis.handlers.BasicHandler.java

public Element getDeploymentData(Document doc) {
    log.debug("Enter: BasicHandler::getDeploymentData");

    Element root = doc.createElementNS("", "handler");

    root.setAttribute("class", this.getClass().getName());
    options = this.getOptions();
    if (options != null) {
        Enumeration e = options.keys();
        while (e.hasMoreElements()) {
            String k = (String) e.nextElement();
            Object v = options.get(k);
            Element e1 = doc.createElementNS("", "option");
            e1.setAttribute("name", k);
            e1.setAttribute("value", v.toString());
            root.appendChild(e1);/*from  w  ww . jav a  2 s. c o  m*/
        }
    }
    log.debug("Exit: BasicHandler::getDeploymentData");
    return (root);
}

From source file:org.apache.axis.handlers.JWSHandler.java

/**
 * If our path ends in the right file extension (*.jws), handle all the
 * work necessary to compile the source file if it needs it, and set
 * up the "proxy" RPC service surrounding it as the MessageContext's
 * active service./*ww w .  j  a v a 2 s .  c o m*/
 *
 */
protected void setupService(MessageContext msgContext) throws Exception {
    // FORCE the targetService to be JWS if the URL is right.
    String realpath = msgContext.getStrProp(Constants.MC_REALPATH);
    String extension = (String) getOption(OPTION_JWS_FILE_EXTENSION);
    if (extension == null)
        extension = DEFAULT_JWS_FILE_EXTENSION;

    if ((realpath != null) && (realpath.endsWith(extension))) {
        /* Grab the *.jws filename from the context - should have been */
        /* placed there by another handler (ie. HTTPActionHandler)     */
        /***************************************************************/
        String jwsFile = realpath;
        String rel = msgContext.getStrProp(Constants.MC_RELATIVE_PATH);

        // Check for file existance, report error with
        // relative path to avoid giving out directory info.
        File f2 = new File(jwsFile);
        if (!f2.exists()) {
            throw new FileNotFoundException(rel);
        }

        if (rel.charAt(0) == '/') {
            rel = rel.substring(1);
        }

        int lastSlash = rel.lastIndexOf('/');
        String dir = null;

        if (lastSlash > 0) {
            dir = rel.substring(0, lastSlash);
        }

        String file = rel.substring(lastSlash + 1);

        String outdir = msgContext.getStrProp(Constants.MC_JWS_CLASSDIR);
        if (outdir == null)
            outdir = ".";

        // Build matching directory structure under the output
        // directory.  In other words, if we have:
        //    /webroot/jws1/Foo.jws
        //
        // That will be compiled to:
        //    .../jwsOutputDirectory/jws1/Foo.class
        if (dir != null) {
            outdir = outdir + File.separator + dir;
        }

        // Confirm output directory exists.  If not, create it IF we're
        // allowed to.
        // !!! TODO: add a switch to control this.
        File outDirectory = new File(outdir);
        if (!outDirectory.exists()) {
            outDirectory.mkdirs();
        }

        if (log.isDebugEnabled())
            log.debug("jwsFile: " + jwsFile);

        String jFile = outdir + File.separator + file.substring(0, file.length() - extension.length() + 1)
                + "java";
        String cFile = outdir + File.separator + file.substring(0, file.length() - extension.length() + 1)
                + "class";

        if (log.isDebugEnabled()) {
            log.debug("jFile: " + jFile);
            log.debug("cFile: " + cFile);
            log.debug("outdir: " + outdir);
        }

        File f1 = new File(cFile);

        /* Get the class */
        /*****************/
        String clsName = null;
        //clsName = msgContext.getStrProp(Constants.MC_RELATIVE_PATH);
        if (clsName == null)
            clsName = f2.getName();
        if (clsName != null && clsName.charAt(0) == '/')
            clsName = clsName.substring(1);

        clsName = clsName.substring(0, clsName.length() - extension.length());
        clsName = clsName.replace('/', '.');

        if (log.isDebugEnabled())
            log.debug("ClsName: " + clsName);

        /* Check to see if we need to recompile */
        /****************************************/
        if (!f1.exists() || f2.lastModified() > f1.lastModified()) {
            /* If the class file doesn't exist, or it's older than the */
            /* java file then recompile the java file.                 */
            /* Start by copying the *.jws file to *.java               */
            /***********************************************************/
            log.debug(Messages.getMessage("compiling00", jwsFile));
            log.debug(Messages.getMessage("copy00", jwsFile, jFile));
            FileReader fr = new FileReader(jwsFile);
            FileWriter fw = new FileWriter(jFile);
            char[] buf = new char[4096];
            int rc;
            while ((rc = fr.read(buf, 0, 4095)) >= 0)
                fw.write(buf, 0, rc);
            fw.close();
            fr.close();

            /* Now run javac on the *.java file */
            /************************************/
            log.debug("javac " + jFile);
            // Process proc = rt.exec( "javac " + jFile );
            // proc.waitFor();
            Compiler compiler = CompilerFactory.getCompiler();

            compiler.setClasspath(ClasspathUtils.getDefaultClasspath(msgContext));
            compiler.setDestination(outdir);
            compiler.addFile(jFile);

            boolean result = compiler.compile();

            /* Delete the temporary *.java file and check return code */
            /**********************************************************/
            (new File(jFile)).delete();

            if (!result) {
                /* Delete the *class file - sometimes it gets created even */
                /* when there are errors - so erase it so it doesn't       */
                /* confuse us.                                             */
                /***********************************************************/
                (new File(cFile)).delete();

                Document doc = XMLUtils.newDocument();

                Element root = doc.createElementNS("", "Errors");
                StringBuffer message = new StringBuffer("Error compiling ");
                message.append(jFile);
                message.append(":\n");

                List errors = compiler.getErrors();
                int count = errors.size();
                for (int i = 0; i < count; i++) {
                    CompilerError error = (CompilerError) errors.get(i);
                    if (i > 0)
                        message.append("\n");
                    message.append("Line ");
                    message.append(error.getStartLine());
                    message.append(", column ");
                    message.append(error.getStartColumn());
                    message.append(": ");
                    message.append(error.getMessage());
                }
                root.appendChild(doc.createTextNode(message.toString()));
                throw new AxisFault("Server.compileError", Messages.getMessage("badCompile00", jFile), null,
                        new Element[] { root });
            }
            ClassUtils.removeClassLoader(clsName);
            // And clean out the cached service.
            soapServices.remove(clsName);
        }

        ClassLoader cl = ClassUtils.getClassLoader(clsName);
        if (cl == null) {
            cl = new JWSClassLoader(clsName, msgContext.getClassLoader(), cFile);
        }

        msgContext.setClassLoader(cl);

        /* Create a new RPCProvider - this will be the "service"   */
        /* that we invoke.                                                */
        /******************************************************************/
        // Cache the rpc service created to handle the class.  The cache
        // is based on class name, so only one .jws/.jwr class can be active
        // in the system at a time.
        SOAPService rpc = (SOAPService) soapServices.get(clsName);
        if (rpc == null) {
            rpc = new SOAPService(new RPCProvider());
            rpc.setName(clsName);
            rpc.setOption(RPCProvider.OPTION_CLASSNAME, clsName);
            rpc.setEngine(msgContext.getAxisEngine());

            // Support specification of "allowedMethods" as a parameter.
            String allowed = (String) getOption(RPCProvider.OPTION_ALLOWEDMETHODS);
            if (allowed == null)
                allowed = "*";
            rpc.setOption(RPCProvider.OPTION_ALLOWEDMETHODS, allowed);
            // Take the setting for the scope option from the handler
            // parameter named "scope"
            String scope = (String) getOption(RPCProvider.OPTION_SCOPE);
            if (scope == null)
                scope = Scope.DEFAULT.getName();
            rpc.setOption(RPCProvider.OPTION_SCOPE, scope);

            rpc.getInitializedServiceDesc(msgContext);

            soapServices.put(clsName, rpc);
        }

        // Set engine, which hooks up type mappings.
        rpc.setEngine(msgContext.getAxisEngine());

        rpc.init(); // ??

        // OK, this is now the destination service!
        msgContext.setService(rpc);
    }

    if (log.isDebugEnabled()) {
        log.debug("Exit: JWSHandler::invoke");
    }
}

From source file:org.apache.axis.SimpleChain.java

public Element getDeploymentData(Document doc) {
    if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("enter00", "SimpleChain::getDeploymentData"));
    }/*from ww w  . ja  v a  2s. c  o m*/

    Element root = doc.createElementNS("", "chain");

    StringBuffer str = new StringBuffer();
    int i = 0;
    while (i < handlers.size()) {
        if (i != 0)
            str.append(",");
        Handler h = (Handler) handlers.elementAt(i);
        str.append(h.getName());
        i++;
    }
    if (i > 0) {
        root.setAttribute("flow", str.toString());
    }

    if (options != null) {
        Enumeration e = options.keys();
        while (e.hasMoreElements()) {
            String k = (String) e.nextElement();
            Object v = options.get(k);
            Element e1 = doc.createElementNS("", "option");
            e1.setAttribute("name", k);
            e1.setAttribute("value", v.toString());
            root.appendChild(e1);
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("Exit: SimpleChain::getDeploymentData");
    }

    return (root);
}

From source file:org.apache.axis.utils.Admin.java

protected static Document processWSDD(MessageContext msgContext, AxisEngine engine, Element root)
        throws Exception {
    Document doc = null;

    String action = root.getLocalName();
    if (action.equals("passwd")) {
        String newPassword = root.getFirstChild().getNodeValue();
        engine.setAdminPassword(newPassword);
        doc = XMLUtils.newDocument();//from w ww .  j ava  2s. c o m
        doc.appendChild(root = doc.createElementNS("", "Admin"));
        root.appendChild(doc.createTextNode(Messages.getMessage("done00")));
        return doc;
    }

    if (action.equals("quit")) {
        log.error(Messages.getMessage("quitRequest00"));
        if (msgContext != null) {
            // put a flag into message context so listener will exit after
            // sending response
            msgContext.setProperty(MessageContext.QUIT_REQUESTED, "true");
        }
        doc = XMLUtils.newDocument();
        doc.appendChild(root = doc.createElementNS("", "Admin"));
        root.appendChild(doc.createTextNode(Messages.getMessage("quit00", "")));
        return doc;
    }

    if (action.equals("list")) {
        return listConfig(engine);
    }

    if (action.equals("clientdeploy")) {
        // set engine to client engine
        engine = engine.getClientEngine();
    }

    WSDDDocument wsddDoc = new WSDDDocument(root);
    EngineConfiguration config = engine.getConfig();
    if (config instanceof WSDDEngineConfiguration) {
        WSDDDeployment deployment = ((WSDDEngineConfiguration) config).getDeployment();
        wsddDoc.deploy(deployment);
    }
    engine.refreshGlobalOptions();

    engine.saveConfiguration();

    doc = XMLUtils.newDocument();
    doc.appendChild(root = doc.createElementNS("", "Admin"));
    root.appendChild(doc.createTextNode(Messages.getMessage("done00")));

    return doc;
}

From source file:org.apache.axis.utils.XMLUtils.java

/**
 * Convert a simple string to an element with a text node
 *
 * @param namespace - element namespace/*from w  ww . jav  a 2  s . c  o m*/
 * @param name - element name
 * @param string - value of the text node
 * @return element - an XML Element, null if no element was created
 */
public static Element StringToElement(String namespace, String name, String string) {
    try {
        Document doc = XMLUtils.newDocument();
        Element element = doc.createElementNS(namespace, name);
        Text text = doc.createTextNode(string);
        element.appendChild(text);
        return element;
    } catch (ParserConfigurationException e) {
        // This should not occur
        throw new InternalException(e);
    }
}

From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java

/**
 * Create a schema by looking at the port type
 *
 * @param namespaceURI - namespace of the porttype uri.
 *  we use this only if a user has not specified a namespace in soap:body
 * @param boeListToProcess - List of BindingOperationEntry objects which require wrappering
 *                     //from w w w  . j a va 2  s .c  o m
 * @return null if there is no element
 */
private Map createSchemaForPorttype(String namespaceURI, List boeListToProcess, Map existingSchemaMap) {

    // this map is used to keep the newly added schemas
    Map newSchemaMap = new HashMap();
    // first of all look at the operations list
    // we can return immediately if we get the operations list
    // as empty
    if (boeListToProcess.isEmpty()) {
        return newSchemaMap;
    }

    // loop through the messages. We'll populate thins map with the relevant
    // messages
    // from the operations
    Map messageQnameToMessageMap = new HashMap();
    Map boeToInputMessageMap = new HashMap();
    Map boeToOutputMessageMap = new HashMap();

    // this contains the required namespace imports. the key in this
    // map would be the namaspace URI
    Map namespaceImportsMap = null;
    // list namespace prefix map. This map will include uri -> prefix
    Map namespacePrefixMap = null;

    // //////////////////////////////////////////////////////////////////////////////////////////////////
    // First thing is to populate the message map with the messages to
    // process.
    // //////////////////////////////////////////////////////////////////////////////////////////////////

    // we really need to do this for a single porttype!
    BindingOperationEntry boe;
    for (int k = 0; k < boeListToProcess.size(); k++) {
        boe = (BindingOperationEntry) boeListToProcess.get(k);
        Input input = boe.getBindingOperation().getOperation().getInput();
        Message message;
        if (input != null) {
            message = input.getMessage();
            messageQnameToMessageMap.put(message.getQName(), message);
            boeToInputMessageMap.put(boe, message);
        }

        Output output = boe.getBindingOperation().getOperation().getOutput();
        if (output != null) {
            message = output.getMessage();
            messageQnameToMessageMap.put(message.getQName(), message);
            boeToOutputMessageMap.put(boe, message);
        }

        // we do not want to process fault messages since they can only be used as document type
        // see basic profile 4.4.2
    }

    // find the xsd prefix
    String xsdPrefix = findSchemaPrefix();
    // DOM document that will be the ultimate creator
    Document document = getDOMDocumentBuilder().newDocument();

    Element elementDeclaration;

    //loop through the input op map and generate the elements
    BindingOperationEntry boEntry;
    for (Iterator boeIter = boeToInputMessageMap.keySet().iterator(); boeIter.hasNext();) {

        boEntry = (BindingOperationEntry) boeIter.next();
        elementDeclaration = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
                xsdPrefix + ":" + XML_SCHEMA_ELEMENT_LOCAL_NAME);
        elementDeclaration.setAttribute(XSD_NAME, boEntry.getBindingOperation().getName());

        //when creating the inner complex type we have to find the parts list from the binding input
        BindingInput bindingInput = boEntry.getBindingOperation().getBindingInput();
        Message message = (Message) boeToInputMessageMap.get(boEntry);

        if (bindingInput != null) {

            Collection partsCollection = null;
            if (BINDING_TYPE_SOAP.equals(this.bindingType)) {
                // first see the body parts list
                List bodyPartsList = getPartsListFromSoapBody(bindingInput.getExtensibilityElements());
                partsCollection = message.getOrderedParts(bodyPartsList);
            } else {
                // i.e http binding
                partsCollection = message.getParts().values();
            }

            List parameterOrder = boEntry.getBindingOperation().getOperation().getParameterOrdering();
            namespaceImportsMap = new HashMap();
            namespacePrefixMap = new HashMap();

            Node newComplexType = getNewComplextType(document, xsdPrefix, partsCollection, parameterOrder,
                    false, namespaceImportsMap, namespacePrefixMap, boEntry);

            elementDeclaration.appendChild(newComplexType);
            String namespaceToUse = namespaceURI;

            if (BINDING_TYPE_SOAP.equals(this.bindingType)) {
                String bodyNamespace = getNamespaceFromSoapBody(bindingInput.getExtensibilityElements());
                namespaceToUse = bodyNamespace != null ? bodyNamespace : namespaceURI;
            }

            if (existingSchemaMap.containsKey(namespaceToUse)) {
                // i.e this namespace is already exists with the original wsdl schemas
                addElementToAnExistingSchema((Element) existingSchemaMap.get(namespaceToUse),
                        elementDeclaration, namespacePrefixMap, namespaceImportsMap, namespaceToUse);
            } else if (newSchemaMap.containsKey(namespaceToUse)) {
                // i.e this namespace is with a newly created schema
                addElementToAnExistingSchema((Element) newSchemaMap.get(namespaceToUse), elementDeclaration,
                        namespacePrefixMap, namespaceImportsMap, namespaceToUse);
            } else {
                // i.e this element namespace has not found yet so
                // we have to create new schema for it
                Element newSchema = createNewSchemaWithElement(elementDeclaration, namespacePrefixMap,
                        namespaceImportsMap, namespaceToUse, document, xsdPrefix);
                newSchemaMap.put(namespaceToUse, newSchema);
            }
            resolvedRpcWrappedElementMap.put(boEntry.getBindingOperation().getName(),
                    new QName(namespaceToUse, boEntry.getBindingOperation().getName(), AXIS2WRAPPED));

        } else {
            throw new WSDLProcessingException("No binding input is defiend for binding operation ==> "
                    + boEntry.getBindingOperation().getName());
        }

    }

    // loop through the output to map and generate the elements
    for (Iterator boeIterator = boeToOutputMessageMap.keySet().iterator(); boeIterator.hasNext();) {
        boEntry = (BindingOperationEntry) boeIterator.next();
        String baseoutputOpName = boEntry.getBindingOperation().getName();
        // see basic profile 4.7.19
        String outputOpName = baseoutputOpName + WRAPPED_OUTPUTNAME_SUFFIX;
        elementDeclaration = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
                xsdPrefix + ":" + XML_SCHEMA_ELEMENT_LOCAL_NAME);
        elementDeclaration.setAttribute(XSD_NAME, outputOpName);

        BindingOutput bindingOutput = boEntry.getBindingOperation().getBindingOutput();
        Message message = (Message) boeToOutputMessageMap.get(boEntry);

        if (bindingOutput != null) {
            Collection partsCollection = null;
            if (BINDING_TYPE_SOAP.equals(this.bindingType)) {
                // first see the body parts list
                List bodyPartsList = getPartsListFromSoapBody(bindingOutput.getExtensibilityElements());
                partsCollection = message.getOrderedParts(bodyPartsList);

            } else {
                // i.e if http binding
                partsCollection = message.getParts().values();
            }

            List parameterOrder = boEntry.getBindingOperation().getOperation().getParameterOrdering();

            // we have to initialize the hash maps always since we add the elements onece we
            // generate it
            namespacePrefixMap = new HashMap();
            namespaceImportsMap = new HashMap();

            Node newComplexType = getNewComplextType(document, xsdPrefix, partsCollection, parameterOrder, true,
                    namespaceImportsMap, namespacePrefixMap, boEntry);
            elementDeclaration.appendChild(newComplexType);

            String namespaceToUse = namespaceURI;

            if (BINDING_TYPE_SOAP.equals(this.bindingType)) {
                String bodyNamespace = getNamespaceFromSoapBody(bindingOutput.getExtensibilityElements());
                namespaceToUse = bodyNamespace != null ? bodyNamespace : namespaceURI;
            }

            if (existingSchemaMap.containsKey(namespaceToUse)) {
                // i.e this namespace is already exists with the original wsdl schemas
                addElementToAnExistingSchema((Element) existingSchemaMap.get(namespaceToUse),
                        elementDeclaration, namespacePrefixMap, namespaceImportsMap, namespaceToUse);
            } else if (newSchemaMap.containsKey(namespaceToUse)) {
                // i.e this namespace is with a newly created schema
                addElementToAnExistingSchema((Element) newSchemaMap.get(namespaceToUse), elementDeclaration,
                        namespacePrefixMap, namespaceImportsMap, namespaceToUse);
            } else {
                // i.e this element namespace has not found yet so
                // we have to create new schema for it
                Element newSchema = createNewSchemaWithElement(elementDeclaration, namespacePrefixMap,
                        namespaceImportsMap, namespaceToUse, document, xsdPrefix);
                newSchemaMap.put(namespaceToUse, newSchema);
            }
            resolvedRpcWrappedElementMap.put(outputOpName,
                    new QName(namespaceToUse, outputOpName, AXIS2WRAPPED));

        } else {
            throw new WSDLProcessingException("No binding out put is defined for binding operation ==>"
                    + boEntry.getBindingOperation().getName());
        }
    }

    return newSchemaMap;
}

From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java

private Element createNewSchemaWithElement(Element newElement, Map namespacePrefixMap, Map namespaceImportsMap,
        String targetNamespace, Document document, String xsdPrefix) {

    Element schemaElement = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
            xsdPrefix + ":" + XML_SCHEMA_LOCAL_NAME);

    // loop through the namespace declarations first
    String[] nameSpaceDeclarationArray = (String[]) namespacePrefixMap.keySet()
            .toArray(new String[namespacePrefixMap.size()]);
    for (int i = 0; i < nameSpaceDeclarationArray.length; i++) {
        String s = nameSpaceDeclarationArray[i];
        schemaElement.setAttributeNS(XML_NAMESPACE_URI,
                NAMESPACE_DECLARATION_PREFIX + namespacePrefixMap.get(s).toString(), s);
    }/*from w w  w  . jav a2  s  .  co  m*/

    if (schemaElement.getAttributeNS(XML_NAMESPACE_URI, xsdPrefix).length() == 0) {
        schemaElement.setAttributeNS(XML_NAMESPACE_URI, NAMESPACE_DECLARATION_PREFIX + xsdPrefix,
                XMLSCHEMA_NAMESPACE_URI);
    }

    // add the targetNamespace
    schemaElement.setAttributeNS(XML_NAMESPACE_URI, XMLNS_AXIS2WRAPPED, targetNamespace);
    schemaElement.setAttribute(XSD_TARGETNAMESPACE, targetNamespace);
    schemaElement.setAttribute(XSD_ELEMENT_FORM_DEFAULT, XSD_UNQUALIFIED);

    // add imports
    Element[] namespaceImports = (Element[]) namespaceImportsMap.values()
            .toArray(new Element[namespaceImportsMap.size()]);
    for (int i = 0; i < namespaceImports.length; i++) {
        schemaElement.appendChild(namespaceImports[i]);

    }

    schemaElement.appendChild(newElement);
    return schemaElement;
}

From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java

/**
 * creates a new shema complex element according to the elements sequence difined
 * this parts list is always for a message refering from the
 * soap rpc type operation/*from  w w  w.j ava  2s  .  c  o  m*/
 *
 * @param document
 * @param xsdPrefix
 * @param partsCollection     - parts to be added
 * @param parameterOrder      - param Order list if it is given
 * @param isOutMessage
 * @param namespaceImportsMap
 * @param namespacePrefixMap
 * @param boe BindingOperationEntry for this partCollection
 * @return new element
 */
private Element getNewComplextType(Document document, String xsdPrefix, Collection partsCollection,
        List parameterOrder, boolean isOutMessage, Map namespaceImportsMap, Map namespacePrefixMap,
        BindingOperationEntry boe) {
    // add the complex type
    Element newComplexType = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
            xsdPrefix + ":" + XML_SCHEMA_COMPLEX_TYPE_LOCAL_NAME);

    Element cmplxTypeSequence = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
            xsdPrefix + ":" + XML_SCHEMA_SEQUENCE_LOCAL_NAME);

    Part part;
    if ((parameterOrder == null) || (parameterOrder.size() == 0)) {
        // no parameter order then just add the elements in the parts collection
        for (Iterator partsIter = partsCollection.iterator(); partsIter.hasNext();) {
            part = (Part) partsIter.next();
            // the part name
            addPartToElement(part, document, xsdPrefix, namespaceImportsMap, namespacePrefixMap,
                    cmplxTypeSequence, isOutMessage, boe);

        }
    } else {
        // i.e an parts order is given
        // first populate all the parts to a map
        Map partsMap = new HashMap();
        for (Iterator partsIter = partsCollection.iterator(); partsIter.hasNext();) {
            part = (Part) partsIter.next();
            partsMap.put(part.getName(), part);
        }

        String partName;
        for (Iterator paramOrderIter = parameterOrder.iterator(); paramOrderIter.hasNext();) {
            partName = (String) paramOrderIter.next();
            part = (Part) partsMap.get(partName);
            if (part != null) {
                addPartToElement(part, document, xsdPrefix, namespaceImportsMap, namespacePrefixMap,
                        cmplxTypeSequence, isOutMessage, boe);
                partsMap.remove(partName);
            }
        }
        // if this is an output message then we have to set the
        // return type if exists
        if (isOutMessage) {
            if (partsMap.size() > 0) {
                if (partsMap.size() == 1) {
                    part = (Part) partsMap.values().iterator().next();
                    // change the name of this part
                    // this is the return type and its name should be result
                    // part.setName("result");
                    addPartToElement(part, document, xsdPrefix, namespaceImportsMap, namespacePrefixMap,
                            cmplxTypeSequence, isOutMessage, boe);
                } else {
                    throw new WSDLProcessingException("the parameter order can left atmost" + " one part");
                }
            }
        }
    }

    newComplexType.appendChild(cmplxTypeSequence);
    return newComplexType;
}

From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java

/**
 * @param part// ww w.j a  v a  2 s  .c om
 * @param document
 * @param xsdPrefix
 * @param namespaceImportsMap
 * @param namespacePrefixMap
 * @param cmplxTypeSequence
 * @param isOutMessage (true is part is referenced by the output clause)
 * @param boe BindingOperationEntry that caused the creation of this part.
 */
private void addPartToElement(Part part, Document document, String xsdPrefix, Map namespaceImportsMap,
        Map namespacePrefixMap, Element cmplxTypeSequence, boolean isOutMessage, BindingOperationEntry boe) {
    Element child;
    String elementName = part.getName();

    // the type name
    QName schemaTypeName = part.getTypeName();

    if (schemaTypeName != null) {

        child = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
                xsdPrefix + ":" + XML_SCHEMA_ELEMENT_LOCAL_NAME);
        // always child attribute should be in no namespace
        child.setAttribute("form", "unqualified");
        child.setAttribute("nillable", "true");

        String prefix;
        if (XMLSCHEMA_NAMESPACE_URI.equals(schemaTypeName.getNamespaceURI())) {
            prefix = xsdPrefix;
            if (log.isDebugEnabled()) {
                log.debug(
                        "Unable to find a namespace for " + xsdPrefix + ". Creating a new namespace attribute");
            }
            cmplxTypeSequence.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + xsdPrefix,
                    XMLSCHEMA_NAMESPACE_URI);
        } else {
            // this schema is a third party one. So we need to have
            // an import statement in our generated schema
            String uri = schemaTypeName.getNamespaceURI();
            if (!namespaceImportsMap.containsKey(uri)) {
                // create Element for namespace import
                Element namespaceImport = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
                        xsdPrefix + ":" + XML_SCHEMA_IMPORT_LOCAL_NAME);
                namespaceImport.setAttribute(NAMESPACE_URI, uri);
                // add this to the map
                namespaceImportsMap.put(uri, namespaceImport);
                // we also need to associate this uri with a prefix
                // and include that prefix
                // in the schema's namspace declarations. So add
                // theis particular namespace to the
                // prefix map as well
                prefix = getTemporaryNamespacePrefix();
                namespacePrefixMap.put(uri, prefix);
            } else {
                // this URI should be already in the namspace prefix
                // map
                prefix = (String) namespacePrefixMap.get(uri);
            }

        }

        child.setAttribute(XSD_NAME, elementName);
        child.setAttribute(XSD_TYPE, prefix + ":" + schemaTypeName.getLocalPart());
        cmplxTypeSequence.appendChild(child);

    } else {
        String bindingOperationName = boe.getBindingOperation().getName();
        String partName = part.getName();
        if (boe.isRPC()) {
            // see the basic profile 4.4.1 for rpc-literal.
            // messages parts can have only types
            throw new WSDLProcessingException("The binding operation " + bindingOperationName
                    + " is RPC/literal. " + "The message parts for this operation must use the type "
                    + "attribute as specificed by "
                    + "WS-I Basic Profile specification (4.4.1).  Message part, " + partName + ", violates"
                    + "this rule.  Please remove the element attribute " + "and use the type attribute.");
        } else {
            // The presense of an element means that a wrapper xsd element is not needed.
            boe.setWrappedOutput(false);
            if (log.isDebugEnabled()) {
                log.debug("The binding operation " + bindingOperationName + " references message part "
                        + partName + ".  This part does not use the "
                        + "type attribute, so a wrappering element is not added.");
            }
        }

    }
}