Search in sources :

Example 26 with JavaMethod

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();
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JAXWSContainer(org.apache.cxf.tools.wsdlto.frontend.jaxws.JAXWSContainer) ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) JavaException(org.apache.cxf.tools.common.model.JavaException) FrontEndProfile(org.apache.cxf.tools.wsdlto.core.FrontEndProfile) JavaModel(org.apache.cxf.tools.common.model.JavaModel) FrontEndGenerator(org.apache.cxf.tools.common.FrontEndGenerator) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) File(java.io.File) Test(org.junit.Test)

Example 27 with JavaMethod

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;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) JavaException(org.apache.cxf.tools.common.model.JavaException) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Method(java.lang.reflect.Method)

Example 28 with JavaMethod

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;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) JavaException(org.apache.cxf.tools.common.model.JavaException) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Method(java.lang.reflect.Method) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Aggregations

JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)28 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)14 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)11 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)9 Test (org.junit.Test)9 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)7 OperationInfo (org.apache.cxf.service.model.OperationInfo)6 JavaException (org.apache.cxf.tools.common.model.JavaException)5 JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)4 ArrayList (java.util.ArrayList)3 ToolContext (org.apache.cxf.tools.common.ToolContext)3 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 URISyntaxException (java.net.URISyntaxException)2 SOAPBinding (javax.jws.soap.SOAPBinding)2 QName (javax.xml.namespace.QName)2 FaultInfo (org.apache.cxf.service.model.FaultInfo)2 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)2