Search in sources :

Example 11 with JAnnotation

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

the class SoapBindingAnnotator method annotate.

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);
    }
}
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) SOAPBinding(javax.jws.soap.SOAPBinding)

Example 12 with JAnnotation

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

the class WebResultAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    final JavaMethod method;
    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 13 with JAnnotation

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

the class WebMethodAnnotatorTest method testAddWebMethodAnnotation.

@Test
public void testAddWebMethodAnnotation() throws Exception {
    JavaMethod method = new JavaMethod();
    method.setName("echoFoo");
    method.setOperationName("echoFoo");
    method.annotate(new WebMethodAnnotator());
    Map<String, JAnnotation> annotations = method.getAnnotationMap();
    assertNotNull(annotations);
    assertEquals(1, annotations.size());
    assertEquals("WebMethod", annotations.keySet().iterator().next());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Test(org.junit.Test)

Example 14 with JAnnotation

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

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

the class WrapperBeanFieldAnnotatorTest method testAnnotate.

@Test
public void testAnnotate() {
    JavaClass clz = new JavaClass();
    clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHi");
    JavaField reqField = new JavaField("array", "String[]", "http://doc.withannotation.fortest.tools.cxf.apache.org/");
    reqField.setOwner(clz);
    List<JAnnotation> annotation = reqField.getAnnotations();
    assertEquals(0, annotation.size());
    reqField.annotate(new WrapperBeanFieldAnnotator());
    annotation = reqField.getAnnotations();
    String expectedNamespace = "http://doc.withannotation.fortest.tools.cxf.apache.org/";
    assertEquals("@XmlElement(name = \"array\", namespace = \"" + expectedNamespace + "\")", annotation.get(0).toString());
    clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHiResponse");
    JavaField resField = new JavaField("return", "String[]", "http://doc.withannotation.fortest.tools.cxf.apache.org/");
    resField.setOwner(clz);
    resField.annotate(new WrapperBeanFieldAnnotator());
    annotation = resField.getAnnotations();
    assertEquals("@XmlElement(name = \"return\", namespace = \"" + expectedNamespace + "\")", annotation.get(0).toString());
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) JavaClass(org.apache.cxf.tools.common.model.JavaClass) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) Test(org.junit.Test)

Aggregations

JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)27 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)20 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)14 Test (org.junit.Test)7 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)6 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)5 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)3 Message (org.apache.cxf.common.i18n.Message)3 JavaField (org.apache.cxf.tools.common.model.JavaField)3 XmlList (javax.xml.bind.annotation.XmlList)2 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)2 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)2 JavaModel (org.apache.cxf.tools.common.model.JavaModel)2 JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)2 WrapperBeanClass (org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass)2 WebMethodAnnotator (org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator)2 Annotation (java.lang.annotation.Annotation)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1