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);
}
}
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");
}
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());
}
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());
}
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());
}
Aggregations