Search in sources :

Example 1 with FrontEndGenerator

use of org.apache.cxf.tools.common.FrontEndGenerator in project cxf by apache.

the class PluginLoader method getFrontEndProfile.

public FrontEndProfile getFrontEndProfile(String name) {
    FrontEnd frontend = getFrontEnd(name);
    FrontEndProfile profile = loadFrontEndProfile(getFrontEndProfileClass(frontend));
    for (FrontEndGenerator generator : getFrontEndGenerators(frontend)) {
        profile.registerGenerator(generator);
    }
    if (frontend.getProcessor() != null) {
        profile.setProcessor(loadProcessor(getProcessorClass(frontend)));
    }
    if (frontend.getContainer() != null) {
        profile.setContainerClass(loadContainerClass(getContainerClass(frontend)));
        profile.setToolspec(getToolspec(frontend));
    }
    if (frontend.getBuilder() != null) {
        profile.setWSDLBuilder(loadBuilder(getBuilderClass(frontend)));
    }
    return profile;
}
Also used : FrontEnd(org.apache.cxf.tools.plugin.FrontEnd) FrontEndGenerator(org.apache.cxf.tools.common.FrontEndGenerator)

Example 2 with FrontEndGenerator

use of org.apache.cxf.tools.common.FrontEndGenerator in project cxf by apache.

the class JAXWSProfileTest method testLoadPlugins.

@Test
public void testLoadPlugins() {
    PluginLoader loader = PluginLoader.getInstance();
    assertNotNull(loader);
    loader.loadPlugin("/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-plugin.xml");
    assertEquals(3, loader.getPlugins().size());
    Plugin plugin = null;
    for (Plugin p : loader.getPlugins().values()) {
        if (p.getName().contains("jaxws")) {
            plugin = p;
        }
    }
    assertNotNull(plugin);
    assertEquals("tools-jaxws-frontend", plugin.getName());
    assertEquals("2.0", plugin.getVersion());
    assertEquals("apache cxf", plugin.getProvider());
    Map<String, FrontEnd> frontends = loader.getFrontEnds();
    assertNotNull(frontends);
    assertEquals(3, frontends.size());
    FrontEnd frontend = getFrontEnd(frontends, 0);
    assertEquals("jaxws", frontend.getName());
    assertEquals("org.apache.cxf.tools.wsdlto.frontend.jaxws", frontend.getPackage());
    assertEquals("JAXWSProfile", frontend.getProfile());
    assertNotNull(frontend.getGenerators());
    assertNotNull(frontend.getGenerators().getGenerator());
    assertEquals(2, frontend.getGenerators().getGenerator().size());
    assertEquals("AntGenerator", getGenerator(frontend, 0).getName());
    assertEquals("ImplGenerator", getGenerator(frontend, 1).getName());
    FrontEndProfile profile = loader.getFrontEndProfile("jaxws");
    assertNotNull(profile);
    List<FrontEndGenerator> generators = profile.getGenerators();
    assertNotNull(generators);
    assertEquals(2, generators.size());
    assertTrue(generators.get(0) instanceof AntGenerator);
    assertTrue(generators.get(1) instanceof ImplGenerator);
    Processor processor = profile.getProcessor();
    assertNotNull(processor);
    assertTrue(processor instanceof WSDLToJavaProcessor);
    AbstractWSDLBuilder builder = profile.getWSDLBuilder();
    assertNotNull(builder);
    assertTrue(builder instanceof JAXWSDefinitionBuilder);
    Class<?> container = profile.getContainerClass();
    assertEquals(container, JAXWSContainer.class);
    assertEquals("/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml", profile.getToolspec());
}
Also used : AbstractWSDLBuilder(org.apache.cxf.tools.wsdlto.core.AbstractWSDLBuilder) Processor(org.apache.cxf.tools.common.Processor) WSDLToJavaProcessor(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.WSDLToJavaProcessor) ImplGenerator(org.apache.cxf.tools.wsdlto.frontend.jaxws.generators.ImplGenerator) FrontEndProfile(org.apache.cxf.tools.wsdlto.core.FrontEndProfile) FrontEnd(org.apache.cxf.tools.plugin.FrontEnd) FrontEndGenerator(org.apache.cxf.tools.common.FrontEndGenerator) WSDLToJavaProcessor(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.WSDLToJavaProcessor) PluginLoader(org.apache.cxf.tools.wsdlto.core.PluginLoader) JAXWSDefinitionBuilder(org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder) Plugin(org.apache.cxf.tools.plugin.Plugin) AntGenerator(org.apache.cxf.tools.wsdlto.frontend.jaxws.generators.AntGenerator) Test(org.junit.Test)

Example 3 with FrontEndGenerator

use of org.apache.cxf.tools.common.FrontEndGenerator 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 ("testDocLitFault".equals(m1.getName())) {
                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 4 with FrontEndGenerator

use of org.apache.cxf.tools.common.FrontEndGenerator in project cxf by apache.

the class WSDLToJavaContainer method processWsdl.

private void processWsdl() {
    validate(context);
    FrontEndProfile frontend = context.get(FrontEndProfile.class);
    if (frontend == null) {
        throw new ToolException(new Message("FOUND_NO_FRONTEND", LOG));
    }
    WSDLConstants.WSDLVersion version = getWSDLVersion();
    String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
    @SuppressWarnings("unchecked") List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
    if (serviceList == null) {
        serviceList = new ArrayList<>();
        // Build the ServiceModel from the WSDLModel
        if (version == WSDLConstants.WSDLVersion.WSDL11) {
            AbstractWSDLBuilder builder = frontend.getWSDLBuilder();
            builder.setContext(context);
            builder.setBus(getBus());
            context.put(Bus.class, getBus());
            wsdlURL = URIParserUtil.getAbsoluteURI(wsdlURL);
            builder.build(wsdlURL);
            builder.customize();
            Definition definition = builder.getWSDLModel();
            context.put(Definition.class, definition);
            builder.validate(definition);
            WSDLServiceBuilder serviceBuilder = new WSDLServiceBuilder(getBus());
            if (context.isVerbose()) {
                serviceBuilder.setUnwrapLogLevel(Level.INFO);
            }
            serviceBuilder.setIgnoreUnknownBindings(true);
            String allowRefs = (String) context.get(ToolConstants.CFG_ALLOW_ELEMENT_REFS);
            if (!StringUtils.isEmpty(allowRefs) || context.optionSet(ToolConstants.CFG_ALLOW_ELEMENT_REFS)) {
                if (allowRefs.length() > 0 && allowRefs.charAt(0) == '=') {
                    allowRefs = allowRefs.substring(1);
                }
                if (StringUtils.isEmpty(allowRefs)) {
                    allowRefs = "true";
                }
                serviceBuilder.setAllowElementRefs(Boolean.valueOf(allowRefs));
            }
            String serviceName = (String) context.get(ToolConstants.CFG_SERVICENAME);
            if (serviceName != null) {
                List<ServiceInfo> services = serviceBuilder.buildServices(definition, getServiceQName(definition));
                serviceList.addAll(services);
            } else if (definition.getServices().size() > 0) {
                serviceList = serviceBuilder.buildServices(definition);
            } else {
                serviceList = serviceBuilder.buildMockServices(definition);
            }
            // remove definition from cache so that won't fail when encounter same wsdl file
            // name but different wsdl content(CXF-3340)
            getBus().getExtension(WSDLManager.class).removeDefinition(definition);
        } else {
        // TODO: wsdl2.0 support
        }
    }
    context.put(ToolConstants.SERVICE_LIST, serviceList);
    Map<String, InterfaceInfo> interfaces = new LinkedHashMap<>();
    ServiceInfo service0 = serviceList.get(0);
    SchemaCollection schemaCollection = service0.getXmlSchemaCollection();
    context.put(ToolConstants.XML_SCHEMA_COLLECTION, schemaCollection);
    context.put(ToolConstants.PORTTYPE_MAP, interfaces);
    context.put(ClassCollector.class, createClassCollector());
    Processor processor = frontend.getProcessor();
    if (processor instanceof ClassNameProcessor) {
        processor.setEnvironment(context);
        for (ServiceInfo service : serviceList) {
            context.put(ServiceInfo.class, service);
            ((ClassNameProcessor) processor).processClassNames();
            context.put(ServiceInfo.class, null);
        }
    }
    if (context.optionSet(ToolConstants.CFG_NO_TYPES)) {
        context.remove(ToolConstants.CFG_TYPES);
        context.remove(ToolConstants.CFG_ALL);
        context.remove(ToolConstants.CFG_COMPILE);
    }
    generateTypes();
    if (context.getErrorListener().getErrorCount() > 0) {
        return;
    }
    for (ServiceInfo service : serviceList) {
        context.put(ServiceInfo.class, service);
        if (context.basicValidateWSDL()) {
            validate(service);
        }
        if (context.getErrorListener().getErrorCount() == 0) {
            // Build the JavaModel from the ServiceModel
            processor.setEnvironment(context);
            processor.process();
        }
    }
    if (context.getErrorListener().getErrorCount() > 0) {
        return;
    }
    if (context.optionSet(ToolConstants.CFG_CLIENT_JAR)) {
        enforceWSDLLocation(context);
    }
    if (!isSuppressCodeGen()) {
        // Generate artifacts
        for (FrontEndGenerator generator : frontend.getGenerators()) {
            generator.generate(context);
        }
    }
    context.remove(ToolConstants.SERVICE_LIST);
    // Build projects: compile classes and copy resources etc.
    if (context.optionSet(ToolConstants.CFG_COMPILE)) {
        new ClassUtils().compile(context);
    }
    if (context.isExcludeNamespaceEnabled()) {
        try {
            removeExcludeFiles();
        } catch (IOException e) {
            throw new ToolException(e);
        }
    }
    if (context.optionSet(ToolConstants.CFG_CLIENT_JAR)) {
        processClientJar(context);
    }
}
Also used : AbstractWSDLBuilder(org.apache.cxf.tools.wsdlto.core.AbstractWSDLBuilder) ClassNameProcessor(org.apache.cxf.tools.common.ClassNameProcessor) Processor(org.apache.cxf.tools.common.Processor) Message(org.apache.cxf.common.i18n.Message) Definition(javax.wsdl.Definition) IOException(java.io.IOException) ClassUtils(org.apache.cxf.tools.common.ClassUtils) FrontEndProfile(org.apache.cxf.tools.wsdlto.core.FrontEndProfile) LinkedHashMap(java.util.LinkedHashMap) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) WSDLConstants(org.apache.cxf.wsdl.WSDLConstants) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) FrontEndGenerator(org.apache.cxf.tools.common.FrontEndGenerator) WSDLManager(org.apache.cxf.wsdl.WSDLManager) ClassNameProcessor(org.apache.cxf.tools.common.ClassNameProcessor) List(java.util.List) ArrayList(java.util.ArrayList) ToolException(org.apache.cxf.tools.common.ToolException) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 5 with FrontEndGenerator

use of org.apache.cxf.tools.common.FrontEndGenerator in project cxf by apache.

the class PluginLoader method getFrontEndGenerators.

private List<FrontEndGenerator> getFrontEndGenerators(FrontEnd frontend) {
    List<FrontEndGenerator> generators = new ArrayList<>();
    String fullClzName = null;
    try {
        for (Generator generator : frontend.getGenerators().getGenerator()) {
            fullClzName = getGeneratorClass(frontend, generator);
            Class<?> clz = ClassLoaderUtils.loadClass(fullClzName, this.getClass());
            generators.add((FrontEndGenerator) clz.newInstance());
        }
    } catch (Exception e) {
        Message msg = new Message("FRONTEND_PROFILE_LOAD_FAIL", LOG, fullClzName);
        LOG.log(Level.SEVERE, msg.toString());
        throw new ToolException(msg, e);
    }
    return generators;
}
Also used : Message(org.apache.cxf.common.i18n.Message) FrontEndGenerator(org.apache.cxf.tools.common.FrontEndGenerator) ArrayList(java.util.ArrayList) ToolException(org.apache.cxf.tools.common.ToolException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) ToolException(org.apache.cxf.tools.common.ToolException) Generator(org.apache.cxf.tools.plugin.Generator) FrontEndGenerator(org.apache.cxf.tools.common.FrontEndGenerator)

Aggregations

FrontEndGenerator (org.apache.cxf.tools.common.FrontEndGenerator)5 FrontEndProfile (org.apache.cxf.tools.wsdlto.core.FrontEndProfile)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Message (org.apache.cxf.common.i18n.Message)2 Processor (org.apache.cxf.tools.common.Processor)2 ToolException (org.apache.cxf.tools.common.ToolException)2 FrontEnd (org.apache.cxf.tools.plugin.FrontEnd)2 AbstractWSDLBuilder (org.apache.cxf.tools.wsdlto.core.AbstractWSDLBuilder)2 Test (org.junit.Test)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Definition (javax.wsdl.Definition)1 JAXBException (javax.xml.bind.JAXBException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)1 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)1