use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.
the class WebServiceAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
JavaInterface intf = null;
if (ja instanceof JavaInterface) {
intf = (JavaInterface) ja;
} else {
throw new RuntimeException("WebService can only annotate JavaInterface");
}
JAnnotation serviceAnnotation = new JAnnotation(WebService.class);
serviceAnnotation.addElement(new JAnnotationElement("targetNamespace", intf.getNamespace()));
serviceAnnotation.addElement(new JAnnotationElement("name", intf.getWebServiceName()));
intf.addAnnotation(serviceAnnotation);
}
use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.
the class WrapperAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
JavaMethod method;
if (ja instanceof JavaMethod) {
method = (JavaMethod) ja;
} else {
throw new RuntimeException("RequestWrapper and ResponseWrapper can only annotate JavaMethod");
}
if (wrapperRequest != null) {
JAnnotation requestAnnotation = new JAnnotation(RequestWrapper.class);
requestAnnotation.addElement(new JAnnotationElement("localName", wrapperRequest.getType()));
requestAnnotation.addElement(new JAnnotationElement("targetNamespace", wrapperRequest.getTargetNamespace()));
requestAnnotation.addElement(new JAnnotationElement("className", wrapperRequest.getClassName()));
method.addAnnotation("RequestWrapper", requestAnnotation);
method.getInterface().addImports(requestAnnotation.getImports());
}
if (wrapperResponse != null) {
List<JAnnotationElement> elements = new ArrayList<>();
elements.add(new JAnnotationElement("localName", wrapperResponse.getType()));
elements.add(new JAnnotationElement("targetNamespace", wrapperResponse.getTargetNamespace()));
elements.add(new JAnnotationElement("className", wrapperResponse.getClassName()));
JAnnotation responseAnnotation = new JAnnotation(ResponseWrapper.class);
responseAnnotation.getElements().addAll(elements);
method.addAnnotation("ResponseWrapper", responseAnnotation);
method.getInterface().addImports(responseAnnotation.getImports());
}
}
use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.
the class XmlJavaTypeAdapterAnnotator method annotate.
public void annotate(JavaAnnotatable jn) {
JAnnotation jaxbAnnotation = new JAnnotation(XmlJavaTypeAdapter.class);
jaxbAnnotation.addElement(new JAnnotationElement("value", adapter));
if (jn instanceof JavaParameter) {
JavaParameter jp = (JavaParameter) jn;
jp.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
} else if (jn instanceof JavaMethod) {
JavaMethod jm = (JavaMethod) jn;
jm.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
} else {
throw new RuntimeException("Annotation of " + jn.getClass() + " not supported.");
}
jf.addImport(XmlJavaTypeAdapter.class.getName());
jf.addImport(adapter.getName());
}
use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.
the class WebParamAnnotatorTest method testAnnotateDOCWrapped.
@Test
public void testAnnotateDOCWrapped() throws Exception {
init(method, parameter, SOAPBinding.Style.DOCUMENT, true);
parameter.annotate(new WebParamAnnotator());
JAnnotation annotation = parameter.getAnnotation("WebParam");
assertEquals("@WebParam(name = \"x\", targetNamespace = \"http://apache.org/cxf\")", annotation.toString());
List<JAnnotationElement> elements = annotation.getElements();
assertEquals(2, elements.size());
assertEquals("http://apache.org/cxf", elements.get(1).getValue());
assertEquals("x", elements.get(0).getValue());
}
use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.
the class WrapperBeanAnnotator method annotate.
public void annotate(final JavaAnnotatable clz) {
WrapperBeanClass beanClass = null;
if (clz instanceof WrapperBeanClass) {
beanClass = (WrapperBeanClass) clz;
} else {
throw new RuntimeException("WrapperBeanAnnotator expect JavaClass as input");
}
JAnnotation xmlRootElement = new JAnnotation(XmlRootElement.class);
xmlRootElement.addElement(new JAnnotationElement("name", beanClass.getElementName().getLocalPart()));
xmlRootElement.addElement(new JAnnotationElement("namespace", beanClass.getElementName().getNamespaceURI()));
JAnnotation xmlAccessorType = new JAnnotation(XmlAccessorType.class);
xmlAccessorType.addElement(new JAnnotationElement(null, XmlAccessType.FIELD));
XmlType tp = null;
if (sourceClass != null) {
tp = sourceClass.getAnnotation(XmlType.class);
}
JAnnotation xmlType = new JAnnotation(XmlType.class);
if (tp == null) {
xmlType.addElement(new JAnnotationElement("name", beanClass.getElementName().getLocalPart()));
xmlType.addElement(new JAnnotationElement("namespace", beanClass.getElementName().getNamespaceURI()));
} else {
if (!"##default".equals(tp.name())) {
xmlType.addElement(new JAnnotationElement("name", tp.name()));
}
if (!"##default".equals(tp.namespace())) {
xmlType.addElement(new JAnnotationElement("namespace", tp.namespace()));
}
if (!StringUtils.isEmpty(tp.factoryMethod())) {
xmlType.addElement(new JAnnotationElement("factoryMethod", tp.factoryMethod()));
}
if (tp.propOrder().length != 1 || !StringUtils.isEmpty(tp.propOrder()[0])) {
xmlType.addElement(new JAnnotationElement("propOrder", tp.propOrder()));
}
}
List<String> props = new ArrayList<>();
for (JavaField f : beanClass.getFields()) {
props.add(f.getParaName());
}
if (props.size() > 1) {
xmlType.addElement(new JAnnotationElement("propOrder", props));
}
// Revisit: why annotation is string?
beanClass.addAnnotation(xmlRootElement);
beanClass.addAnnotation(xmlAccessorType);
beanClass.addAnnotation(xmlType);
}
Aggregations