Example usage for javax.xml.namespace QName getLocalPart

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

Introduction

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

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part 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/*from   w  w w . ja v  a 2 s .  c o  m*/
 * @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

/**
 * @param doc//from w ww  . ja v a 2 s  .c  o m
 * @param operation
 * @return Returns the parameter element.
 */
protected Element[] getInputParamElement(Document doc, AxisOperation operation) {

    AxisMessage inputMessage = operation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    List paramElementList = new ArrayList();
    if (inputMessage != null) {

        // This is the  wrapped component - add the type mapping
        Element mainParameter = generateParamComponent(doc, inputMessage.getDocumentation(),
                this.mapper.getParameterName(inputMessage.getElementQName()),
                this.mapper.getTypeMappingName(inputMessage.getElementQName()), operation.getName(),
                inputMessage.getElementQName(), inputMessage.getPartName(), false, false);

        paramElementList.add(mainParameter);

        //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 (inputMessage.getParameter(Constants.COMPLEX_TYPE) != null) {
                Parameter parameter = inputMessage.getParameter(Constants.COMPLEX_TYPE);
                addAttribute(doc, "complextype", (String) parameter.getValue(), mainParameter);
            }
        }

        //added the unwapparameters attribute this is use full to unwrap if paramerters are
        //zero
        if (!this.codeGenConfiguration.isParametersWrapped()) {
            addAttribute(doc, "unwrappParameters", "true", mainParameter);
        }

        // 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 (inputMessage.getParameter(Constants.UNWRAPPED_KEY) != null) {

            //we have this unwrapped earlier. get the info holder
            //and then look at the parameters
            Parameter detailsParameter = inputMessage.getParameter(Constants.UNWRAPPED_DETAILS);
            MessagePartInformationHolder infoHolder = (MessagePartInformationHolder) detailsParameter
                    .getValue();
            List partsList = infoHolder.getPartsList();
            wrapped_jaxws = true;
            //populate the parts list - this list is needed to generate multiple
            //parameters in the signatures
            //todo documentation is kept empty(null) in this scenario
            for (int i = 0; i < partsList.size(); i++) {
                QName qName = (QName) partsList.get(i);
                mainParameter.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))));
            }

        }

    }

    return (Element[]) paramElementList.toArray(new Element[paramElementList.size()]);
}

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

/**
 * A convenient method for the generating the parameter element
 *
 * @param doc//from   w w  w  .j  a va2s  . 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 av  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 ww.j a  v  a  2s.  c om
 * @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;/*  ww  w . j a  v  a  2s  .c om*/

    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);
            }//from w ww  . j  a  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   ww  w .  j  av  a  2  s  .  c om
    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/* ww w .  ja va 2 s  .  c  o 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 ww .j  a v  a  2  s .  co m*/
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        Assert.fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}