Search in sources :

Example 1 with PluginLoader

use of org.apache.cxf.tools.wsdlto.core.PluginLoader in project cxf by apache.

the class JavaScriptContainer method execute.

@SuppressWarnings("unchecked")
public void execute() throws ToolException {
    if (hasInfoOption()) {
        return;
    }
    buildToolContext();
    validate(context);
    WSDLConstants.WSDLVersion version = getWSDLVersion();
    String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
    List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
    if (serviceList == null) {
        serviceList = new ArrayList<>();
        PluginLoader pluginLoader = PluginLoader.newInstance();
        // for JavaScript generation, we always use JAX-WS.
        FrontEndProfile frontend = pluginLoader.getFrontEndProfile("jaxws");
        // 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());
            builder.build(URIParserUtil.getAbsoluteURI(wsdlURL));
            builder.customize();
            Definition definition = builder.getWSDLModel();
            context.put(Definition.class, definition);
            builder.validate(definition);
            WSDLServiceBuilder serviceBuilder = new WSDLServiceBuilder(getBus());
            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);
            }
        } else {
            // TODO: wsdl2.0 support
            throw new ToolException("Only WSDL 1.1 supported");
        }
    }
    if (serviceList.isEmpty()) {
        throw new ToolException("Did not find any services in WSDL");
    }
    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, new ClassCollector());
    WSDLToJavaScriptProcessor processor = new WSDLToJavaScriptProcessor();
    for (ServiceInfo service : serviceList) {
        context.put(ServiceInfo.class, service);
        validate(service);
        processor.setEnvironment(context);
        processor.process();
    }
}
Also used : AbstractWSDLBuilder(org.apache.cxf.tools.wsdlto.core.AbstractWSDLBuilder) ClassCollector(org.apache.cxf.tools.util.ClassCollector) Definition(javax.wsdl.Definition) 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) ArrayList(java.util.ArrayList) List(java.util.List) ToolException(org.apache.cxf.tools.common.ToolException) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) PluginLoader(org.apache.cxf.tools.wsdlto.core.PluginLoader)

Example 2 with PluginLoader

use of org.apache.cxf.tools.wsdlto.core.PluginLoader 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)

Aggregations

AbstractWSDLBuilder (org.apache.cxf.tools.wsdlto.core.AbstractWSDLBuilder)2 FrontEndProfile (org.apache.cxf.tools.wsdlto.core.FrontEndProfile)2 PluginLoader (org.apache.cxf.tools.wsdlto.core.PluginLoader)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Definition (javax.wsdl.Definition)1 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)1 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)1 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)1 FrontEndGenerator (org.apache.cxf.tools.common.FrontEndGenerator)1 Processor (org.apache.cxf.tools.common.Processor)1 ToolException (org.apache.cxf.tools.common.ToolException)1 FrontEnd (org.apache.cxf.tools.plugin.FrontEnd)1 Plugin (org.apache.cxf.tools.plugin.Plugin)1 ClassCollector (org.apache.cxf.tools.util.ClassCollector)1 AntGenerator (org.apache.cxf.tools.wsdlto.frontend.jaxws.generators.AntGenerator)1 ImplGenerator (org.apache.cxf.tools.wsdlto.frontend.jaxws.generators.ImplGenerator)1 WSDLToJavaProcessor (org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.WSDLToJavaProcessor)1 JAXWSDefinitionBuilder (org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder)1