Search in sources :

Example 6 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class OperationProcessor method addPollingMethod.

private void addPollingMethod(JavaMethod method) throws ToolException {
    JavaMethod pollingMethod = new JavaMethod(method.getInterface());
    pollingMethod.setAsync(true);
    pollingMethod.setName(method.getName() + ToolConstants.ASYNC_METHOD_SUFFIX);
    pollingMethod.setStyle(method.getStyle());
    pollingMethod.setWrapperStyle(method.isWrapperStyle());
    pollingMethod.setSoapAction(method.getSoapAction());
    pollingMethod.setOperationName(method.getOperationName());
    boolean convertOutToAsync = !method.isWrapperStyle() && "void".equals(method.getReturn().getClassName());
    String asyncCname = null;
    for (JavaParameter param : method.getParameters()) {
        if (convertOutToAsync) {
            if (param.isHolder()) {
                if (param.isINOUT()) {
                    JavaParameter p2 = new JavaParameter();
                    p2.setName(param.getName());
                    p2.setClassName(param.getHolderName());
                    p2.setStyle(JavaType.Style.IN);
                    pollingMethod.addParameter(p2);
                    for (String s : param.getAnnotationTags()) {
                        JAnnotation ann = param.getAnnotation(s);
                        p2.addAnnotation(s, ann);
                    }
                } else if (!param.isHeader() && asyncCname == null) {
                    asyncCname = param.getClassName();
                }
            } else {
                pollingMethod.addParameter(param);
            }
        } else {
            pollingMethod.addParameter(param);
        }
    }
    JavaReturn response = new JavaReturn();
    response.setClassName(getAsyncClassName(method, "Response", asyncCname));
    pollingMethod.setReturn(response);
    // REVISIT: test the operation name in the annotation
    pollingMethod.annotate(new WebMethodAnnotator());
    pollingMethod.addAnnotation("RequestWrapper", method.getAnnotationMap().get("RequestWrapper"));
    pollingMethod.addAnnotation("ResponseWrapper", method.getAnnotationMap().get("ResponseWrapper"));
    pollingMethod.addAnnotation("SOAPBinding", method.getAnnotationMap().get("SOAPBinding"));
    method.getInterface().addMethod(pollingMethod);
}
Also used : JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) WebMethodAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator)

Example 7 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class OperationProcessor method setWrapper.

private void setWrapper(OperationInfo operation) {
    MessagePartInfo inputPart = null;
    if (operation.getInput() != null) {
        inputPart = operation.getInput().getFirstMessagePart();
    }
    MessagePartInfo outputPart = null;
    if (operation.getOutput() != null) {
        outputPart = operation.getOutput().getFirstMessagePart();
    }
    if (inputPart != null) {
        wrapperRequest = new JavaParameter();
        wrapperRequest.setName(ProcessorUtil.resolvePartName(inputPart));
        wrapperRequest.setType(ProcessorUtil.getPartType(inputPart));
        wrapperRequest.setTargetNamespace(ProcessorUtil.resolvePartNamespace(inputPart));
        wrapperRequest.setClassName(ProcessorUtil.getFullClzName(inputPart, context, false));
    }
    if (outputPart != null) {
        wrapperResponse = new JavaParameter();
        wrapperResponse.setName(ProcessorUtil.resolvePartName(outputPart));
        wrapperResponse.setType(ProcessorUtil.getPartType(outputPart));
        wrapperResponse.setTargetNamespace(ProcessorUtil.resolvePartNamespace(outputPart));
        wrapperResponse.setClassName(ProcessorUtil.getFullClzName(outputPart, context, false));
    }
}
Also used : JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 8 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class ParameterProcessor method processWrappedInput.

private void processWrappedInput(JavaMethod method, MessageInfo inputMessage) throws ToolException {
    if (messagePartsNotUnique(inputMessage)) {
        processInput(method, inputMessage);
        return;
    } else if (inputMessage.getMessagePartsNumber() == 0) {
        return;
    }
    MessagePartInfo part = inputMessage.getFirstMessagePart();
    List<QName> wrappedElements = ProcessorUtil.getWrappedElementQNames(context, part.getElementQName());
    if ((wrappedElements == null || wrappedElements.isEmpty()) && countOutOfBandHeader(inputMessage) == 0) {
        return;
    }
    for (QName item : wrappedElements) {
        JavaParameter jp = getParameterFromQName(part.getElementQName(), item, JavaType.Style.IN, part);
        checkPartName(inputMessage, item, jp);
        if (StringUtils.isEmpty(part.getConcreteName().getNamespaceURI())) {
            jp.setTargetNamespace("");
        }
        addParameter(part, method, jp);
    }
    // Adding out of band headers
    if (requireOutOfBandHeader() && countOutOfBandHeader(inputMessage) > 0) {
        for (MessagePartInfo hpart : inputMessage.getMessageParts()) {
            if (!isOutOfBandHeader(hpart)) {
                continue;
            }
            addParameter(hpart, method, getParameterFromPart(method, hpart, JavaType.Style.IN));
        }
    }
}
Also used : QName(javax.xml.namespace.QName) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 9 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class ParameterProcessor method processWrappedAbstractOutput.

private void processWrappedAbstractOutput(JavaMethod method, MessageInfo inputMessage, MessageInfo outputMessage) throws ToolException {
    if (messagePartsNotUnique(inputMessage) || messagePartsNotUnique(outputMessage)) {
        processOutput(method, inputMessage, outputMessage);
        return;
    }
    if (outputMessage.getMessagePartsNumber() == 0) {
        addVoidReturn(method);
        return;
    }
    MessagePartInfo inputPart = inputMessage.getMessagePartsNumber() > 0 ? inputMessage.getFirstMessagePart() : null;
    MessagePartInfo outputPart = outputMessage.getMessagePartsNumber() > 0 ? outputMessage.getFirstMessagePart() : null;
    List<QName> inputWrapElement = null;
    List<QName> outputWrapElement = null;
    if (inputPart != null) {
        inputWrapElement = ProcessorUtil.getWrappedElementQNames(context, inputPart.getElementQName());
    }
    if (outputPart != null) {
        outputWrapElement = ProcessorUtil.getWrappedElementQNames(context, outputPart.getElementQName());
    }
    if (inputWrapElement == null || outputWrapElement.isEmpty()) {
        addVoidReturn(method);
        return;
    }
    method.setReturn(null);
    boolean qualified = ProcessorUtil.isSchemaFormQualified(context, outputPart.getElementQName());
    if (outputWrapElement.size() == 1) {
        QName outElement = outputWrapElement.iterator().next();
        boolean sameWrapperChild = false;
        for (QName inElement : inputWrapElement) {
            if (isSameWrapperChild(inElement, outElement)) {
                JavaParameter jpIn = null;
                for (JavaParameter j : method.getParameters()) {
                    if (inElement.equals(j.getQName())) {
                        jpIn = j;
                    }
                }
                JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.INOUT, outputPart);
                if (!qualified && !isRefElement(outputPart, outElement)) {
                    jp.setTargetNamespace("");
                }
                if (jpIn != null && !jpIn.getClassName().equals(jp.getClassName())) {
                    jp.setStyle(JavaType.Style.OUT);
                }
                addParameter(outputPart, method, jp);
                sameWrapperChild = true;
                if (method.getReturn() == null) {
                    addVoidReturn(method);
                }
                break;
            }
        }
        if (!sameWrapperChild) {
            JavaReturn jreturn = getReturnFromQName(outElement, outputPart);
            if (!qualified && !this.isRefElement(outputPart, outElement)) {
                jreturn.setTargetNamespace("");
            }
            method.setReturn(jreturn);
        }
        return;
    }
    for (QName outElement : outputWrapElement) {
        if ("return".equals(outElement.getLocalPart())) {
            if (method.getReturn() != null) {
                org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("WRAPPER_STYLE_TWO_RETURN_TYPES", LOG);
                throw new ToolException(msg);
            }
            JavaReturn jreturn = getReturnFromQName(outElement, outputPart);
            if (!qualified) {
                jreturn.setTargetNamespace("");
            }
            method.setReturn(jreturn);
            continue;
        }
        boolean sameWrapperChild = false;
        if (inputWrapElement != null) {
            for (QName inElement : inputWrapElement) {
                if (isSameWrapperChild(inElement, outElement)) {
                    JavaParameter jpIn = null;
                    for (JavaParameter j : method.getParameters()) {
                        if (inElement.equals(j.getQName())) {
                            jpIn = j;
                        }
                    }
                    JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.INOUT, outputPart);
                    if (!qualified && !isRefElement(outputPart, outElement)) {
                        jp.setTargetNamespace("");
                    }
                    if (jpIn != null && !jpIn.getClassName().equals(jp.getClassName())) {
                        jp.setStyle(JavaType.Style.OUT);
                        checkPartName(outputMessage, outElement, jp);
                    }
                    addParameter(outputPart, method, jp);
                    sameWrapperChild = true;
                    break;
                }
            }
        }
        if (!sameWrapperChild) {
            JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.OUT, outputPart);
            if (!qualified && !isRefElement(outputPart, outElement)) {
                jp.setTargetNamespace("");
            }
            checkPartName(outputMessage, outElement, jp);
            addParameter(outputPart, method, jp);
        }
    }
    if (method.getReturn() == null) {
        addVoidReturn(method);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) Message(org.apache.cxf.common.i18n.Message) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) ToolException(org.apache.cxf.tools.common.ToolException)

Example 10 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class ParameterProcessor method processOutput.

private void processOutput(JavaMethod method, MessageInfo inputMessage, MessageInfo outputMessage) throws ToolException {
    Map<QName, MessagePartInfo> inputPartsMap = inputMessage.getMessagePartsMap();
    List<MessagePartInfo> outputParts = outputMessage == null ? new ArrayList<>() : outputMessage.getMessageParts();
    // figure out output parts that are not present in input parts
    List<MessagePartInfo> outParts = new ArrayList<>();
    int numHeader = 0;
    if (isRequestResponse(method)) {
        for (MessagePartInfo outpart : outputParts) {
            boolean oob = false;
            if (isOutOfBandHeader(outpart)) {
                if (!requireOutOfBandHeader()) {
                    continue;
                }
                oob = true;
            }
            MessagePartInfo inpart = inputPartsMap.get(outpart.getName());
            if (inpart == null) {
                outParts.add(outpart);
                if (oob) {
                    numHeader++;
                }
                continue;
            } else if (isSamePart(inpart, outpart)) {
                boolean found = false;
                for (JavaParameter p : method.getParameters()) {
                    if (p.getQName().equals(ProcessorUtil.getElementName(outpart)) && p.getPartName().equals(outpart.getName().getLocalPart())) {
                        p.setHolder(true);
                        p.setHolderName(javax.xml.ws.Holder.class.getName());
                        String holderClass = p.getClassName();
                        if (JAXBUtils.holderClass(holderClass) != null) {
                            holderClass = JAXBUtils.holderClass(holderClass).getName();
                        }
                        p.setClassName(holderClass);
                        p.getAnnotations().clear();
                        p.setStyle(JavaType.Style.INOUT);
                        p.annotate(new WebParamAnnotator(isOutOfBandHeader(outpart)));
                        found = true;
                    }
                }
                if (!found) {
                    addParameter(outpart, method, getParameterFromPart(method, outpart, JavaType.Style.INOUT));
                }
                continue;
            } else if (!isSamePart(inpart, outpart)) {
                if (oob) {
                    numHeader++;
                }
                outParts.add(outpart);
                continue;
            }
        }
    }
    if (isRequestResponse(method)) {
        if (outParts.size() - numHeader == 1 && !isHeader(outParts.get(0))) {
            processReturn(method, outParts.get(0));
            outParts.remove(0);
        } else {
            processReturn(method, null);
        }
        JAXWSBinding mBinding = outputMessage.getOperation().getExtensor(JAXWSBinding.class);
        for (MessagePartInfo part : outParts) {
            JavaParameter param = getParameterFromPart(method, part, JavaType.Style.OUT);
            if (mBinding != null && mBinding.getJaxwsParas() != null) {
                for (JAXWSParameter jwp : mBinding.getJaxwsParas()) {
                    if (part.getName().getLocalPart().equals(jwp.getPart())) {
                        param.setName(jwp.getName());
                    }
                }
            }
            addParameter(part, method, param);
        }
    } else {
        processReturn(method, null);
    }
}
Also used : QName(javax.xml.namespace.QName) JAXWSParameter(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter) ArrayList(java.util.ArrayList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) WebParamAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebParamAnnotator) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)

Aggregations

JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)18 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)9 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)6 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)5 JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)5 QName (javax.xml.namespace.QName)4 Message (org.apache.cxf.common.i18n.Message)3 ToolException (org.apache.cxf.tools.common.ToolException)3 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)3 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)2 OperationInfo (org.apache.cxf.service.model.OperationInfo)2 JavaException (org.apache.cxf.tools.common.model.JavaException)2 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)2 JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)2 JAXWSParameter (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter)2