Package org.apache.cxf.tools.common.model

Examples of org.apache.cxf.tools.common.model.JavaMethod


        JAnnotation jaxbAnnotation = new JAnnotation(XmlList.class);
        if (jn instanceof JavaParameter) {
            JavaParameter jp = (JavaParameter)jn;
            jp.addAnnotation("XmlList", jaxbAnnotation);
        } else if (jn instanceof JavaMethod) {
            JavaMethod jm = (JavaMethod)jn;
            jm.addAnnotation("XmlList", jaxbAnnotation);
        } else {
            throw new RuntimeException("XmlList can only annotate to JavaParameter or JavaMethod");
        }
       
        jf.addImport(XmlList.class.getName());
View Full Code Here


        if (ja instanceof JavaParameter) {
            parameter = (JavaParameter) ja;
        } else {
            throw new RuntimeException("WebParamAnnotator only annotate the JavaParameter");
        }
        JavaMethod method = parameter.getMethod();

        if (method.hasParameter(parameter.getName())) {
            JavaParameter paramInList = method.getParameter(parameter.getName());
            if (paramInList.isIN() && parameter.isOUT()) {
                parameter.setStyle(JavaType.Style.INOUT);
            }
        }

        JAnnotation webParamAnnotation = new JAnnotation(WebParam.class);
        String name = parameter.getName();
        String targetNamespace = method.getInterface().getNamespace();
        String partName = null;

        if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT
            || parameter.isHeader()) {
            targetNamespace = parameter.getTargetNamespace();

            if (parameter.getQName() != null) {
                name = parameter.getQName().getLocalPart();
            }
            if (!method.isWrapperStyle()) {
                partName = parameter.getPartName();
            }
        }

        if (method.getSoapStyle() == SOAPBinding.Style.RPC) {
            name = parameter.getPartName();
            partName = parameter.getPartName();
        }

        if (partName != null) {
            webParamAnnotation.addElement(new JAnnotationElement("partName", partName));
        }
        if (parameter.getStyle() == JavaType.Style.OUT) {
            webParamAnnotation.addElement(new JAnnotationElement("mode", WebParam.Mode.OUT));
        } else if (parameter.getStyle() == JavaType.Style.INOUT) {
            webParamAnnotation.addElement(new JAnnotationElement("mode", WebParam.Mode.INOUT));
        }
        webParamAnnotation.addElement(new JAnnotationElement("name", name));
        if (null != targetNamespace
                && (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT || parameter.isHeader())) {       
            webParamAnnotation.addElement(new JAnnotationElement("targetNamespace",
                                                                        targetNamespace));       
        }
        for (String importClz : webParamAnnotation.getImports()) {
            parameter.getMethod().getInterface().addImport(importClz);
View Full Code Here

        jaxbAnnotation.addElement(new JAnnotationElement("value", adapter));
        if (jn instanceof JavaParameter) {
            JavaParameter jp = (JavaParameter)jn;
            jp.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
        } else if (jn instanceof JavaMethod) {
            JavaMethod jm = (JavaMethod)jn;
            jm.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
        } else {
            throw new RuntimeException("Annotation of " + jn.getClass() + " not supported.");
        }
        jf.addImport(XmlJavaTypeAdapter.class.getName());
        jf.addImport(adapter.getName());
View Full Code Here

            jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
        }

        Object[] methods = jf.getMethods().toArray();
        for (int i = 0; i < methods.length; i++) {
            JavaMethod jm = (JavaMethod)methods[i];
            if (jm.getOperationName() != null && jm.getOperationName().equals(bop.getName().getLocalPart())) {
                if (isSoapBinding()) {
                    // TODO: add customize here
                    //doCustomizeOperation(jf, jm, bop);
                    Map<String, Object> prop = getSoapOperationProp(bop);
                    String soapAction = prop.get(soapOPAction) == null ? "" : (String)prop.get(soapOPAction);
                    String soapStyle = prop.get(soapOPStyle) == null ? "" : (String)prop.get(soapOPStyle);
                    jm.setSoapAction(soapAction);

                    if (SOAPBindingUtil.getSoapStyle(soapStyle) == null && this.bindingObj == null) {
                        org.apache.cxf.common.i18n.Message msg =
                            new  org.apache.cxf.common.i18n.Message("BINDING_STYLE_NOT_DEFINED",
                                                                         LOG);
                        throw new ToolException(msg);
                    }
                    if (SOAPBindingUtil.getSoapStyle(soapStyle) == null) {
                        jm.setSoapStyle(jf.getSOAPStyle());
                    } else {
                        jm.setSoapStyle(SOAPBindingUtil.getSoapStyle(soapStyle));
                    }
                } else {
                    // REVISIT: fix for xml binding
                    jm.setSoapStyle(jf.getSOAPStyle());
                }

                if (jm.getSoapStyle().equals(javax.jws.soap.SOAPBinding.Style.RPC)) {
                    jm.getAnnotationMap().remove("SOAPBinding");
                }

                OperationProcessor processor = new OperationProcessor(context);

                int headerType = isNonWrappable(bop);

                OperationInfo opinfo = bop.getOperationInfo();

                JAXWSBinding opBinding = opinfo.getExtensor(JAXWSBinding.class);
                JAXWSBinding infBinding = opinfo.getInterface().getExtensor(JAXWSBinding.class);
                boolean enableMime = enableOpMime;
                boolean enableWrapperStyle = true;
               
                if (infBinding != null && infBinding.isSetEnableWrapperStyle()) {
                    enableWrapperStyle = infBinding.isEnableWrapperStyle();
                }
                if (infBinding != null && infBinding.isSetEnableMime()) {
                    enableMime = infBinding.isEnableMime();
                }
                if (opBinding != null && opBinding.isSetEnableWrapperStyle()) {
                    enableWrapperStyle = opBinding.isEnableWrapperStyle();
                }
                if (opBinding != null && opBinding.isSetEnableMime()) {
                    enableMime = opBinding.isEnableMime();
                }
                if (jaxwsBinding.isEnableMime() || enableMime) {
                    jm.setMimeEnable(true);
                }
                if ((jm.isWrapperStyle() && headerType > this.noHEADER)
                    || !jaxwsBinding.isEnableWrapperStyle()
                    || (jm.enableMime() && jm.isWrapperStyle())
                    || !enableWrapperStyle) {
                    // changed wrapper style

                    jm.setWrapperStyle(false);
                    processor.processMethod(jm, bop.getOperationInfo());
                    jm.getAnnotationMap().remove("ResponseWrapper");
                    jm.getAnnotationMap().remove("RequestWrapper");

                } else {
                    processor.processMethod(jm, bop.getOperationInfo());
                }

                if (headerType == this.resultHeader) {
                    JAnnotation resultAnno = jm.getAnnotationMap().get("WebResult");
                    if (resultAnno != null) {
                        resultAnno.addElement(new JAnnotationElement("header", true, true));
                    }
                }
                processParameter(jm, bop);
View Full Code Here

import org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.ProcessorUtil;

public final class MethodMapper {

    public JavaMethod map(OperationInfo operation) {
        JavaMethod method = new JavaMethod();
        // set default Document Bare style
        method.setSoapStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);

        String operationName = operation.getName().getLocalPart();

        method.setName(ProcessorUtil.mangleNameToVariableName(operationName));
        method.setOperationName(operationName);

        JAXWSBinding opBinding = operation.getExtensor(JAXWSBinding.class);
        if (opBinding != null
            && opBinding.getMethodName() != null) {
            method.setName(opBinding.getMethodName());
        }
       
        if (opBinding != null
            && opBinding.getMethodJavaDoc() != null) {
            method.setJavaDoc(opBinding.getMethodJavaDoc());
        } else {
            method.setJavaDoc(operation.getDocumentation());
        }

        if (operation.isOneWay()) {
            method.setStyle(OperationType.ONE_WAY);
        } else {
            method.setStyle(OperationType.REQUEST_RESPONSE);
        }

        method.setWrapperStyle(operation.isUnwrappedCapable());

        return method;
    }
View Full Code Here

    public OperationProcessor(ToolContext c) {
        super(c);
    }

    public void process(JavaInterface intf, OperationInfo operation) throws ToolException {
        JavaMethod method = new MethodMapper().map(operation);
        method.setInterface(intf);
       
        processMethod(method, operation);
       
        Collection<FaultInfo> faults = operation.getFaults();
        FaultProcessor faultProcessor = new FaultProcessor(context);
        faultProcessor.process(method, faults);

        method.annotate(new WSActionAnnotator(operation));

        intf.addMethod(method);
    }
View Full Code Here

        method.getInterface().addImport("java.util.concurrent.Future");
        method.getInterface().addImport("javax.xml.ws.Response");
    }

    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);               
View Full Code Here

        method.getInterface().addImport("javax.jws.WebParam");
        method.getInterface().addMethod(callbackMethod);
    }

    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);
    }
View Full Code Here

            jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
        }

        Object[] methods = jf.getMethods().toArray();
        for (int i = 0; i < methods.length; i++) {
            JavaMethod jm = (JavaMethod)methods[i];
            if (jm.getOperationName() != null && jm.getOperationName().equals(bop.getName().getLocalPart())) {
                if (isSoapBinding()) {
                    // TODO: add customize here
                    //doCustomizeOperation(jf, jm, bop);
                    Map prop = getSoapOperationProp(bop);
                    String soapAction = prop.get(soapOPAction) == null ? "" : (String)prop.get(soapOPAction);
                    String soapStyle = prop.get(soapOPStyle) == null ? "" : (String)prop.get(soapOPStyle);
                    jm.setSoapAction(soapAction);

                    if (SOAPBindingUtil.getSoapStyle(soapStyle) == null && this.bindingObj == null) {
                        org.apache.cxf.common.i18n.Message msg =
                            new  org.apache.cxf.common.i18n.Message("BINDING_STYLE_NOT_DEFINED",
                                                                         LOG);
                        throw new ToolException(msg);
                    }
                    if (SOAPBindingUtil.getSoapStyle(soapStyle) == null) {
                        jm.setSoapStyle(jf.getSOAPStyle());
                    } else {
                        jm.setSoapStyle(SOAPBindingUtil.getSoapStyle(soapStyle));
                    }
                } else {
                    // REVISIT: fix for xml binding
                    jm.setSoapStyle(jf.getSOAPStyle());
                }

                if (jm.getSoapStyle().equals(javax.jws.soap.SOAPBinding.Style.RPC)) {
                    jm.getAnnotationMap().remove("SOAPBinding");
                }

                OperationProcessor processor = new OperationProcessor(context);

                int headerType = isNonWrappable(bop);

                OperationInfo opinfo = bop.getOperationInfo();

                JAXWSBinding opBinding = (JAXWSBinding)opinfo.getExtensor(JAXWSBinding.class);
                JAXWSBinding infBinding = (JAXWSBinding)opinfo.getInterface().getExtensor(JAXWSBinding.class);
                boolean enableMime = enableOpMime;
                boolean enableWrapperStyle = true;
               
                if (infBinding != null && infBinding.isSetEnableWrapperStyle()) {
                    enableWrapperStyle = infBinding.isEnableWrapperStyle();
                }
                if (infBinding != null && infBinding.isSetEnableMime()) {
                    enableMime = infBinding.isEnableMime();
                }
                if (opBinding != null && opBinding.isSetEnableWrapperStyle()) {
                    enableWrapperStyle = opBinding.isEnableWrapperStyle();
                }
                if (opBinding != null && opBinding.isSetEnableMime()) {
                    enableMime = opBinding.isEnableMime();
                }
                if (jaxwsBinding.isEnableMime() || enableMime) {
                    jm.setMimeEnable(true);
                }
                if ((jm.isWrapperStyle() && headerType > this.noHEADER)
                    || !jaxwsBinding.isEnableWrapperStyle()
                    || (jm.enableMime() && jm.isWrapperStyle())
                    || !enableWrapperStyle) {
                    // changed wrapper style

                    jm.setWrapperStyle(false);
                    processor.processMethod(jm, bop.getOperationInfo());
                    jm.getAnnotationMap().remove("ResponseWrapper");
                    jm.getAnnotationMap().remove("RequestWrapper");

                } else {
                    processor.processMethod(jm, bop.getOperationInfo());
                }

                if (headerType == this.resultHeader) {
                    JAnnotation resultAnno = jm.getAnnotationMap().get("WebResult");
                    if (resultAnno != null) {
                        resultAnno.addElement(new JAnnotationElement("header", true, true));
                    }
                }
                processParameter(jm, bop);
View Full Code Here

    public OperationProcessor(ToolContext c) {
        super(c);
    }

    public void process(JavaInterface intf, OperationInfo operation) throws ToolException {
        JavaMethod method = new MethodMapper().map(operation);
        method.setInterface(intf);
        processMethod(method, operation, null);
        Collection<FaultInfo> faults = operation.getFaults();
        FaultProcessor faultProcessor = new FaultProcessor(context);
        faultProcessor.process(method, faults);

        method.annotate(new WSActionAnnotator(operation));

        intf.addMethod(method);
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.tools.common.model.JavaMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.