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

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


public class ParameterProcessorTest extends Assert {
    @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(method, p1);

        JavaParameter p2 = new JavaParameter("request", String.class.getName(), null);
        p2.setStyle(JavaType.Style.OUT);
        processor.addParameter(method, p2);

        assertEquals(1, method.getParameters().size());
        assertEquals(JavaType.Style.INOUT, method.getParameters().get(0).getStyle());
    }
View Full Code Here


import org.apache.cxf.tools.common.model.JavaMethod;

public class WebMethodAnnotator implements Annotator {

    public void annotate(JavaAnnotatable ja) {
        JavaMethod method = null;
        if (ja instanceof JavaMethod) {
            method = (JavaMethod) ja;
        } else {
            throw new RuntimeException("WebMethod can only annotate JavaMethod");
        }
        String operationName = method.getOperationName();
        JAnnotation methodAnnotation = new JAnnotation(WebMethod.class);
       
        if (!method.getName().equals(operationName)) {
            methodAnnotation.addElement(new JAnnotationElement("operationName", operationName));
        }
        if (!StringUtils.isEmpty(method.getSoapAction())) {
            methodAnnotation.addElement(new JAnnotationElement("action", method.getSoapAction()));
        }
        method.addAnnotation("WebMethod", methodAnnotation);
    }
View Full Code Here

    JavaMethod method;
    JavaParameter parameter;

    @Before
    public void setUp() {
        method = new JavaMethod();
        parameter = new JavaParameter();
        parameter.setMethod(method);
    }
View Full Code Here

        return operation;
    }
   
    @Test
    public void testMap() throws Exception {
        JavaMethod method = new MethodMapper().map(getOperation());
        assertNotNull(method);

        assertEquals(javax.jws.soap.SOAPBinding.Style.DOCUMENT, method.getSoapStyle());
        assertEquals("operationTest", method.getName());
        assertEquals("OperationTest", method.getOperationName());
        assertEquals(OperationType.REQUEST_RESPONSE, method.getStyle());
        assertFalse(method.isWrapperStyle());
        assertFalse(method.isOneWay());
    }
View Full Code Here

        OperationInfo operation = getOperation();

        MessageInfo inputMessage = operation.createMessage(new QName("urn:test:ns", "testInputMessage"));
        operation.setInput("input", inputMessage);

        JavaMethod method = new MethodMapper().map(operation);
        assertNotNull(method);
        assertTrue(method.isOneWay());
    }
View Full Code Here

    @Test
    public void testMapWrappedOperation() throws Exception {
        OperationInfo operation = getOperation();
        operation.setUnwrappedOperation(operation);

        JavaMethod method = new MethodMapper().map(operation);
        assertNotNull(method);
       
        assertTrue(method.isWrapperStyle());
    }
View Full Code Here

            List<JavaMethod> methods = intf.getMethods();
            assertEquals(6, methods.size());

            Boolean methodSame = false;
            JavaMethod m1 = null;
            for (JavaMethod m2 : methods) {
                if (m2.getName().equals("testDocLitFault")) {
                    methodSame = true;
                    m1 = m2;
                    break;
                }
            }
            assertTrue(methodSame);
           
            assertEquals(2, m1.getExceptions().size());
            assertEquals("BadRecordLitFault", m1.getExceptions().get(0).getName());
            assertEquals("NoSuchCodeLitFault", m1.getExceptions().get(1).getName());

            String address = null;

            for (JavaServiceClass service : javaModel.getServiceClasses().values()) {
                List<JavaPort> ports = (List<JavaPort>) service.getPorts();
View Full Code Here

import org.apache.cxf.tools.common.model.JavaMethod;

public class SoapBindingAnnotator implements Annotator {

    public void annotate(JavaAnnotatable ja) {
        JavaMethod method;
        if (ja instanceof JavaMethod) {
            method = (JavaMethod) ja;
        } else {
            throw new RuntimeException("SOAPBindingAnnotator can only annotate JavaMethod");
        }
        if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT) {
            if (!method.isWrapperStyle()
                && !SOAPBinding.ParameterStyle.BARE.equals(method.getInterface().getSOAPParameterStyle())) {
           
                JAnnotation bindingAnnotation = new JAnnotation(SOAPBinding.class);
                bindingAnnotation.addElement(new JAnnotationElement("parameterStyle",
                                                                           SOAPBinding.ParameterStyle.BARE));
                method.addAnnotation("SOAPBinding", bindingAnnotation);
            } else if (method.isWrapperStyle()
                && SOAPBinding.ParameterStyle.BARE.equals(method.getInterface().getSOAPParameterStyle())) {
                JAnnotation bindingAnnotation = new JAnnotation(SOAPBinding.class);
                bindingAnnotation.addElement(new JAnnotationElement("parameterStyle",
                                                                        SOAPBinding.ParameterStyle.WRAPPED));
                method.addAnnotation("SOAPBinding", bindingAnnotation);               
            }
        } else if (!SOAPBinding.Style.RPC.equals(method.getInterface().getSOAPStyle())) {
            JAnnotation bindingAnnotation = new JAnnotation(SOAPBinding.class);
            bindingAnnotation.addElement(new JAnnotationElement("style",
                                                                       SOAPBinding.Style.RPC));
            method.addAnnotation("SOAPBinding", bindingAnnotation);           
        }
    }
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));       
        }

        parameter.setAnnotation(webParamAnnotation);
View Full Code Here

        wrapperRequest = request;
        wrapperResponse = response;
    }
   
    public void annotate(JavaAnnotatable ja) {
        JavaMethod method;
        if (ja instanceof JavaMethod) {
            method = (JavaMethod) ja;
        } else {
            throw new RuntimeException("RequestWrapper and ResponseWrapper can only annotate JavaMethod");
        }
        if (wrapperRequest != null) {
            JAnnotation requestAnnotation = new JAnnotation(RequestWrapper.class);
            requestAnnotation.addElement(new JAnnotationElement("localName",
                                                                       wrapperRequest.getType()));
            requestAnnotation.addElement(new JAnnotationElement("targetNamespace",
                                                                       wrapperRequest.getTargetNamespace()));
            requestAnnotation.addElement(new JAnnotationElement("className",
                                                                       wrapperRequest.getClassName()));

            method.addAnnotation("RequestWrapper", requestAnnotation);
            method.getInterface().addImports(requestAnnotation.getImports());
        }
        if (wrapperResponse != null) {
            List<JAnnotationElement> elements = new ArrayList<JAnnotationElement>();
            elements.add(new JAnnotationElement("localName", wrapperResponse.getType()));
            elements.add(new JAnnotationElement("targetNamespace", wrapperResponse.getTargetNamespace()));
            elements.add(new JAnnotationElement("className", wrapperResponse.getClassName()));

            JAnnotation responseAnnotation = new JAnnotation(ResponseWrapper.class);
            responseAnnotation.getElements().addAll(elements);
            method.addAnnotation("ResponseWrapper", responseAnnotation);
            method.getInterface().addImports(responseAnnotation.getImports());
        }
    }
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.