Search in sources :

Example 1 with JavaReturn

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

the class OperationProcessor method addCallbackMethod.

private void addCallbackMethod(JavaMethod method) throws ToolException {
    JavaMethod callbackMethod = new JavaMethod(method.getInterface());
    callbackMethod.setAsync(true);
    callbackMethod.setName(method.getName() + ToolConstants.ASYNC_METHOD_SUFFIX);
    callbackMethod.setStyle(method.getStyle());
    callbackMethod.setWrapperStyle(method.isWrapperStyle());
    callbackMethod.setSoapAction(method.getSoapAction());
    callbackMethod.setOperationName(method.getOperationName());
    JavaReturn future = new JavaReturn();
    future.setClassName("Future<?>");
    callbackMethod.setReturn(future);
    // REVISIT: test the operation name in the annotation
    callbackMethod.annotate(new WebMethodAnnotator());
    callbackMethod.addAnnotation("ResponseWrapper", method.getAnnotationMap().get("ResponseWrapper"));
    callbackMethod.addAnnotation("RequestWrapper", method.getAnnotationMap().get("RequestWrapper"));
    callbackMethod.addAnnotation("SOAPBinding", method.getAnnotationMap().get("SOAPBinding"));
    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);
                    callbackMethod.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 {
                callbackMethod.addParameter(param);
            }
        } else {
            callbackMethod.addParameter(param);
        }
    }
    JavaParameter asyncHandler = new JavaParameter();
    asyncHandler.setName("asyncHandler");
    asyncHandler.setCallback(true);
    asyncHandler.setClassName(getAsyncClassName(method, "AsyncHandler", asyncCname));
    asyncHandler.setStyle(JavaType.Style.IN);
    callbackMethod.addParameter(asyncHandler);
    JAnnotation asyncHandlerAnnotation = new JAnnotation(WebParam.class);
    asyncHandlerAnnotation.addElement(new JAnnotationElement("name", "asyncHandler"));
    asyncHandlerAnnotation.addElement(new JAnnotationElement("targetNamespace", ""));
    asyncHandler.addAnnotation("WebParam", asyncHandlerAnnotation);
    method.getInterface().addImport("javax.jws.WebParam");
    method.getInterface().addMethod(callbackMethod);
}
Also used : JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) 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 2 with JavaReturn

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

the class ParameterProcessor method processReturn.

private void processReturn(JavaMethod method, MessagePartInfo part) {
    String name = part == null ? "return" : part.getName().getLocalPart();
    String type = part == null ? "void" : ProcessorUtil.resolvePartType(part, context);
    String namespace = part == null ? null : ProcessorUtil.resolvePartNamespace(part);
    JavaReturn returnType = new JavaReturn(name, type, namespace);
    if (part != null) {
        returnType.setDefaultValueWriter(ProcessorUtil.getDefaultValueWriter(part, context));
    }
    returnType.setQName(ProcessorUtil.getElementName(part));
    returnType.setStyle(JavaType.Style.OUT);
    if (namespace != null && type != null && !"void".equals(type)) {
        returnType.setClassName(ProcessorUtil.getFullClzName(part, context, false));
    }
    if (part != null && part.getXmlSchema() instanceof XmlSchemaSimpleType) {
        processXmlSchemaSimpleType((XmlSchemaSimpleType) part.getXmlSchema(), method, part);
    } else if (part != null && part.getXmlSchema() instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement) part.getXmlSchema();
        if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
            processXmlSchemaSimpleType((XmlSchemaSimpleType) element.getSchemaType(), method, part);
        }
    }
    method.setReturn(returnType);
}
Also used : JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement)

Example 3 with JavaReturn

use of org.apache.cxf.tools.common.model.JavaReturn 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 4 with JavaReturn

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

the class ParameterProcessor method addVoidReturn.

private void addVoidReturn(JavaMethod method) {
    JavaReturn returnType = new JavaReturn("return", "void", null);
    method.setReturn(returnType);
}
Also used : JavaReturn(org.apache.cxf.tools.common.model.JavaReturn)

Example 5 with JavaReturn

use of org.apache.cxf.tools.common.model.JavaReturn 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)

Aggregations

JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)8 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)5 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)4 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)2 OperationInfo (org.apache.cxf.service.model.OperationInfo)2 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)2 JavaException (org.apache.cxf.tools.common.model.JavaException)2 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)2 WebMethodAnnotator (org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator)2 QName (javax.xml.namespace.QName)1 Message (org.apache.cxf.common.i18n.Message)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 ToolException (org.apache.cxf.tools.common.ToolException)1 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)1