use of org.apache.cxf.tools.common.model.JavaMethod 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.JavaMethod 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.JavaMethod in project cxf by apache.
the class RequestWrapperTest method testNoAnnotationNoClass.
@Test
public void testNoAnnotationNoClass() throws Exception {
String pkgName = "org.apache.cxf.tools.fortest.classnoanno.docwrapped";
Class<?> testingClass = Class.forName(pkgName + ".Stock");
OperationInfo opInfo = getOperation(testingClass, "getPrice");
Wrapper wrapper = new RequestWrapper();
wrapper.setOperationInfo(opInfo);
assertTrue(wrapper.isWrapperAbsent());
assertTrue(wrapper.isToDifferentPackage());
assertFalse(wrapper.isWrapperBeanClassNotExist());
assertEquals(pkgName + ".jaxws", wrapper.getJavaClass().getPackageName());
assertEquals("GetPrice", wrapper.getJavaClass().getName());
JavaClass jClass = wrapper.buildWrapperBeanClass();
assertNotNull(jClass);
List<JavaField> jFields = jClass.getFields();
assertEquals(1, jFields.size());
assertEquals("arg0", jFields.get(0).getName());
assertEquals("java.lang.String", jFields.get(0).getClassName());
List<JavaMethod> jMethods = jClass.getMethods();
assertEquals(2, jMethods.size());
JavaMethod jMethod = jMethods.get(0);
assertEquals("getArg0", jMethod.getName());
assertTrue(jMethod.getParameterListWithoutAnnotation().isEmpty());
jMethod = jMethods.get(1);
assertEquals("setArg0", jMethod.getName());
assertEquals(1, jMethod.getParameterListWithoutAnnotation().size());
assertEquals("java.lang.String newArg0", jMethod.getParameterListWithoutAnnotation().get(0));
}
use of org.apache.cxf.tools.common.model.JavaMethod in project cxf by apache.
the class MethodMapper method map.
public JavaMethod map(OperationInfo operation) {
JavaMethod method = new JavaMethod();
// set default Document Bare style
method.setSoapStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
String operationName = operation.getName().getLocalPart();
method.setName(ProcessorUtil.mangleNameToVariableName(operationName));
method.setOperationName(operationName);
JAXWSBinding opBinding = operation.getExtensor(JAXWSBinding.class);
if (opBinding != null && opBinding.getMethodName() != null) {
method.setName(opBinding.getMethodName());
}
if (opBinding != null && opBinding.getMethodJavaDoc() != null) {
method.setJavaDoc(opBinding.getMethodJavaDoc());
} else {
method.setJavaDoc(operation.getDocumentation());
}
if (operation.isOneWay()) {
method.setStyle(OperationType.ONE_WAY);
} else {
method.setStyle(OperationType.REQUEST_RESPONSE);
}
method.setWrapperStyle(operation.isUnwrappedCapable());
return method;
}
use of org.apache.cxf.tools.common.model.JavaMethod in project cxf by apache.
the class ParameterProcessorTest method testAddParameter.
@Test
public void testAddParameter() throws Exception {
ParameterProcessor processor = new ParameterProcessor(new ToolContext());
JavaMethod method = new JavaMethod();
JavaParameter p1 = new JavaParameter("request", String.class.getName(), null);
p1.setStyle(JavaType.Style.IN);
processor.addParameter(null, method, p1);
JavaParameter p2 = new JavaParameter("request", String.class.getName(), null);
p2.setStyle(JavaType.Style.OUT);
processor.addParameter(null, method, p2);
assertEquals(1, method.getParameters().size());
assertEquals(JavaType.Style.INOUT, method.getParameters().get(0).getStyle());
}
Aggregations