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