use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.
the class WrapperBeanFieldAnnotator method annotate.
public void annotate(final JavaAnnotatable field) {
JavaField jField = null;
if (field instanceof JavaField) {
jField = (JavaField) field;
} else {
throw new RuntimeException("WrapperBeanFiledAnnotator expect JavaField as input");
}
String rawName = jField.getRawName();
boolean hasEl = false;
for (Annotation ann : jField.getJaxbAnnotaions()) {
if (ann instanceof XmlMimeType) {
JAnnotation mimeAnno = new JAnnotation(XmlMimeType.class);
mimeAnno.addElement(new JAnnotationElement("value", ((XmlMimeType) ann).value()));
jField.addAnnotation(mimeAnno);
} else if (ann instanceof XmlJavaTypeAdapter) {
JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
jaxbAnn.addElement(new JAnnotationElement("value", ((XmlJavaTypeAdapter) ann).value()));
jaxbAnn.addElement(new JAnnotationElement("type", ((XmlJavaTypeAdapter) ann).type()));
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlAttachmentRef) {
JAnnotation jaxbAnn = new JAnnotation(XmlAttachmentRef.class);
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlList) {
JAnnotation jaxbAnn = new JAnnotation(XmlList.class);
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlElement) {
hasEl = true;
XmlElement el = (XmlElement) ann;
JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
xmlElementAnnotation.addElement(new JAnnotationElement("name", el.name()));
if (!StringUtils.isEmpty(el.namespace())) {
xmlElementAnnotation.addElement(new JAnnotationElement("namespace", el.namespace()));
}
if (el.nillable()) {
xmlElementAnnotation.addElement(new JAnnotationElement("nillable", el.nillable(), true));
}
if (el.required()) {
xmlElementAnnotation.addElement(new JAnnotationElement("required", el.required(), true));
}
if (!StringUtils.isEmpty(el.defaultValue())) {
xmlElementAnnotation.addElement(new JAnnotationElement("defaultValue", el.defaultValue()));
}
jField.addAnnotation(xmlElementAnnotation);
}
}
if (!hasEl) {
JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
xmlElementAnnotation.addElement(new JAnnotationElement("name", rawName));
if (!StringUtils.isEmpty(jField.getTargetNamespace())) {
xmlElementAnnotation.addElement(new JAnnotationElement("namespace", jField.getTargetNamespace()));
}
jField.addAnnotation(xmlElementAnnotation);
}
}
use of org.apache.cxf.tools.common.model.JAnnotationElement 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.JAnnotationElement 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.JAnnotationElement in project cxf by apache.
the class WebMethodAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
JavaMethod method = null;
if (ja instanceof JavaMethod) {
method = (JavaMethod) ja;
} else {
throw new RuntimeException("WebMethod can only annotate JavaMethod");
}
String operationName = method.getOperationName();
JAnnotation methodAnnotation = new JAnnotation(WebMethod.class);
if (!method.getName().equals(operationName)) {
methodAnnotation.addElement(new JAnnotationElement("operationName", operationName));
}
if (!StringUtils.isEmpty(method.getSoapAction())) {
methodAnnotation.addElement(new JAnnotationElement("action", method.getSoapAction()));
}
method.addAnnotation("WebMethod", methodAnnotation);
}
use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.
the class WebParamAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
JavaParameter parameter = null;
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);
}
Aggregations