Example usage for javax.xml.namespace QName getNamespaceURI

List of usage examples for javax.xml.namespace QName getNamespaceURI

Introduction

In this page you can find the example usage for javax.xml.namespace QName getNamespaceURI.

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

From source file:org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.java

/**
 * Gets the base64 types. If not available this will be empty!!!
 *
 * @param doc//w w  w. j a v a  2s  . com
 * @return Returns Element.
 */
protected Element getBase64Elements(Document doc) {
    Element root = doc.createElement("base64Elements");
    Element elt;
    QName qname;

    // this is a list of QNames
    List list = (List) codeGenConfiguration.getProperties().get(Constants.BASE_64_PROPERTY_KEY);

    if ((list != null) && !list.isEmpty()) {
        int count = list.size();

        for (int i = 0; i < count; i++) {
            qname = (QName) list.get(i);
            elt = doc.createElement("name");
            addAttribute(doc, "ns-url", qname.getNamespaceURI(), elt);
            addAttribute(doc, "localName", qname.getLocalPart(), elt);
            root.appendChild(elt);
        }
    }

    return root;
}

From source file:org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.java

/**
 * A convenient method for the generating the parameter element
 *
 * @param doc/*  www .  j  a  va  2  s .c  om*/
 * @param paramName
 * @param paramType
 * @param opName
 * @param paramName
 */
protected Element generateParamComponent(Document doc, String comment, String paramName, String paramType,
        QName opName, QName paramQName, String partName, boolean isPrimitive, boolean isArray) {
    Element paramElement = doc.createElement("param");
    addAttribute(doc, "name", paramName, paramElement);

    addAttribute(doc, "comment", (comment == null) ? "" : comment, paramElement);

    if (codeGenConfiguration.getOutputLanguage().equals("jax-ws") && useHolderClass_jaxws) {
        Class primitive = JavaUtils.getWrapperClass(paramType);
        if (primitive != null) {
            paramType = primitive.getName();
        }
    }

    addAttribute(doc, "type", (paramType == null) ? "" : paramType, paramElement);

    //adds the short type
    addShortType(paramElement, (paramQName == null) ? null : paramQName.getLocalPart());

    // add an extra attribute to say whether the type mapping is the default
    if (mapper.getDefaultMappingName().equals(paramType)) {
        addAttribute(doc, "default", "yes", paramElement);
    }
    addAttribute(doc, "value", getParamInitializer(paramType), paramElement);
    // add this as a body parameter
    addAttribute(doc, "location", "body", paramElement);

    //if the opName and partName are present , add them
    if (opName != null) {
        String localPart = opName.getLocalPart();
        addAttribute(doc, "opname", JavaUtils.xmlNameToJava(localPart), paramElement);
    }

    if (paramQName != null) {
        Element qNameElement = doc.createElement("qname");
        addAttribute(doc, "nsuri", paramQName.getNamespaceURI(), qNameElement);
        addAttribute(doc, "localname", paramQName.getLocalPart(), qNameElement);
        paramElement.appendChild(qNameElement);
    }

    if (partName != null) {
        String javaName = null;
        if (JavaUtils.isJavaKeyword(partName)) {
            javaName = JavaUtils.makeNonJavaKeyword(partName);
        } else {
            if (codeGenConfiguration.getOutputLanguage().equals("jax-ws")) {
                javaName = JavaUtils.xmlNameToJavaIdentifier(JavaUtils.xmlNameToJava(partName));
            } else {
                javaName = JavaUtils.capitalizeFirstChar(JavaUtils.xmlNameToJava(partName));
            }
        }
        addAttribute(doc, "partname", javaName, paramElement);
    }

    if (isPrimitive) {
        addAttribute(doc, "primitive", "yes", paramElement);
    }

    if (isArray) {
        addAttribute(doc, "array", "yes", paramElement);
    }

    return paramElement;
}

From source file:org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.java

/**
 * @param doc/*from w  ww .  j a v  a  2  s. c o  m*/
 * @param operation
 * @return Returns Element.
 */
protected Element getOutputParamElement(Document doc, AxisOperation operation) {
    Element paramElement = doc.createElement("param");
    AxisMessage outputMessage = operation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
    if (outputMessage == null) {
        return null;
    }
    String parameterName;
    String typeMappingStr;
    String comment = null;
    parameterName = this.mapper.getParameterName(outputMessage.getElementQName());
    comment = outputMessage.getDocumentation();
    String typeMapping = this.mapper.getTypeMappingName(outputMessage.getElementQName());
    typeMappingStr = (typeMapping == null) ? "" : typeMapping;

    addAttribute(doc, "name", parameterName, paramElement);
    addAttribute(doc, "comment", (comment == null) ? "" : comment, paramElement);
    addAttribute(doc, "type", typeMappingStr, paramElement);

    //adds the short type
    addShortType(paramElement,
            (outputMessage.getElementQName() == null) ? null : outputMessage.getElementQName().getLocalPart());

    // add an extra attribute to say whether the type mapping is the default
    if (mapper.getDefaultMappingName().equals(typeMappingStr)) {
        addAttribute(doc, "default", "yes", paramElement);
    }

    // add this as a body parameter
    addAttribute(doc, "location", "body", paramElement);
    String localPart = operation.getName().getLocalPart();
    addAttribute(doc, "opname", JavaUtils.xmlNameToJava(localPart), paramElement);

    //if the unwrapping or backWordCompatibility flag is on then we have to
    //put the element complex type if it exits
    if (this.codeGenConfiguration.isBackwordCompatibilityMode()
            || !this.codeGenConfiguration.isParametersWrapped()) {
        if (outputMessage.getParameter(Constants.COMPLEX_TYPE) != null) {
            Parameter parameter = outputMessage.getParameter(Constants.COMPLEX_TYPE);
            addAttribute(doc, "complextype", (String) parameter.getValue(), paramElement);
        }
    }
    String partName = outputMessage.getPartName();
    if (partName != null && codeGenConfiguration.getOutputLanguage().equals("jax-ws")) {
        String javaName = null;
        if (JavaUtils.isJavaKeyword(partName)) {
            javaName = JavaUtils.makeNonJavaKeyword(partName);
        } else {
            javaName = JavaUtils.xmlNameToJavaIdentifier(JavaUtils.xmlNameToJava(partName));
        }
        addAttribute(doc, "partname", javaName, paramElement);
    }

    // this message has been unwrapped - find the correct references of the
    // the message by looking at the unwrapped details object and attach the
    // needed parameters inside main parameter element
    if (outputMessage.getParameter(Constants.UNWRAPPED_KEY) != null) {

        //we have this unwrapped earlier. get the info holder
        //and then look at the parameters
        Parameter detailsParameter = outputMessage.getParameter(Constants.UNWRAPPED_DETAILS);
        MessagePartInformationHolder infoHolder = (MessagePartInformationHolder) detailsParameter.getValue();
        List partsList = infoHolder.getPartsList();

        //populate the parts list - this list is needed to generate multiple
        //parameters in the signatures
        // in out put params we only intersted if there is only one parameter
        // otherwise we can not unwrap it.
        // this logic handles at the template level
        //todo comment is empty(null) in this scenario
        QName qName;
        for (Iterator iter = partsList.iterator(); iter.hasNext();) {
            qName = (QName) iter.next();
            paramElement.appendChild(generateParamComponent(doc, null, this.mapper.getParameterName(qName),
                    this.mapper.getTypeMappingName(qName), operation.getName(), qName, qName.getLocalPart(),
                    (this.mapper.getTypeMappingStatus(qName) != null),
                    Constants.ARRAY_TYPE.equals(this.mapper.getTypeMappingStatus(qName))));
        }

    }

    QName paramQName = outputMessage.getElementQName();
    if (paramQName != null) {
        Element qNameElement = doc.createElement("qname");
        addAttribute(doc, "nsuri", paramQName.getNamespaceURI(), qNameElement);
        addAttribute(doc, "localname", paramQName.getLocalPart(), qNameElement);
        paramElement.appendChild(qNameElement);
    }

    return paramElement;
}

From source file:org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.java

/**
 * @param doc/*from   w  w w .  j  a va2 s . co m*/
 * @param parameters
 * @param location
 */
protected List getParameterElementList(Document doc, List parameters, String location) {
    List parameterElementList = new ArrayList();

    if ((parameters != null) && !parameters.isEmpty()) {
        int count = parameters.size();

        for (int i = 0; i < count; i++) {
            Element param = doc.createElement("param");
            SOAPHeaderMessage header = (SOAPHeaderMessage) parameters.get(i);
            QName name = header.getElement();

            addAttribute(doc, "name", this.mapper.getParameterName(name), param);

            String typeMapping = this.mapper.getTypeMappingName(name);
            String typeMappingStr = (typeMapping == null) ? "" : typeMapping;

            addAttribute(doc, "type", typeMappingStr, param);
            addAttribute(doc, "location", location, param);
            if (header.isMustUnderstand()) {
                addAttribute(doc, "mustUnderstand", "true", param);
            }

            if (name != null) {
                Element qNameElement = doc.createElement("qname");
                addAttribute(doc, "nsuri", name.getNamespaceURI(), qNameElement);
                addAttribute(doc, "localname", name.getLocalPart(), qNameElement);
                param.appendChild(qNameElement);
            }
            parameterElementList.add(param);
        }
    }
    return parameterElementList;
}

From source file:org.apache.camel.builder.xml.MessageVariableResolver.java

public Object resolveVariable(QName name) {
    String uri = name.getNamespaceURI();
    String localPart = name.getLocalPart();
    Object answer = null;/*from w  w w. ja  v  a  2s. c  o m*/

    Message in = exchange.get().getIn();
    if (uri == null || uri.length() == 0) {
        answer = variables.get(localPart);
        if (answer == null) {
            Message message = in;
            if (message != null) {
                answer = message.getHeader(localPart);
            }
            if (answer == null) {
                answer = exchange.get().getProperty(localPart);
            }
        }
    } else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) {
        try {
            answer = System.getProperty(localPart);
        } catch (Exception e) {
            LOG.debug("Security exception evaluating system property: " + localPart + ". Reason: " + e, e);
        }
    } else if (uri.equals(ENVIRONMENT_VARIABLES)) {
        answer = System.getenv().get(localPart);
    } else if (uri.equals(EXCHANGE_PROPERTY)) {
        answer = exchange.get().getProperty(localPart);
    } else if (uri.equals(IN_NAMESPACE)) {
        answer = in.getHeader(localPart);
        if (answer == null && localPart.equals("body")) {
            answer = in.getBody();
        }
    } else if (uri.equals(OUT_NAMESPACE)) {
        if (exchange.get().hasOut()) {
            Message out = exchange.get().getOut();
            answer = out.getHeader(localPart);
            if (answer == null && localPart.equals("body")) {
                answer = out.getBody();
            }
        }
    }

    // If we can't find an answer we must return void.
    // We can't return null then the xpath engine will throw a NullPointerException
    if (answer == null) {
        return Void.class;
    } else {
        return answer;
    }
}

From source file:org.apache.camel.builder.xml.XPathBuilder.java

protected XPathFunctionResolver createDefaultFunctionResolver(final XPathFunctionResolver parent) {
    return new XPathFunctionResolver() {
        public XPathFunction resolveFunction(QName qName, int argumentCount) {
            XPathFunction answer = null;
            if (parent != null) {
                answer = parent.resolveFunction(qName, argumentCount);
            }/*  ww w.ja v a 2 s  . c om*/
            if (answer == null) {
                if (isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), IN_NAMESPACE)
                        || isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), DEFAULT_NAMESPACE)) {
                    String localPart = qName.getLocalPart();
                    if (localPart.equals("body") && argumentCount == 0) {
                        return getBodyFunction();
                    }
                    if (localPart.equals("header") && argumentCount == 1) {
                        return getHeaderFunction();
                    }
                }
                if (isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), OUT_NAMESPACE)) {
                    String localPart = qName.getLocalPart();
                    if (localPart.equals("body") && argumentCount == 0) {
                        return getOutBodyFunction();
                    }
                    if (localPart.equals("header") && argumentCount == 1) {
                        return getOutHeaderFunction();
                    }
                }
                if (isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), FUNCTION_NAMESPACE)) {
                    String localPart = qName.getLocalPart();
                    if (localPart.equals("properties") && argumentCount == 1) {
                        return getPropertiesFunction();
                    }
                    if (localPart.equals("simple") && argumentCount == 1) {
                        return getSimpleFunction();
                    }
                }
            }
            return answer;
        }
    };
}

From source file:org.apache.camel.converter.soap.name.ServiceInterfaceStrategyTest.java

@Test
public void testServiceInterfaceStrategyWithClient() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, true);
    QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByName.class);
    Assert.assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
    Assert.assertEquals("getCustomersByName", elName.getLocalPart());

    QName elName2 = strategy.findQNameForSoapActionOrType("getCustomersByName", GetCustomersByName.class);
    Assert.assertEquals("http://customerservice.example.com/", elName2.getNamespaceURI());
    Assert.assertEquals("getCustomersByName", elName2.getLocalPart());

    // Tests the case where the soap action is found but the in type is null
    QName elName3 = strategy.findQNameForSoapActionOrType("http://customerservice.example.com/getAllCustomers",
            null);//from w  w  w  . ja  v a2  s.c  o  m
    Assert.assertNull(elName3);

    try {
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        Assert.fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}

From source file:org.apache.camel.converter.soap.name.ServiceInterfaceStrategyTest.java

@Test
public void testServiceInterfaceStrategyWithServer() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, false);

    // Tests the case where the action is not found but the type is
    QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByNameResponse.class);
    Assert.assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
    Assert.assertEquals("getCustomersByNameResponse", elName.getLocalPart());

    // Tests the case where the soap action is found
    QName elName2 = strategy.findQNameForSoapActionOrType(
            "http://customerservice.example.com/getCustomersByName", GetCustomersByName.class);
    Assert.assertEquals("http://customerservice.example.com/", elName2.getNamespaceURI());
    Assert.assertEquals("getCustomersByNameResponse", elName2.getLocalPart());

    // this tests the case that the soap action as well as the type are not
    // found//w  w w  .ja  va 2s  .co m
    try {
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        Assert.fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}

From source file:org.apache.camel.converter.soap.name.ServiceInterfaceStrategyTest.java

@Test
public void testServiceInterfaceStrategyWithRequestWrapperAndClient() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(
            com.example.customerservice2.CustomerService.class, true);
    QName elName = strategy.findQNameForSoapActionOrType("",
            com.example.customerservice2.GetCustomersByName.class);
    Assert.assertEquals("http://customerservice2.example.com/", elName.getNamespaceURI());
    Assert.assertEquals("getCustomersByName", elName.getLocalPart());

    try {/* w w  w.  j  av  a 2s.  co  m*/
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        Assert.fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}

From source file:org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.ServiceProcessor.java

private int isNonWrappable(BindingOperationInfo bop) {
    QName operationName = bop.getName();
    MessageInfo bodyMessage = null;/*from   w  w w  .  ja va2  s  .  co  m*/
    QName headerMessage = null;
    SoapHeader header = null;
    boolean containParts = false;
    boolean isSameMessage = false;
    boolean isNonWrappable = false;
    boolean allPartsHeader = false;
    int result = this.noHEADER;

    // begin process input
    if (bop.getInput() != null && bop.getInput().getExtensors(ExtensibilityElement.class) != null) {
        List<ExtensibilityElement> extensors = bop.getInput().getExtensors(ExtensibilityElement.class);
        if (extensors != null) {
            for (ExtensibilityElement ext : extensors) {
                if (SOAPBindingUtil.isSOAPBody(ext)) {
                    bodyMessage = getMessage(operationName, true);
                }
                if (SOAPBindingUtil.isSOAPHeader(ext)) {
                    header = SOAPBindingUtil.getSoapHeader(ext);
                    headerMessage = header.getMessage();
                    if (header.getPart().length() > 0) {
                        containParts = true;
                    }
                }
            }
        }

        if (headerMessage != null && bodyMessage != null
                && headerMessage.getNamespaceURI().equalsIgnoreCase(bodyMessage.getName().getNamespaceURI())
                && headerMessage.getLocalPart().equalsIgnoreCase(bodyMessage.getName().getLocalPart())) {
            isSameMessage = true;
        }

        isNonWrappable = isSameMessage && containParts;
        // if is nonwrapple then return
        if (isNonWrappable) {
            result = this.inHEADER;
        }
    }
    isSameMessage = false;
    containParts = false;

    // process output
    if (bop.getOutput() != null && bop.getOutput().getExtensors(ExtensibilityElement.class) != null) {
        List<ExtensibilityElement> extensors = bop.getOutput().getExtensors(ExtensibilityElement.class);
        if (extensors != null) {
            for (ExtensibilityElement ext : extensors) {
                if (SOAPBindingUtil.isSOAPBody(ext)) {
                    bodyMessage = getMessage(operationName, false);
                }
                if (SOAPBindingUtil.isSOAPHeader(ext)) {
                    header = SOAPBindingUtil.getSoapHeader(ext);
                    headerMessage = header.getMessage();
                    if (header.getPart().length() > 0) {
                        containParts = true;
                    }
                }
            }
        }
        if (headerMessage != null && bodyMessage != null
                && headerMessage.getNamespaceURI().equalsIgnoreCase(bodyMessage.getName().getNamespaceURI())
                && headerMessage.getLocalPart().equalsIgnoreCase(bodyMessage.getName().getLocalPart())) {
            isSameMessage = true;
            if (bodyMessage.getMessagePartsNumber() == 1) {
                allPartsHeader = true;
            }

        }
        isNonWrappable = isSameMessage && containParts;
        if (isNonWrappable && allPartsHeader) {
            result = this.resultHeader;
        }
        if (isNonWrappable && !allPartsHeader) {
            result = this.outHEADER;
        }
    }

    return result;
}