Search in sources :

Example 6 with JavaMethod

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

the class WSActionAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaMethod method;
    if (ja instanceof JavaMethod) {
        method = (JavaMethod) ja;
    } else {
        throw new RuntimeException("Action can only annotate JavaMethod");
    }
    boolean required = false;
    JavaInterface intf = method.getInterface();
    MessageInfo inputMessage = operation.getInput();
    MessageInfo outputMessage = operation.getOutput();
    JAnnotation actionAnnotation = new JAnnotation(Action.class);
    if (inputMessage.getExtensionAttributes() != null) {
        String inputAction = getAction(inputMessage);
        if (inputAction != null) {
            actionAnnotation.addElement(new JAnnotationElement("input", inputAction));
            required = true;
        }
    }
    if (outputMessage != null && outputMessage.getExtensionAttributes() != null) {
        String outputAction = getAction(outputMessage);
        if (outputAction != null) {
            actionAnnotation.addElement(new JAnnotationElement("output", outputAction));
            required = true;
        }
    }
    if (operation.hasFaults()) {
        List<JAnnotation> faultAnnotations = new ArrayList<>();
        for (FaultInfo faultInfo : operation.getFaults()) {
            if (faultInfo.getExtensionAttributes() != null) {
                String faultAction = getAction(faultInfo);
                if (faultAction == null) {
                    continue;
                }
                JavaException exceptionClass = getExceptionClass(method, faultInfo);
                if (!StringUtils.isEmpty(exceptionClass.getPackageName()) && !exceptionClass.getPackageName().equals(intf.getPackageName())) {
                    intf.addImport(exceptionClass.getClassName());
                }
                JAnnotation faultAnnotation = new JAnnotation(FaultAction.class);
                faultAnnotation.addElement(new JAnnotationElement("className", exceptionClass));
                faultAnnotation.addElement(new JAnnotationElement("value", faultAction));
                faultAnnotations.add(faultAnnotation);
                required = true;
            }
        }
        actionAnnotation.addElement(new JAnnotationElement("fault", faultAnnotations));
    }
    if (required) {
        method.addAnnotation("Action", actionAnnotation);
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) FaultInfo(org.apache.cxf.service.model.FaultInfo) JavaException(org.apache.cxf.tools.common.model.JavaException) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) ArrayList(java.util.ArrayList) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 7 with JavaMethod

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

the class WebResultAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaMethod method = null;
    if (ja instanceof JavaMethod) {
        method = (JavaMethod) ja;
    } else {
        throw new RuntimeException("WebResult can only annotate JavaMethod");
    }
    if (method.isOneWay()) {
        JAnnotation oneWayAnnotation = new JAnnotation(Oneway.class);
        method.addAnnotation("Oneway", oneWayAnnotation);
        return;
    }
    if ("void".equals(method.getReturn().getType())) {
        return;
    }
    JAnnotation resultAnnotation = new JAnnotation(WebResult.class);
    String targetNamespace = method.getReturn().getTargetNamespace();
    String name = "return";
    if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT && !method.isWrapperStyle()) {
        name = method.getName() + "Response";
    }
    if (method.getSoapStyle() == SOAPBinding.Style.RPC) {
        name = method.getReturn().getName();
        targetNamespace = method.getInterface().getNamespace();
    }
    if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT) {
        if (method.getReturn().getQName() != null) {
            name = method.getReturn().getQName().getLocalPart();
        }
        targetNamespace = method.getReturn().getTargetNamespace();
    }
    resultAnnotation.addElement(new JAnnotationElement("name", name));
    if (null != targetNamespace) {
        resultAnnotation.addElement(new JAnnotationElement("targetNamespace", targetNamespace));
    }
    if (method.getSoapStyle() == SOAPBinding.Style.RPC || (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT && !method.isWrapperStyle())) {
        resultAnnotation.addElement(new JAnnotationElement("partName", method.getReturn().getName()));
    }
    method.addAnnotation("WebResult", resultAnnotation);
    method.getInterface().addImport("javax.jws.WebResult");
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Example 8 with JavaMethod

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

the class RequestWrapperTest method testNoAnnotationNoClass.

@Test
public void testNoAnnotationNoClass() throws Exception {
    String pkgName = "org.apache.cxf.tools.fortest.classnoanno.docwrapped";
    Class<?> testingClass = Class.forName(pkgName + ".Stock");
    OperationInfo opInfo = getOperation(testingClass, "getPrice");
    Wrapper wrapper = new RequestWrapper();
    wrapper.setOperationInfo(opInfo);
    assertTrue(wrapper.isWrapperAbsent());
    assertTrue(wrapper.isToDifferentPackage());
    assertFalse(wrapper.isWrapperBeanClassNotExist());
    assertEquals(pkgName + ".jaxws", wrapper.getJavaClass().getPackageName());
    assertEquals("GetPrice", wrapper.getJavaClass().getName());
    JavaClass jClass = wrapper.buildWrapperBeanClass();
    assertNotNull(jClass);
    List<JavaField> jFields = jClass.getFields();
    assertEquals(1, jFields.size());
    assertEquals("arg0", jFields.get(0).getName());
    assertEquals("java.lang.String", jFields.get(0).getClassName());
    List<JavaMethod> jMethods = jClass.getMethods();
    assertEquals(2, jMethods.size());
    JavaMethod jMethod = jMethods.get(0);
    assertEquals("getArg0", jMethod.getName());
    assertTrue(jMethod.getParameterListWithoutAnnotation().isEmpty());
    jMethod = jMethods.get(1);
    assertEquals("setArg0", jMethod.getName());
    assertEquals(1, jMethod.getParameterListWithoutAnnotation().size());
    assertEquals("java.lang.String newArg0", jMethod.getParameterListWithoutAnnotation().get(0));
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaField(org.apache.cxf.tools.common.model.JavaField) JavaClass(org.apache.cxf.tools.common.model.JavaClass) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Test(org.junit.Test)

Example 9 with JavaMethod

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

the class MethodMapper method map.

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;
}
Also used : JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)

Example 10 with JavaMethod

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

Aggregations

JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)28 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)14 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)11 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)9 Test (org.junit.Test)9 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)7 OperationInfo (org.apache.cxf.service.model.OperationInfo)6 JavaException (org.apache.cxf.tools.common.model.JavaException)5 JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)4 ArrayList (java.util.ArrayList)3 ToolContext (org.apache.cxf.tools.common.ToolContext)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 URISyntaxException (java.net.URISyntaxException)2 SOAPBinding (javax.jws.soap.SOAPBinding)2 QName (javax.xml.namespace.QName)2 FaultInfo (org.apache.cxf.service.model.FaultInfo)2 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)2