use of org.apache.cxf.tools.common.model.JavaMethod in project cxf by apache.
the class OperationProcessor method addPollingMethod.
private void addPollingMethod(JavaMethod method) throws ToolException {
JavaMethod pollingMethod = new JavaMethod(method.getInterface());
pollingMethod.setAsync(true);
pollingMethod.setName(method.getName() + ToolConstants.ASYNC_METHOD_SUFFIX);
pollingMethod.setStyle(method.getStyle());
pollingMethod.setWrapperStyle(method.isWrapperStyle());
pollingMethod.setSoapAction(method.getSoapAction());
pollingMethod.setOperationName(method.getOperationName());
boolean convertOutToAsync = !method.isWrapperStyle() && "void".equals(method.getReturn().getClassName());
String asyncCname = null;
for (JavaParameter param : method.getParameters()) {
if (convertOutToAsync) {
if (param.isHolder()) {
if (param.isINOUT()) {
JavaParameter p2 = new JavaParameter();
p2.setName(param.getName());
p2.setClassName(param.getHolderName());
p2.setStyle(JavaType.Style.IN);
pollingMethod.addParameter(p2);
for (String s : param.getAnnotationTags()) {
JAnnotation ann = param.getAnnotation(s);
p2.addAnnotation(s, ann);
}
} else if (!param.isHeader() && asyncCname == null) {
asyncCname = param.getClassName();
}
} else {
pollingMethod.addParameter(param);
}
} else {
pollingMethod.addParameter(param);
}
}
JavaReturn response = new JavaReturn();
response.setClassName(getAsyncClassName(method, "Response", asyncCname));
pollingMethod.setReturn(response);
// REVISIT: test the operation name in the annotation
pollingMethod.annotate(new WebMethodAnnotator());
pollingMethod.addAnnotation("RequestWrapper", method.getAnnotationMap().get("RequestWrapper"));
pollingMethod.addAnnotation("ResponseWrapper", method.getAnnotationMap().get("ResponseWrapper"));
pollingMethod.addAnnotation("SOAPBinding", method.getAnnotationMap().get("SOAPBinding"));
method.getInterface().addMethod(pollingMethod);
}
use of org.apache.cxf.tools.common.model.JavaMethod 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.JavaMethod in project cxf by apache.
the class BindingAnnotator method processBinding.
private boolean processBinding(JavaInterface intf) {
SOAPBinding.Style soapStyle = intf.getSOAPStyle();
SOAPBinding.Use soapUse = intf.getSOAPUse();
boolean allWrapped = true;
boolean allBare = true;
boolean allRPC = true;
boolean allDOC = true;
for (JavaMethod method : intf.getMethods()) {
if (!method.isWrapperStyle()) {
allWrapped = false;
} else {
allBare = false;
}
SOAPBinding.Style mStyle = method.getSoapStyle();
if (mStyle == null) {
mStyle = soapStyle;
}
if (mStyle == null) {
mStyle = SOAPBinding.Style.DOCUMENT;
}
if (soapStyle == null && method.getSoapStyle() != null) {
soapStyle = method.getSoapStyle();
}
if (SOAPBinding.Style.DOCUMENT.equals(mStyle)) {
allRPC = false;
} else {
allDOC = false;
}
if (soapUse == null && method.getSoapUse() != null) {
soapUse = method.getSoapUse();
}
}
if (allDOC) {
soapStyle = SOAPBinding.Style.DOCUMENT;
} else if (allRPC) {
soapStyle = SOAPBinding.Style.RPC;
}
if (soapStyle == SOAPBinding.Style.DOCUMENT) {
intf.setSOAPStyle(SOAPBinding.Style.DOCUMENT);
if (allWrapped) {
intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.WRAPPED);
} else if (allBare) {
intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.BARE);
}
} else if (soapStyle == null) {
intf.setSOAPStyle(SOAPBinding.Style.DOCUMENT);
if (allWrapped) {
intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.WRAPPED);
} else if (allBare) {
intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.BARE);
}
} else {
intf.setSOAPStyle(SOAPBinding.Style.RPC);
}
if (intf.getSOAPParameterStyle() == null) {
intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.WRAPPED);
}
if (soapUse == SOAPBinding.Use.LITERAL) {
intf.setSOAPUse(SOAPBinding.Use.LITERAL);
} else if (soapUse == null) {
intf.setSOAPUse(SOAPBinding.Use.LITERAL);
} else {
intf.setSOAPUse(SOAPBinding.Use.ENCODED);
}
return !(intf.getSOAPStyle() == SOAPBinding.Style.DOCUMENT && intf.getSOAPUse() == SOAPBinding.Use.LITERAL && intf.getSOAPParameterStyle() == SOAPBinding.ParameterStyle.WRAPPED);
}
use of org.apache.cxf.tools.common.model.JavaMethod 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.JavaMethod 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