Search in sources :

Example 1 with JavaParameter

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

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

the class ParameterProcessor method processInput.

private void processInput(JavaMethod method, MessageInfo inputMessage) throws ToolException {
    if (requireOutOfBandHeader()) {
        try {
            Class.forName("org.apache.cxf.binding.soap.SoapBindingFactory");
        } catch (Exception e) {
            LOG.log(Level.WARNING, new Message("SOAP_MISSING", LOG).toString());
        }
    }
    JAXWSBinding mBinding = inputMessage.getOperation().getExtensor(JAXWSBinding.class);
    for (MessagePartInfo part : inputMessage.getMessageParts()) {
        if (isOutOfBandHeader(part) && !requireOutOfBandHeader()) {
            continue;
        }
        JavaParameter param = getParameterFromPart(method, part, JavaType.Style.IN);
        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);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) JAXWSParameter(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ToolException(org.apache.cxf.tools.common.ToolException)

Example 3 with JavaParameter

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

the class ParameterProcessor method getParameterFromQName.

private JavaParameter getParameterFromQName(QName wrapperElement, QName item, JavaType.Style style, MessagePartInfo part) {
    String fullJavaName = "";
    fullJavaName = this.dataBinding.getWrappedElementType(wrapperElement, item);
    String targetNamespace = item.getNamespaceURI();
    String jpname = ProcessorUtil.mangleNameToVariableName(item.getLocalPart());
    JavaParameter parameter = new JavaParameter(jpname, fullJavaName, targetNamespace);
    parameter.setStyle(style);
    parameter.setQName(item);
    parameter.setDefaultValueWriter(ProcessorUtil.getDefaultValueWriterForWrappedElement(part, context, item));
    if (style == JavaType.Style.OUT || style == JavaType.Style.INOUT) {
        parameter.setHolder(true);
        parameter.setHolderName(javax.xml.ws.Holder.class.getName());
        String holderClass = fullJavaName;
        if (JAXBUtils.holderClass(fullJavaName) != null) {
            holderClass = JAXBUtils.holderClass(fullJavaName).getName();
        }
        parameter.setClassName(holderClass);
    }
    return parameter;
}
Also used : JavaParameter(org.apache.cxf.tools.common.model.JavaParameter)

Example 4 with JavaParameter

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

the class ParameterProcessorTest method testAddParameter.

@Test
public void testAddParameter() throws Exception {
    ParameterProcessor processor = new ParameterProcessor(new ToolContext());
    JavaMethod method = new JavaMethod();
    JavaParameter p1 = new JavaParameter("request", String.class.getName(), null);
    p1.setStyle(JavaType.Style.IN);
    processor.addParameter(null, method, p1);
    JavaParameter p2 = new JavaParameter("request", String.class.getName(), null);
    p2.setStyle(JavaType.Style.OUT);
    processor.addParameter(null, method, p2);
    assertEquals(1, method.getParameters().size());
    assertEquals(JavaType.Style.INOUT, method.getParameters().get(0).getStyle());
}
Also used : JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) ToolContext(org.apache.cxf.tools.common.ToolContext) Test(org.junit.Test)

Example 5 with JavaParameter

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

the class WebParamAnnotatorTest method setUp.

@Before
public void setUp() {
    method = new JavaMethod();
    parameter = new JavaParameter();
    parameter.setMethod(method);
}
Also used : JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) Before(org.junit.Before)

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