use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class WrapperBeanAnnotator method annotate.
public void annotate(final JavaAnnotatable clz) {
final WrapperBeanClass beanClass;
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);
}
use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class ServiceProcessor method setParameterAsHeader.
private void setParameterAsHeader(JavaParameter parameter) {
parameter.setHeader(true);
JAnnotation parameterAnnotation = parameter.getAnnotation("WebParam");
parameterAnnotation.addElement(new JAnnotationElement("header", true, true));
parameterAnnotation.addElement(new JAnnotationElement("name", parameter.getQName().getLocalPart()));
parameterAnnotation.addElement(new JAnnotationElement("partName", parameter.getPartName()));
parameterAnnotation.addElement(new JAnnotationElement("targetNamespace", parameter.getTargetNamespace()));
}
use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class BindingAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
JavaInterface intf;
if (ja instanceof JavaInterface) {
intf = (JavaInterface) ja;
} else {
throw new RuntimeException("BindingAnnotator can only annotate JavaInterface");
}
if (processBinding(intf)) {
JAnnotation bindingAnnotation = new JAnnotation(SOAPBinding.class);
if (!SOAPBinding.Style.DOCUMENT.equals(intf.getSOAPStyle())) {
bindingAnnotation.addElement(new JAnnotationElement("style", intf.getSOAPStyle()));
}
if (!SOAPBinding.Use.LITERAL.equals(intf.getSOAPUse())) {
bindingAnnotation.addElement(new JAnnotationElement("use", intf.getSOAPUse()));
}
if (intf.getSOAPStyle() == SOAPBinding.Style.DOCUMENT && intf.getSOAPParameterStyle() != SOAPBinding.ParameterStyle.WRAPPED) {
bindingAnnotation.addElement(new JAnnotationElement("parameterStyle", intf.getSOAPParameterStyle()));
}
intf.addAnnotation(bindingAnnotation);
}
for (JavaMethod method : intf.getMethods()) {
if (!method.isAsync()) {
method.annotate(new SoapBindingAnnotator());
}
}
}
use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class WebParamAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
final JavaParameter parameter;
if (ja instanceof JavaParameter) {
parameter = (JavaParameter) ja;
} else {
throw new RuntimeException("WebParamAnnotator only annotate the JavaParameter");
}
JavaMethod method = parameter.getMethod();
if (method.hasParameter(parameter.getName())) {
JavaParameter paramInList = method.getParameter(parameter.getName());
if (paramInList.isIN() && parameter.isOUT()) {
parameter.setStyle(JavaType.Style.INOUT);
}
}
JAnnotation webParamAnnotation = new JAnnotation(WebParam.class);
String name = parameter.getName();
String targetNamespace = method.getInterface().getNamespace();
String partName = null;
if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT || parameter.isHeader()) {
targetNamespace = parameter.getTargetNamespace();
if (parameter.getQName() != null) {
name = parameter.getQName().getLocalPart();
}
if (!method.isWrapperStyle()) {
partName = parameter.getPartName();
}
}
if (method.getSoapStyle() == SOAPBinding.Style.RPC) {
name = parameter.getPartName();
partName = parameter.getPartName();
}
if (partName != null) {
webParamAnnotation.addElement(new JAnnotationElement("partName", partName));
}
if (parameter.getStyle() == JavaType.Style.OUT) {
webParamAnnotation.addElement(new JAnnotationElement("mode", WebParam.Mode.OUT));
} else if (parameter.getStyle() == JavaType.Style.INOUT) {
webParamAnnotation.addElement(new JAnnotationElement("mode", WebParam.Mode.INOUT));
}
webParamAnnotation.addElement(new JAnnotationElement("name", name));
if (null != targetNamespace && (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT || parameter.isHeader())) {
webParamAnnotation.addElement(new JAnnotationElement("targetNamespace", targetNamespace));
}
for (String importClz : webParamAnnotation.getImports()) {
parameter.getMethod().getInterface().addImport(importClz);
}
if (forceHeader) {
webParamAnnotation.addElement(new JAnnotationElement("header", true, true));
}
parameter.addAnnotation("WebParam", webParamAnnotation);
}
use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class WebServiceAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
final JavaInterface intf;
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);
}
Aggregations