Search in sources :

Example 1 with ServiceBuilder

use of org.apache.cxf.service.ServiceBuilder in project cxf by apache.

the class JavaToWSDLProcessor method getServiceBuilder.

@SuppressWarnings("unchecked")
public ServiceBuilder getServiceBuilder() throws ToolException {
    Object beanFilesParameter = context.get(ToolConstants.CFG_BEAN_CONFIG);
    List<String> beanDefinitions = new ArrayList<>();
    if (beanFilesParameter != null) {
        if (beanFilesParameter instanceof String) {
            beanDefinitions.add((String) beanFilesParameter);
        } else if (beanFilesParameter instanceof List) {
            // is there a better way to avoid the warning?
            beanDefinitions.addAll((List<String>) beanFilesParameter);
        } else {
            String[] list = (String[]) beanFilesParameter;
            for (String b : list) {
                beanDefinitions.add(b);
            }
        }
    }
    ServiceBuilderFactory builderFactory = ServiceBuilderFactory.getInstance(beanDefinitions, getDataBindingName());
    Class<?> clz = getServiceClass();
    context.put(Class.class, clz);
    if (clz.isInterface()) {
        context.put(ToolConstants.GEN_FROM_SEI, Boolean.TRUE);
        context.put(ToolConstants.SEI_CLASS, clz.getName());
    } else {
        context.put(ToolConstants.IMPL_CLASS, clz.getName());
        if (clz.getInterfaces().length == 1) {
            context.put(ToolConstants.SEI_CLASS, clz.getInterfaces()[0].getName());
        }
        context.put(ToolConstants.GEN_FROM_SEI, Boolean.FALSE);
    }
    builderFactory.setServiceClass(clz);
    builderFactory.setDatabindingName(getDataBindingName());
    // The service class determines the frontend, so no need to pass it in twice.
    ServiceBuilder builder = builderFactory.newBuilder();
    builder.validate();
    if (context.get(ToolConstants.CFG_ADDRESS) != null) {
        String address = (String) context.get(ToolConstants.CFG_ADDRESS);
        builder.setAddress(address);
    } else {
        builder.setAddress(DEFAULT_ADDRESS);
    }
    builder.setTransportId(getTransportId());
    builder.setBus(getBus());
    builder.setBindingId(getBindingId());
    return builder;
}
Also used : ServiceBuilderFactory(org.apache.cxf.tools.java2wsdl.processor.internal.ServiceBuilderFactory) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ServiceBuilder(org.apache.cxf.service.ServiceBuilder)

Example 2 with ServiceBuilder

use of org.apache.cxf.service.ServiceBuilder in project cxf by apache.

the class JavaToJSProcessor method getServiceBuilder.

@SuppressWarnings("unchecked")
public ServiceBuilder getServiceBuilder() throws ToolException {
    Object beanFilesParameter = context.get(ToolConstants.CFG_BEAN_CONFIG);
    List<String> beanDefinitions = new ArrayList<>();
    if (beanFilesParameter != null) {
        if (beanFilesParameter instanceof String) {
            beanDefinitions.add((String) beanFilesParameter);
        } else if (beanFilesParameter instanceof List) {
            // is there a better way to avoid the warning?
            beanDefinitions.addAll((List<String>) beanFilesParameter);
        } else {
            String[] list = (String[]) beanFilesParameter;
            for (String b : list) {
                beanDefinitions.add(b);
            }
        }
    }
    ServiceBuilderFactory builderFactory = ServiceBuilderFactory.getInstance(beanDefinitions, getDataBindingName());
    Class<?> clz = getServiceClass();
    context.put(Class.class, clz);
    if (clz.isInterface()) {
        context.put(ToolConstants.GEN_FROM_SEI, Boolean.TRUE);
        context.put(ToolConstants.SEI_CLASS, clz.getName());
    } else {
        context.put(ToolConstants.IMPL_CLASS, clz.getName());
        if (clz.getInterfaces().length == 1) {
            context.put(ToolConstants.SEI_CLASS, clz.getInterfaces()[0].getName());
        }
        context.put(ToolConstants.GEN_FROM_SEI, Boolean.FALSE);
    }
    builderFactory.setServiceClass(clz);
    builderFactory.setDatabindingName(getDataBindingName());
    // The service class determines the frontend, so no need to pass it in
    // twice.
    ServiceBuilder builder = builderFactory.newBuilder();
    builder.validate();
    builder.setTransportId(getTransportId());
    builder.setBus(getBus());
    builder.setBindingId(getBindingId());
    return builder;
}
Also used : ServiceBuilderFactory(org.apache.cxf.tools.java2wsdl.processor.internal.ServiceBuilderFactory) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ServiceBuilder(org.apache.cxf.service.ServiceBuilder)

Example 3 with ServiceBuilder

use of org.apache.cxf.service.ServiceBuilder in project cxf by apache.

the class ServiceBuilderFactoryTest method testGetJaxwsBuilder.

@Test
public void testGetJaxwsBuilder() {
    factory.setServiceClass(Stock.class);
    ServiceBuilder builder = factory.newBuilder();
    assertNotNull(builder);
    assertTrue(builder instanceof JaxwsServiceBuilder);
}
Also used : JaxwsServiceBuilder(org.apache.cxf.jaxws.JaxwsServiceBuilder) ServiceBuilder(org.apache.cxf.service.ServiceBuilder) JaxwsServiceBuilder(org.apache.cxf.jaxws.JaxwsServiceBuilder) SimpleServiceBuilder(org.apache.cxf.simple.SimpleServiceBuilder) Test(org.junit.Test)

Example 4 with ServiceBuilder

use of org.apache.cxf.service.ServiceBuilder in project cxf by apache.

the class ServiceBuilderFactoryTest method testGetSimpleBuilder.

@Test
public void testGetSimpleBuilder() {
    factory.setServiceClass(Hello.class);
    ServiceBuilder builder = factory.newBuilder();
    assertNotNull(builder);
    assertTrue(builder instanceof SimpleServiceBuilder);
}
Also used : SimpleServiceBuilder(org.apache.cxf.simple.SimpleServiceBuilder) ServiceBuilder(org.apache.cxf.service.ServiceBuilder) JaxwsServiceBuilder(org.apache.cxf.jaxws.JaxwsServiceBuilder) SimpleServiceBuilder(org.apache.cxf.simple.SimpleServiceBuilder) Test(org.junit.Test)

Example 5 with ServiceBuilder

use of org.apache.cxf.service.ServiceBuilder in project cxf by apache.

the class JavaToWSDLProcessor method process.

public void process() throws ToolException {
    String oldClassPath = System.getProperty(JAVA_CLASS_PATH);
    LOG.log(Level.FINE, "OLD_CP", oldClassPath);
    if (context.get(ToolConstants.CFG_CLASSPATH) != null) {
        String newCp = (String) context.get(ToolConstants.CFG_CLASSPATH);
        System.setProperty(JAVA_CLASS_PATH, newCp + File.pathSeparator + oldClassPath);
        LOG.log(Level.FINE, "NEW_CP", newCp);
    }
    // check for command line specification of data binding.
    ServiceBuilder builder = getServiceBuilder();
    ServiceInfo service = builder.createService();
    customize(service);
    File wsdlFile = getOutputFile(builder.getOutputFile(), service.getName().getLocalPart() + ".wsdl");
    File outputDir = getOutputDir(wsdlFile);
    if (context.containsKey(ToolConstants.CFG_WSDL)) {
        generators.add(getWSDLGenerator(wsdlFile));
    }
    if (context.containsKey(ToolConstants.CFG_WRAPPERBEAN)) {
        generators.add(getWrapperBeanGenerator());
        generators.add(getFaultBeanGenerator());
    }
    generate(service, outputDir);
    List<ServiceInfo> serviceList = new ArrayList<>();
    serviceList.add(service);
    context.put(ToolConstants.SERVICE_LIST, serviceList);
    System.setProperty(JAVA_CLASS_PATH, oldClassPath);
    LOG.log(Level.FINE, "RESUME_CP", oldClassPath);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) ArrayList(java.util.ArrayList) File(java.io.File) ServiceBuilder(org.apache.cxf.service.ServiceBuilder)

Aggregations

ServiceBuilder (org.apache.cxf.service.ServiceBuilder)7 ArrayList (java.util.ArrayList)3 File (java.io.File)2 List (java.util.List)2 JaxwsServiceBuilder (org.apache.cxf.jaxws.JaxwsServiceBuilder)2 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)2 SimpleServiceBuilder (org.apache.cxf.simple.SimpleServiceBuilder)2 ToolException (org.apache.cxf.tools.common.ToolException)2 ServiceBuilderFactory (org.apache.cxf.tools.java2wsdl.processor.internal.ServiceBuilderFactory)2 Test (org.junit.Test)2 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 BusApplicationContext (org.apache.cxf.bus.spring.BusApplicationContext)1 DataBinding (org.apache.cxf.databinding.DataBinding)1 AbstractServiceFactory (org.apache.cxf.frontend.AbstractServiceFactory)1 BasicNameManager (org.apache.cxf.javascript.BasicNameManager)1 NamespacePrefixAccumulator (org.apache.cxf.javascript.NamespacePrefixAccumulator)1 ServiceJavascriptBuilder (org.apache.cxf.javascript.service.ServiceJavascriptBuilder)1