use of org.apache.cxf.tools.common.model.JavaMethod in project cxf by apache.
the class JAXWSContainerTest method testCodeGen.
@Test
public void testCodeGen() {
try {
JAXWSContainer container = new JAXWSContainer(null);
ToolContext context = new ToolContext();
// By default we only generate the SEI/Types/Exception classes/Service Class(client stub)
// Uncomment to generate the impl class
// context.put(ToolConstants.CFG_IMPL, "impl");
// Uncomment to compile the generated classes
// context.put(ToolConstants.CFG_COMPILE, ToolConstants.CFG_COMPILE);
// Where to put the compiled classes
// context.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes");
// 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"));
// In case you want to remove some generators
List<String> generatorNames = Arrays.asList(new String[] { ToolConstants.CLT_GENERATOR, ToolConstants.SVR_GENERATOR, ToolConstants.IMPL_GENERATOR, ToolConstants.ANT_GENERATOR, ToolConstants.SERVICE_GENERATOR, ToolConstants.FAULT_GENERATOR, ToolConstants.SEI_GENERATOR });
FrontEndProfile frontend = context.get(FrontEndProfile.class);
List<FrontEndGenerator> generators = frontend.getGenerators();
for (FrontEndGenerator generator : generators) {
assertTrue(generatorNames.contains(generator.getName()));
}
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(1, output.list().length);
assertTrue(new File(output, "org/apache/cxf/w2j/hello_world_soap_http/Greeter.java").exists());
assertTrue(new File(output, "org/apache/cxf/w2j/hello_world_soap_http/SOAPService.java").exists());
assertTrue(new File(output, "org/apache/cxf/w2j/hello_world_soap_http/NoSuchCodeLitFault.java").exists());
assertTrue(new File(output, "org/apache/cxf/w2j/hello_world_soap_http/types/SayHi.java").exists());
assertTrue(new File(output, "org/apache/cxf/w2j/hello_world_soap_http/types/GreetMe.java").exists());
// Now you can get the JavaModel from the context.
JavaModel javaModel = context.get(JavaModel.class);
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
assertEquals(1, interfaces.size());
JavaInterface intf = interfaces.values().iterator().next();
assertEquals("http://cxf.apache.org/w2j/hello_world_soap_http", intf.getNamespace());
assertEquals("Greeter", intf.getName());
assertEquals("org.apache.cxf.w2j.hello_world_soap_http", intf.getPackageName());
List<JavaMethod> methods = intf.getMethods();
assertEquals(6, methods.size());
Boolean methodSame = false;
for (JavaMethod m1 : methods) {
if (m1.getName().equals("testDocLitFault")) {
methodSame = true;
break;
}
}
assertTrue(methodSame);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.cxf.tools.common.model.JavaMethod in project cxf by apache.
the class JavaFirstUtil method serviceInfo2JavaInf.
public static JavaInterface serviceInfo2JavaInf(ServiceInfo service) {
JavaInterface javaInf = new JavaInterface();
InterfaceInfo inf = service.getInterface();
for (OperationInfo op : inf.getOperations()) {
JavaMethod jm = new JavaMethod();
Method m = (Method) op.getProperty(ReflectionServiceFactoryBean.METHOD);
jm.setName(m.getName());
int i = 0;
for (Type type : m.getGenericParameterTypes()) {
JavaParameter jp = new JavaParameter();
jp.setClassName(getClassName(type));
jp.setStyle(Style.IN);
jp.setName("arg" + i++);
jm.addParameter(jp);
}
for (Type type : m.getGenericExceptionTypes()) {
JavaException jex = new JavaException();
String className = getClassName(type);
jex.setClassName(className);
jex.setName(className);
jm.addException(jex);
}
JavaReturn jreturn = new JavaReturn();
jreturn.setClassName(getClassName(m.getGenericReturnType()));
jreturn.setStyle(Style.OUT);
jm.setReturn(jreturn);
String pkg = PackageUtils.getPackageName(m.getDeclaringClass());
javaInf.setPackageName(pkg.length() == 0 ? ToolConstants.DEFAULT_PACKAGE_NAME : pkg);
javaInf.addMethod(jm);
javaInf.setName(inf.getName().getLocalPart());
jm.getParameterList();
}
return javaInf;
}
use of org.apache.cxf.tools.common.model.JavaMethod in project cxf by apache.
the class JAXWSFrontEndProcessor method serviceInfo2JavaInf.
public JavaInterface serviceInfo2JavaInf(ServiceInfo service) {
JavaInterface javaInf = new JavaInterface();
InterfaceInfo inf = service.getInterface();
for (OperationInfo op : inf.getOperations()) {
JavaMethod jm = new JavaMethod();
Method m = (Method) op.getProperty(ReflectionServiceFactoryBean.METHOD);
jm.setName(m.getName());
int i = 0;
for (Type type : m.getGenericParameterTypes()) {
JavaParameter jp = new JavaParameter();
jp.setClassName(getClassName(type));
jp.setStyle(Style.IN);
jp.setName("arg" + i++);
jm.addParameter(jp);
}
for (Type type : m.getGenericExceptionTypes()) {
JavaException jex = new JavaException();
String className = getClassName(type);
jex.setClassName(className);
jex.setName(className);
jm.addException(jex);
}
JavaReturn jreturn = new JavaReturn();
jreturn.setClassName(getClassName(m.getGenericReturnType()));
jreturn.setStyle(Style.OUT);
jm.setReturn(jreturn);
String pkg = PackageUtils.getPackageName(m.getDeclaringClass());
javaInf.setPackageName(pkg.length() > 0 ? pkg : ToolConstants.DEFAULT_PACKAGE_NAME);
javaInf.addMethod(jm);
javaInf.setName(inf.getName().getLocalPart());
jm.getParameterList();
}
return javaInf;
}
Aggregations