Example usage for org.w3c.dom Element getLocalName

List of usage examples for org.w3c.dom Element getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Element getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.apache.axis.message.MessageElement.java

/**
 * create a node through a deep copy of the passed in element.
 * @param elem name to copy from/*  ww w  . jav  a 2s. com*/
 */
public MessageElement(Element elem) {
    namespaceURI = elem.getNamespaceURI();
    name = elem.getLocalName();
    copyNode(elem);
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * helper method for recusively getting the element that has namespace URI and localname
 * @param parentElement parent element//from w ww.  jav a  2s  .  com
 * @param namespace namespace
 * @param localName local name of element
 * @return (potentially empty) list of elements that match the (namespace,localname) tuple
 */
protected NodeList getElementsNS(org.w3c.dom.Element parentElement, String namespace, String localName) {
    NodeList children = parentElement.getChildNodes();
    NodeListImpl matches = new NodeListImpl();

    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i) instanceof Text) {
            continue;
        }
        Element child = (Element) children.item(i);
        if (namespace.equals(child.getNamespaceURI()) && localName.equals(child.getLocalName())) {
            matches.addNode(child);
        }
        // search the grand-children.
        matches.addNodeList(child.getElementsByTagNameNS(namespace, localName));
    }
    return matches;
}

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

protected static Document processWSDD(MessageContext msgContext, AxisEngine engine, Element root)
        throws Exception {
    Document doc = null;/* w w w.  j av  a 2s  . c o m*/

    String action = root.getLocalName();
    if (action.equals("passwd")) {
        String newPassword = root.getFirstChild().getNodeValue();
        engine.setAdminPassword(newPassword);
        doc = XMLUtils.newDocument();
        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.wsdl.fromJava.Types.java

/**
 * Loads the types from the input schema file.
 *
 * @param inputSchema file or URL/*from   w  w w .jav  a  2s .c om*/
 * @throws IOException
 * @throws WSDLException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public void loadInputSchema(String inputSchema)
        throws IOException, WSDLException, SAXException, ParserConfigurationException {

    // Read the input wsdl file into a Document
    Document doc = XMLUtils.newDocument(inputSchema);

    // Ensure that the root element is xsd:schema
    Element root = doc.getDocumentElement();

    if (root.getLocalName().equals("schema") && Constants.isSchemaXSD(root.getNamespaceURI())) {
        Node schema = docHolder.importNode(root, true);

        if (null == wsdlTypesElem) {
            writeWsdlTypesElement();
        }

        wsdlTypesElem.appendChild(schema);

        // Create a symbol table and populate it with the input types
        BaseTypeMapping btm = new BaseTypeMapping() {

            public String getBaseName(QName qNameIn) {

                QName qName = new QName(qNameIn.getNamespaceURI(), qNameIn.getLocalPart());
                Class cls = defaultTM.getClassForQName(qName);

                if (cls == null) {
                    return null;
                } else {
                    return JavaUtils.getTextClassName(cls.getName());
                }
            }
        };
        SymbolTable symbolTable = new SymbolTable(btm, true, false, false);

        symbolTable.populateTypes(new URL(inputSchema), doc);
        processSymTabEntries(symbolTable);
    } else {

        // If not, we'll just bail out... perhaps we should log a warning
        // or throw an exception?
        ;
    }
}

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

private void setPortAddress(Definition definition, String requestIP) throws AxisFault {
    Iterator serviceItr = definition.getServices().values().iterator();
    while (serviceItr.hasNext()) {
        Service serviceElement = (Service) serviceItr.next();
        Iterator portItr = serviceElement.getPorts().values().iterator();
        while (portItr.hasNext()) {
            Port port = (Port) portItr.next();
            AxisEndpoint endpoint = getAxisEndpoint(port.getName());
            List list = port.getExtensibilityElements();
            for (int i = 0; i < list.size(); i++) {
                Object extensibilityEle = list.get(i);
                if (extensibilityEle instanceof SOAPAddress) {
                    SOAPAddress soapAddress = (SOAPAddress) extensibilityEle;
                    String existingAddress = soapAddress.getLocationURI();
                    if (existingAddress == null || existingAddress.equals("REPLACE_WITH_ACTUAL_URL")) {
                        if (endpoint != null) {
                            ((SOAPAddress) extensibilityEle)
                                    .setLocationURI(endpoint.calculateEndpointURL(requestIP));
                        } else {
                            ((SOAPAddress) extensibilityEle).setLocationURI(getEPRs()[0]);
                        }/*from w w w.  j  a  v  a  2s  .  c  o  m*/
                    } else {
                        if (requestIP == null) {
                            if (endpoint != null) {
                                ((SOAPAddress) extensibilityEle)
                                        .setLocationURI(endpoint.calculateEndpointURL());
                            } else {
                                ((SOAPAddress) extensibilityEle)
                                        .setLocationURI(getLocationURI(getEPRs(), existingAddress));
                            }
                        } else {
                            if (endpoint != null) {
                                ((SOAPAddress) extensibilityEle)
                                        .setLocationURI(endpoint.calculateEndpointURL(requestIP));
                            } else {
                                ((SOAPAddress) extensibilityEle).setLocationURI(
                                        getLocationURI(calculateEPRs(requestIP), existingAddress));
                            }
                        }
                    }
                } else if (extensibilityEle instanceof SOAP12Address) {
                    SOAP12Address soapAddress = (SOAP12Address) extensibilityEle;
                    String exsistingAddress = soapAddress.getLocationURI();
                    if (requestIP == null) {
                        if (endpoint != null) {
                            ((SOAP12Address) extensibilityEle).setLocationURI(endpoint.calculateEndpointURL());

                        } else {
                            ((SOAP12Address) extensibilityEle)
                                    .setLocationURI(getLocationURI(getEPRs(), exsistingAddress));
                        }
                    } else {
                        if (endpoint != null) {
                            ((SOAP12Address) extensibilityEle)
                                    .setLocationURI(endpoint.calculateEndpointURL(requestIP));
                        } else {
                            ((SOAP12Address) extensibilityEle)
                                    .setLocationURI(getLocationURI(calculateEPRs(requestIP), exsistingAddress));

                        }
                    }
                } else if (extensibilityEle instanceof HTTPAddress) {
                    HTTPAddress httpAddress = (HTTPAddress) extensibilityEle;
                    String exsistingAddress = httpAddress.getLocationURI();
                    if (requestIP == null) {
                        if (endpoint != null) {
                            ((HTTPAddress) extensibilityEle).setLocationURI(endpoint.calculateEndpointURL());
                        } else {
                            ((HTTPAddress) extensibilityEle)
                                    .setLocationURI(getLocationURI(getEPRs(), exsistingAddress));
                        }
                    } else {
                        if (endpoint != null) {
                            ((HTTPAddress) extensibilityEle)
                                    .setLocationURI(endpoint.calculateEndpointURL(requestIP));
                        } else {
                            ((HTTPAddress) extensibilityEle)
                                    .setLocationURI(getLocationURI(calculateEPRs(requestIP), exsistingAddress));
                        }
                    }
                } else if (extensibilityEle instanceof UnknownExtensibilityElement) {
                    UnknownExtensibilityElement unknownExtensibilityElement = (UnknownExtensibilityElement) extensibilityEle;
                    Element element = unknownExtensibilityElement.getElement();
                    if (AddressingConstants.ENDPOINT_REFERENCE.equals(element.getLocalName())) {
                        NodeList nodeList = element.getChildNodes();
                        Node node = null;
                        Element currentElement = null;
                        for (int j = 0; j < nodeList.getLength(); j++) {
                            node = nodeList.item(j);
                            if (node instanceof Element) {
                                currentElement = (Element) node;
                                if (AddressingConstants.EPR_ADDRESS.equals(currentElement.getLocalName())) {
                                    String exsistingAddress = currentElement.getTextContent();
                                    if (requestIP == null) {
                                        if (endpoint != null) {
                                            currentElement.setTextContent(endpoint.calculateEndpointURL());
                                        } else {
                                            currentElement.setTextContent(
                                                    getLocationURI(getEPRs(), exsistingAddress));
                                        }
                                    } else {
                                        if (endpoint != null) {
                                            currentElement
                                                    .setTextContent(endpoint.calculateEndpointURL(requestIP));
                                        } else {
                                            currentElement.setTextContent(
                                                    getLocationURI(calculateEPRs(requestIP), exsistingAddress));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

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

private void addElementToAnExistingSchema(Element schemaElement, Element newElement, Map namespacePrefixMap,
        Map namespaceImportsMap, String targetNamespace) {

    Document ownerDocument = schemaElement.getOwnerDocument();

    String newElementName = newElement.getAttribute(XSD_NAME);

    // check whether this element already exists.
    NodeList nodeList = schemaElement.getChildNodes();
    Element nodeElement = null;
    for (int i = 1; i < nodeList.getLength(); i++) {
        if (nodeList.item(i) instanceof Element) {
            nodeElement = (Element) nodeList.item(i);
            if (nodeElement.getLocalName().equals(XML_SCHEMA_ELEMENT_LOCAL_NAME)) {
                if (nodeElement.getAttribute(XSD_NAME).equals(newElementName)) {
                    // if the element already exists we do not add this element
                    // and just return.
                    return;
                }// w ww  . j  av  a2s  .  co  m
            }
        }

    }

    // loop through the namespace declarations first and add them
    String[] nameSpaceDeclarationArray = (String[]) namespacePrefixMap.keySet()
            .toArray(new String[namespacePrefixMap.size()]);
    for (int i = 0; i < nameSpaceDeclarationArray.length; i++) {
        String s = nameSpaceDeclarationArray[i];
        checkAndAddNamespaceDeclarations(s, namespacePrefixMap, schemaElement);
    }

    // add imports - check whether it is the targetnamespace before
    // adding
    Element[] namespaceImports = (Element[]) namespaceImportsMap.values()
            .toArray(new Element[namespaceImportsMap.size()]);
    for (int i = 0; i < namespaceImports.length; i++) {
        if (!targetNamespace.equals(namespaceImports[i].getAttribute(NAMESPACE_URI))) {
            schemaElement.appendChild(ownerDocument.importNode(namespaceImports[i], true));
        }
    }

    schemaElement.appendChild(ownerDocument.importNode(newElement, true));

}

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

/**
 * Get the Extensible elements form wsdl4jExtensibleElements
 * <code>Vector</code> if any and copy them to <code>Component</code>
 * <p/> Note - SOAP body extensible element will be processed differently
 *
 * @param wsdl4jExtensibleElements// w ww. j a  v a 2  s.c o  m
 * @param description                   where is the ext element (port , portype , biding)
 * @param wsdl4jDefinition
 * @param originOfExtensibilityElements -
 *                                      this will indicate the place this extensibility element came
 *                                      from.
 */
private void copyExtensibleElements(List wsdl4jExtensibleElements, Definition wsdl4jDefinition,
        AxisDescription description, String originOfExtensibilityElements) throws AxisFault {

    ExtensibilityElement wsdl4jExtensibilityElement;

    for (Iterator iterator = wsdl4jExtensibleElements.iterator(); iterator.hasNext();) {

        wsdl4jExtensibilityElement = (ExtensibilityElement) iterator.next();

        if (wsdl4jExtensibilityElement instanceof UnknownExtensibilityElement) {

            UnknownExtensibilityElement unknown = (UnknownExtensibilityElement) (wsdl4jExtensibilityElement);
            QName type = unknown.getElementType();

            // <wsp:Policy>
            if (WSDLConstants.WSDL11Constants.POLICY.equals(type)) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: PolicyElement found " + unknown);
                }
                Policy policy = (Policy) PolicyUtil.getPolicyComponent(unknown.getElement());
                description.getPolicySubject().attachPolicy(policy);

                //                    int attachmentScope =
                //                            getPolicyAttachmentPoint(description, originOfExtensibilityElements);
                //                    if (attachmentScope > -1) {
                //                        description.getPolicyInclude().addPolicyElement(
                //                                attachmentScope, policy);
                //                    }
                // <wsp:PolicyReference>
            } else if (WSDLConstants.WSDL11Constants.POLICY_REFERENCE.equals(type)) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: PolicyReference found " + unknown);
                }
                PolicyReference policyReference = (PolicyReference) PolicyUtil
                        .getPolicyComponent(unknown.getElement());
                description.getPolicySubject().attachPolicyReference(policyReference);

                //                    int attachmentScope =
                //                            getPolicyAttachmentPoint(description, originOfExtensibilityElements);
                //                    if (attachmentScope > -1) {
                //                        description.getPolicyInclude().addPolicyRefElement(
                //                                attachmentScope, policyReference);
                //                    }
            } else if (AddressingConstants.Final.WSAW_USING_ADDRESSING.equals(type)
                    || AddressingConstants.Submission.WSAW_USING_ADDRESSING.equals(unknown.getElementType())) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: wsaw:UsingAddressing found " + unknown);
                }
                // FIXME We need to set this the appropriate Axis Description AxisEndpoint or
                // AxisBinding .
                if (originOfExtensibilityElements.equals(PORT)
                        || originOfExtensibilityElements.equals(BINDING)) {
                    if (Boolean.TRUE.equals(unknown.getRequired())) {
                        AddressingHelper.setAddressingRequirementParemeterValue(axisService,
                                AddressingConstants.ADDRESSING_REQUIRED);
                    } else {
                        AddressingHelper.setAddressingRequirementParemeterValue(axisService,
                                AddressingConstants.ADDRESSING_OPTIONAL);
                    }
                }

            } else if (wsdl4jExtensibilityElement.getElementType() != null
                    && wsdl4jExtensibilityElement.getElementType().getNamespaceURI()
                            .equals(org.apache.axis2.namespace.Constants.FORMAT_BINDING)) {
                Element typeMapping = unknown.getElement();

                NodeList typeMaps = typeMapping
                        .getElementsByTagNameNS(org.apache.axis2.namespace.Constants.FORMAT_BINDING, "typeMap");
                int count = typeMaps.getLength();
                HashMap typeMapper = new HashMap();
                for (int index = 0; index < count; index++) {
                    Node node = typeMaps.item(index);
                    NamedNodeMap attributes = node.getAttributes();
                    Node typeName = attributes.getNamedItem("typeName");

                    if (typeName != null) {
                        String prefix = getPrefix(typeName.getNodeValue());

                        if (prefix != null) {
                            String ns = (String) wsdl4jDefinition.getNamespaces().get(prefix);
                            if (ns != null) {
                                Node formatType = attributes.getNamedItem("formatType");
                                typeMapper.put(new QName(ns, getTypeName(typeName.getNodeValue())),
                                        formatType.getNodeValue());
                            }

                        }
                    }
                }
            } else if (wsdl4jExtensibilityElement.getElementType() != null && wsdl4jExtensibilityElement
                    .getElementType().getNamespaceURI().equals(org.apache.axis2.namespace.Constants.JAVA_NS)) {
                Element unknowJavaElement = unknown.getElement();
                if (unknowJavaElement.getLocalName().equals("address")) {
                    NamedNodeMap nameAttributes = unknowJavaElement.getAttributes();
                    Node node = nameAttributes.getNamedItem("className");
                    Parameter serviceClass = new Parameter();
                    serviceClass.setName("className");
                    serviceClass.setValue(node.getNodeValue());
                    axisService.addParameter(serviceClass);
                    Parameter transportName = new Parameter();
                    transportName.setName("TRANSPORT_NAME");
                    transportName.setValue("java");
                    axisService.addParameter(transportName);
                }
            } else {
                // Ignore this element - it is a totally unknown element
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: Unknown Extensibility Element found " + unknown);
                }
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAP12Address) {
            SOAP12Address soapAddress = (SOAP12Address) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, soapAddress.getLocationURI());
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAPAddress) {
            SOAPAddress soapAddress = (SOAPAddress) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, soapAddress.getLocationURI());
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPAddress) {
            HTTPAddress httpAddress = (HTTPAddress) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, httpAddress.getLocationURI());
            }

        } else if (wsdl4jExtensibilityElement instanceof Schema) {
            Schema schema = (Schema) wsdl4jExtensibilityElement;
            // just add this schema - no need to worry about the imported
            // ones
            axisService.addSchema(getXMLSchema(schema.getElement(), schema.getDocumentBaseURI()));

        } else if (wsdl4jExtensibilityElement instanceof SOAP12Operation) {
            SOAP12Operation soapOperation = (SOAP12Operation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;

            String style = soapOperation.getStyle();
            if (style != null) {
                axisBindingOperation.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }

            String soapActionURI = soapOperation.getSoapActionURI();

            if (this.isCodegen && ((soapActionURI == null) || (soapActionURI.equals("")))) {
                soapActionURI = axisBindingOperation.getAxisOperation().getInputAction();
            }

            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
                log.debug("WSDL Binding Operation: " + axisBindingOperation.getName() + ", SOAPAction: "
                        + soapActionURI);

            if (soapActionURI != null && !soapActionURI.equals("")) {
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, soapActionURI);
                axisBindingOperation.getAxisOperation().setSoapAction(soapActionURI);
                if (!isServerSide) {
                    axisBindingOperation.getAxisOperation().setOutputAction(soapActionURI);
                }

                axisService.mapActionToOperation(soapActionURI, axisBindingOperation.getAxisOperation());
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAPOperation) {
            SOAPOperation soapOperation = (SOAPOperation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;

            String style = soapOperation.getStyle();
            if (style != null) {
                axisBindingOperation.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }

            String soapAction = soapOperation.getSoapActionURI();
            if (this.isCodegen && ((soapAction == null) || (soapAction.equals("")))) {
                soapAction = axisBindingOperation.getAxisOperation().getInputAction();
            }

            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
                log.debug("WSDL Binding Operation: " + axisBindingOperation.getName() + ", SOAPAction: "
                        + soapAction);

            if (soapAction != null) {
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, soapAction);
                axisBindingOperation.getAxisOperation().setSoapAction(soapAction);
                if (!isServerSide) {
                    axisBindingOperation.getAxisOperation().setOutputAction(soapAction);
                }

                axisService.mapActionToOperation(soapAction, axisBindingOperation.getAxisOperation());
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPOperation) {
            HTTPOperation httpOperation = (HTTPOperation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;

            String httpLocation = httpOperation.getLocationURI();
            if (httpLocation != null) {
                // change the template to make it same as WSDL 2 template
                httpLocation = httpLocation.replaceAll("\\(", "{");
                httpLocation = httpLocation.replaceAll("\\)", "}");
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, httpLocation);

            }
            axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION,
                    HTTPConstants.MEDIA_TYPE_TEXT_XML);

        } else if (wsdl4jExtensibilityElement instanceof SOAP12Header) {

            SOAP12Header soapHeader = (SOAP12Header) wsdl4jExtensibilityElement;
            SOAPHeaderMessage headerMessage = new SOAPHeaderMessage();

            headerMessage.setNamespaceURI(soapHeader.getNamespaceURI());
            headerMessage.setUse(soapHeader.getUse());

            Boolean required = soapHeader.getRequired();

            if (required != null) {
                headerMessage.setRequired(required.booleanValue());
            }

            if (wsdl4jDefinition != null) {
                // find the relevant schema part from the messages
                Message msg = wsdl4jDefinition.getMessage(soapHeader.getMessage());

                if (msg == null) {
                    msg = getMessage(wsdl4jDefinition, soapHeader.getMessage(), new HashSet());
                }

                if (msg == null) {
                    // TODO i18n this
                    throw new AxisFault("message " + soapHeader.getMessage() + " not found in the WSDL ");
                }
                Part msgPart = msg.getPart(soapHeader.getPart());

                if (msgPart == null) {
                    // TODO i18n this
                    throw new AxisFault("message part " + soapHeader.getPart() + " not found in the WSDL ");
                }
                // see basic profile 4.4.2 Bindings and Faults header, fault and headerfaults
                // can only have elements
                headerMessage.setElement(msgPart.getElementName());
            }

            headerMessage.setMessage(soapHeader.getMessage());
            headerMessage.setPart(soapHeader.getPart());

            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                List soapHeaders = (List) bindingMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
                if (soapHeaders == null) {
                    soapHeaders = new ArrayList();
                    bindingMessage.setProperty(WSDL2Constants.ATTR_WSOAP_HEADER, soapHeaders);
                }
                soapHeaders.add(headerMessage);
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAPHeader) {

            SOAPHeader soapHeader = (SOAPHeader) wsdl4jExtensibilityElement;
            SOAPHeaderMessage headerMessage = new SOAPHeaderMessage();
            headerMessage.setNamespaceURI(soapHeader.getNamespaceURI());
            headerMessage.setUse(soapHeader.getUse());
            Boolean required = soapHeader.getRequired();
            if (null != required) {
                headerMessage.setRequired(required.booleanValue());
            }
            if (null != wsdl4jDefinition) {
                // find the relevant schema part from the messages
                Message msg = wsdl4jDefinition.getMessage(soapHeader.getMessage());

                if (msg == null) {
                    msg = getMessage(wsdl4jDefinition, soapHeader.getMessage(), new HashSet());
                }

                if (msg == null) {
                    // todo i18n this
                    throw new AxisFault("message " + soapHeader.getMessage() + " not found in the WSDL ");
                }
                Part msgPart = msg.getPart(soapHeader.getPart());
                if (msgPart == null) {
                    // todo i18n this
                    throw new AxisFault("message part " + soapHeader.getPart() + " not found in the WSDL ");
                }
                headerMessage.setElement(msgPart.getElementName());
            }
            headerMessage.setMessage(soapHeader.getMessage());

            headerMessage.setPart(soapHeader.getPart());

            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                List soapHeaders = (List) bindingMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
                if (soapHeaders == null) {
                    soapHeaders = new ArrayList();
                    bindingMessage.setProperty(WSDL2Constants.ATTR_WSOAP_HEADER, soapHeaders);
                }
                soapHeaders.add(headerMessage);
            }
        } else if (wsdl4jExtensibilityElement instanceof SOAPBinding) {

            SOAPBinding soapBinding = (SOAPBinding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;

            axisBinding.setType(soapBinding.getTransportURI());

            axisBinding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
                    SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

            String style = soapBinding.getStyle();
            if (style != null) {
                axisBinding.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAP12Binding) {

            SOAP12Binding soapBinding = (SOAP12Binding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;

            axisBinding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
                    SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

            String style = soapBinding.getStyle();
            if (style != null) {
                axisBinding.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }

            String transportURI = soapBinding.getTransportURI();
            axisBinding.setType(transportURI);

        } else if (wsdl4jExtensibilityElement instanceof HTTPBinding) {
            HTTPBinding httpBinding = (HTTPBinding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;
            // set the binding style same as the wsd2 to process smoothly
            axisBinding.setType(WSDL2Constants.URI_WSDL2_HTTP);
            axisBinding.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, httpBinding.getVerb());
        } else if (wsdl4jExtensibilityElement instanceof MIMEContent) {
            if (description instanceof AxisBindingMessage) {
                MIMEContent mimeContent = (MIMEContent) wsdl4jExtensibilityElement;
                String messageSerialization = mimeContent.getType();
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(),
                        originOfExtensibilityElements, messageSerialization);
            }
        } else if (wsdl4jExtensibilityElement instanceof MIMEMimeXml) {
            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(),
                        originOfExtensibilityElements, HTTPConstants.MEDIA_TYPE_TEXT_XML);
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPUrlEncoded) {
            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(),
                        originOfExtensibilityElements, HTTPConstants.MEDIA_TYPE_X_WWW_FORM);
            }
        }
    }
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected Element createChildFromXmlFragmentOrText(Document doc, Input input, String localElementName,
        String errorMessage, String elementOrText)
        throws IOException, ParserConfigurationException, XmlSignatureException {
    String ending = localElementName + ">";
    Element child;
    if (elementOrText.startsWith("<") && elementOrText.endsWith(ending)) {
        try {//from   www  . jav  a 2  s.c  o  m
            // assume xml
            InputSource source = new InputSource(new StringReader(elementOrText));
            source.setEncoding("UTF-8");
            Document parsedDoc = XmlSignatureHelper.newDocumentBuilder(Boolean.TRUE).parse(source);
            replacePrefixes(parsedDoc, input);
            child = (Element) doc.adoptNode(parsedDoc.getDocumentElement());
            // check for correct namespace
            String ns = findNamespace(input.getMessage());
            if (!ns.equals(child.getNamespaceURI())) {
                throw new XmlSignatureException(String.format(
                        "The XAdES confguration is invalid. The root element '%s' of the provided XML fragment '%s' has the invalid namespace '%s'. The correct namespace is '%s'.",
                        child.getLocalName(), elementOrText, child.getNamespaceURI(), ns));
            }
        } catch (SAXException e) {
            throw new XmlSignatureException(
                    String.format(errorMessage, elementOrText, localElementName, namespace), e);
        }
    } else {
        child = createElement(localElementName, doc, input);
        child.setTextContent(elementOrText);
    }
    return child;
}

From source file:org.apache.camel.spring.handler.CamelNamespaceHandler.java

/**
 * Used for auto registering producer and consumer templates if not already defined in XML.
 *//*w w  w . ja  va 2 s. co m*/
protected void registerTemplates(Element element, ParserContext parserContext, String contextId) {
    boolean template = false;
    boolean consumerTemplate = false;

    NodeList list = element.getChildNodes();
    int size = list.getLength();
    for (int i = 0; i < size; i++) {
        Node child = list.item(i);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            String localName = childElement.getLocalName();
            if ("template".equals(localName)) {
                template = true;
            } else if ("consumerTemplate".equals(localName)) {
                consumerTemplate = true;
            }
        }
    }

    if (!template) {
        // either we have not used template before or we have auto registered it already and therefore we
        // need it to allow to do it so it can remove the existing auto registered as there is now a clash id
        // since we have multiple camel contexts
        boolean existing = autoRegisterMap.get("template") != null;
        boolean inUse = false;
        try {
            inUse = parserContext.getRegistry().isBeanNameInUse("template");
        } catch (BeanCreationException e) {
            // Spring Eclipse Tooling may throw an exception when you edit the Spring XML online in Eclipse
            // when the isBeanNameInUse method is invoked, so ignore this and continue (CAMEL-2739)
            LOG.debug("Error checking isBeanNameInUse(template). This exception will be ignored", e);
        }
        if (!inUse || existing) {
            String id = "template";
            // auto create a template
            Element templateElement = element.getOwnerDocument().createElement("template");
            templateElement.setAttribute("id", id);
            BeanDefinitionParser parser = parserMap.get("template");
            BeanDefinition definition = parser.parse(templateElement, parserContext);

            // auto register it
            autoRegisterBeanDefinition(id, definition, parserContext, contextId);
        }
    }

    if (!consumerTemplate) {
        // either we have not used template before or we have auto registered it already and therefore we
        // need it to allow to do it so it can remove the existing auto registered as there is now a clash id
        // since we have multiple camel contexts
        boolean existing = autoRegisterMap.get("consumerTemplate") != null;
        boolean inUse = false;
        try {
            inUse = parserContext.getRegistry().isBeanNameInUse("consumerTemplate");
        } catch (BeanCreationException e) {
            // Spring Eclipse Tooling may throw an exception when you edit the Spring XML online in Eclipse
            // when the isBeanNameInUse method is invoked, so ignore this and continue (CAMEL-2739)
            LOG.debug("Error checking isBeanNameInUse(consumerTemplate). This exception will be ignored", e);
        }
        if (!inUse || existing) {
            String id = "consumerTemplate";
            // auto create a template
            Element templateElement = element.getOwnerDocument().createElement("consumerTemplate");
            templateElement.setAttribute("id", id);
            BeanDefinitionParser parser = parserMap.get("consumerTemplate");
            BeanDefinition definition = parser.parse(templateElement, parserContext);

            // auto register it
            autoRegisterBeanDefinition(id, definition, parserContext, contextId);
        }
    }

}

From source file:org.apache.cocoon.forms.formmodel.library.Library.java

protected WidgetDefinition buildWidgetDefinition(Element widgetDefinition) throws Exception {
    String widgetName = widgetDefinition.getLocalName();
    WidgetDefinitionBuilder builder = null;
    try {/*from w  w w  . ja v a2  s  .com*/
        builder = (WidgetDefinitionBuilder) widgetDefinitionBuilderSelector.select(widgetName);
    } catch (ServiceException e) {
        throw new CascadingException(
                "Unknown kind of widget '" + widgetName + "' at " + DomHelper.getLocation(widgetDefinition), e);
    }

    context.setSuperDefinition(null);
    String extend = DomHelper.getAttribute(widgetDefinition, "extends", null);

    if (extend != null)
        context.setSuperDefinition(getDefinition(extend));

    return builder.buildWidgetDefinition(widgetDefinition, context);
}