Search in sources :

Example 6 with JAnnotationElement

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

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

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

the class XmlSeeAlsoAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    if (collector == null || collector.getTypesPackages().isEmpty()) {
        return;
    }
    JavaInterface intf = null;
    if (ja instanceof JavaInterface) {
        intf = (JavaInterface) ja;
    } else {
        throw new RuntimeException("XmlSeeAlso can only annotate JavaInterface");
    }
    JAnnotation jaxbAnnotation = new JAnnotation(XmlSeeAlso.class);
    intf.addImports(jaxbAnnotation.getImports());
    List<JavaType> types = new ArrayList<>();
    for (String pkg : collector.getTypesPackages()) {
        if (pkg.equals(intf.getPackageName())) {
            types.add(new JavaType(null, "ObjectFactory", null));
        } else {
            types.add(new JavaType(null, pkg + ".ObjectFactory", null));
        }
    }
    jaxbAnnotation.addElement(new JAnnotationElement(null, types));
    intf.addAnnotation(jaxbAnnotation);
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaType(org.apache.cxf.tools.common.model.JavaType) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) ArrayList(java.util.ArrayList)

Example 9 with JAnnotationElement

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

the class WebMethodAnnotatorTest method testAddWebResultAnnotation.

@Test
public void testAddWebResultAnnotation() throws Exception {
    JavaMethod method = new JavaMethod();
    method.annotate(new WebResultAnnotator());
    Map<String, JAnnotation> annotations = method.getAnnotationMap();
    assertNotNull(annotations);
    assertEquals(1, annotations.size());
    assertEquals("WebResult", annotations.keySet().iterator().next());
    JAnnotation resultAnnotation = annotations.get("WebResult");
    assertEquals("@WebResult(name = \"return\")", resultAnnotation.toString());
    List<JAnnotationElement> elements = resultAnnotation.getElements();
    assertNotNull(elements);
    assertEquals(1, elements.size());
    assertEquals("name", elements.get(0).getName());
    assertEquals("return", elements.get(0).getValue());
}
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) Test(org.junit.Test)

Example 10 with JAnnotationElement

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

the class WebParamAnnotatorTest method testAnnotateDOCBare.

@Test
public void testAnnotateDOCBare() throws Exception {
    init(method, parameter, SOAPBinding.Style.DOCUMENT, false);
    parameter.annotate(new WebParamAnnotator());
    JAnnotation annotation = parameter.getAnnotation("WebParam");
    assertEquals("@WebParam(partName = \"y\", name = \"x\", " + "targetNamespace = \"http://apache.org/cxf\")", annotation.toString());
    List<JAnnotationElement> elements = annotation.getElements();
    assertEquals(3, elements.size());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) Test(org.junit.Test)

Aggregations

JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)20 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)20 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)11 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)6 ArrayList (java.util.ArrayList)4 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)3 Test (org.junit.Test)3 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)2 Message (org.apache.cxf.common.i18n.Message)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 Annotation (java.lang.annotation.Annotation)1 HandlerChain (javax.jws.HandlerChain)1 SOAPBinding (javax.jws.soap.SOAPBinding)1 XmlAttachmentRef (javax.xml.bind.annotation.XmlAttachmentRef)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlList (javax.xml.bind.annotation.XmlList)1 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)1 XmlType (javax.xml.bind.annotation.XmlType)1 QName (javax.xml.namespace.QName)1 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)1