Search in sources :

Example 16 with JavaModel

use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.

the class PortTypeProcessor method process.

public void process(ServiceInfo serviceInfo) throws ToolException {
    operationMap.clear();
    JavaModel jmodel = context.get(JavaModel.class);
    InterfaceInfo interfaceInfo = serviceInfo.getInterface();
    if (interfaceInfo == null) {
        return;
    }
    JavaInterface intf = getInterface(context, serviceInfo, interfaceInfo);
    intf.setJavaModel(jmodel);
    Element handler = (Element) context.get(ToolConstants.HANDLER_CHAIN);
    intf.setHandlerChains(handler);
    Collection<OperationInfo> operations = interfaceInfo.getOperations();
    for (OperationInfo operation : operations) {
        if (isOverloading(operation.getName())) {
            LOG.log(Level.WARNING, "SKIP_OVERLOADED_OPERATION", operation.getName());
            continue;
        }
        OperationProcessor operationProcessor = new OperationProcessor(context);
        operationProcessor.process(intf, operation);
    }
    jmodel.setLocation(intf.getLocation());
    jmodel.addInterface(intf.getName(), intf);
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaModel(org.apache.cxf.tools.common.model.JavaModel) Element(org.w3c.dom.Element) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Example 17 with JavaModel

use of org.apache.cxf.tools.common.model.JavaModel 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();
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaException(org.apache.cxf.tools.common.model.JavaException) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) 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) JavaPort(org.apache.cxf.tools.common.model.JavaPort) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Test(org.junit.Test)

Example 18 with JavaModel

use of org.apache.cxf.tools.common.model.JavaModel 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 19 with JavaModel

use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.

the class AntGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    JavaModel javaModel = env.get(JavaModel.class);
    Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
    Map<String, String> serverClassNamesMap = new HashMap<>();
    Map<String, String> clientClassNamesMap = new HashMap<>();
    for (JavaInterface intf : interfaces.values()) {
        clientClassNamesMap.put(intf.getName() + "Client", intf.getFullClassName() + "Client");
        serverClassNamesMap.put(intf.getName() + "Server", intf.getFullClassName() + "Server");
    }
    clearAttributes();
    setAttributes("clientClassNamesMap", clientClassNamesMap);
    setAttributes("serverClassNamesMap", serverClassNamesMap);
    setAttributes("srcdir", penv.get(ToolConstants.CFG_SOURCEDIR));
    setAttributes("clsdir", penv.get(ToolConstants.CFG_CLASSDIR));
    setAttributes("classpath", penv.get(ToolConstants.CFG_CLASSPATH));
    setAttributes("classpath", penv.get(ToolConstants.CFG_CLASSPATH));
    setCommonAttributes();
    doWrite(BUILD_TEMPLATE, parseOutputName(null, "build", ".xml"));
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) HashMap(java.util.HashMap) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

Example 20 with JavaModel

use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.

the class JaxwsImplGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    JavaModel javaModel = env.get(JavaModel.class);
    if (passthrough()) {
        return;
    }
    Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
    QName service = (QName) env.get(ToolConstants.SERVICE_NAME);
    for (JavaInterface intf : interfaces.values()) {
        clearAttributes();
        setAttributes("intf", intf);
        setAttributes("service", service);
        setCommonAttributes();
        doWrite(IMPL_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName() + "Impl"));
        env.put(ToolConstants.IMPL_CLASS, intf.getFullClassName() + "Impl");
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

Aggregations

JavaModel (org.apache.cxf.tools.common.model.JavaModel)24 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)20 QName (javax.xml.namespace.QName)11 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)8 JavaPort (org.apache.cxf.tools.common.model.JavaPort)6 JavaServiceClass (org.apache.cxf.tools.common.model.JavaServiceClass)6 Message (org.apache.cxf.common.i18n.Message)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 JavaException (org.apache.cxf.tools.common.model.JavaException)3 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 ToolContext (org.apache.cxf.tools.common.ToolContext)2 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)2 JavaExceptionClass (org.apache.cxf.tools.common.model.JavaExceptionClass)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)2 AntGenerator (org.apache.cxf.tools.java2wsdl.processor.internal.AntGenerator)2 ClassCollector (org.apache.cxf.tools.util.ClassCollector)2 AbstractGenerator (org.apache.cxf.tools.wsdlto.core.AbstractGenerator)2