use of org.apache.cxf.tools.common.model.JavaMethod 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.JavaMethod 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.JavaMethod in project cxf by apache.
the class XmlListAnotator method annotate.
public void annotate(JavaAnnotatable jn) {
JAnnotation jaxbAnnotation = new JAnnotation(XmlList.class);
if (jn instanceof JavaParameter) {
JavaParameter jp = (JavaParameter) jn;
jp.addAnnotation("XmlList", jaxbAnnotation);
} else if (jn instanceof JavaMethod) {
JavaMethod jm = (JavaMethod) jn;
jm.addAnnotation("XmlList", jaxbAnnotation);
} else {
throw new RuntimeException("XmlList can only annotate to JavaParameter or JavaMethod");
}
jf.addImport(XmlList.class.getName());
}
use of org.apache.cxf.tools.common.model.JavaMethod in project cxf by apache.
the class MethodMapperTest method testMapWrappedOperation.
@Test
public void testMapWrappedOperation() throws Exception {
OperationInfo operation = getOperation();
operation.setUnwrappedOperation(operation);
JavaMethod method = new MethodMapper().map(operation);
assertNotNull(method);
assertTrue(method.isWrapperStyle());
}
use of org.apache.cxf.tools.common.model.JavaMethod in project cxf by apache.
the class JAXWSContainerTest method testSuppressCodeGen.
@Test
public void testSuppressCodeGen() {
try {
JAXWSContainer container = new JAXWSContainer(null);
ToolContext context = new ToolContext();
// Do not generate any artifacts, we just want the code model.
context.put(ToolConstants.CFG_SUPPRESS_GEN, "suppress");
// Where to put the generated source code
context.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
// Delegate jaxb to generate the type classes
context.put(DataBindingProfile.class, PluginLoader.getInstance().getDataBindingProfile("jaxb"));
context.put(FrontEndProfile.class, PluginLoader.getInstance().getFrontEndProfile("jaxws"));
container.setContext(context);
// Now shoot
container.execute();
// At this point you should be able to get the
// SEI/Service(Client stub)/Exception classes/Types classes
assertNotNull(output.list());
assertEquals(0, output.list().length);
// Now you can get the JavaModel from the context.
Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) context.get(WSDLToJavaProcessor.MODEL_MAP));
JavaModel javaModel = map.get(new QName("http://cxf.apache.org/w2j/hello_world_soap_http", "SOAPService"));
assertNotNull(javaModel);
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
assertEquals(1, interfaces.size());
JavaInterface intf = interfaces.values().iterator().next();
String interfaceName = intf.getName();
assertEquals("Greeter", interfaceName);
assertEquals("http://cxf.apache.org/w2j/hello_world_soap_http", intf.getNamespace());
assertEquals("org.apache.cxf.w2j.hello_world_soap_http", intf.getPackageName());
List<JavaMethod> methods = intf.getMethods();
assertEquals(6, methods.size());
Boolean methodSame = false;
JavaMethod m1 = null;
for (JavaMethod m2 : methods) {
if (m2.getName().equals("testDocLitFault")) {
methodSame = true;
m1 = m2;
break;
}
}
assertTrue(methodSame);
assertNotNull(m1);
assertEquals(2, m1.getExceptions().size());
List<String> names = new ArrayList<>();
for (JavaException exc : m1.getExceptions()) {
names.add(exc.getName());
}
assertTrue("BadRecordLitFault", names.contains("BadRecordLitFault"));
assertTrue("NoSuchCodeLitFault", names.contains("NoSuchCodeLitFault"));
String address = null;
for (JavaServiceClass service : javaModel.getServiceClasses().values()) {
if ("SOAPService_Test1".equals(service.getName())) {
continue;
}
List<JavaPort> ports = service.getPorts();
for (JavaPort port : ports) {
if (interfaceName.equals(port.getPortType())) {
address = port.getBindingAdress();
break;
}
}
if (!"".equals(address)) {
break;
}
}
assertEquals("http://localhost:9000/SoapContext/SoapPort", address);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations