cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject svn commit: r956044 - in /cxf/trunk/tools/javato/ws: ./ src/main/java/org/apache/cxf/tools/java2js/processor/ src/main/java/org/apache/cxf/tools/java2wsdl/processor/ src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ src/test/java/org/apa...
Date Fri, 18 Jun 2010 16:40:45 GMT
Author: asoldano
Date: Fri Jun 18 16:40:44 2010
New Revision: 956044

URL: http://svn.apache.org/viewvc?rev=956044&view=rev
Log:
[CXF-2852] Refactor java2ws tools for requiring Spring just when a spring bean configuration
file is actually specified

Added:
    cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
  (with props)
    cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
  (with props)
Modified:
    cxf/trunk/tools/javato/ws/pom.xml
    cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java
    cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
    cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java
    cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java

Modified: cxf/trunk/tools/javato/ws/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/pom.xml?rev=956044&r1=956043&r2=956044&view=diff
==============================================================================
--- cxf/trunk/tools/javato/ws/pom.xml (original)
+++ cxf/trunk/tools/javato/ws/pom.xml Fri Jun 18 16:40:44 2010
@@ -128,7 +128,6 @@
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-frontend-jaxws</artifactId>
             <version>${project.version}</version>
-            <scope>test</scope>
             <exclusions>
                 <exclusion>
                     <groupId>org.apache.cxf</groupId>

Modified: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java?rev=956044&r1=956043&r2=956044&view=diff
==============================================================================
--- cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java
(original)
+++ cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java
Fri Jun 18 16:40:44 2010
@@ -37,7 +37,6 @@ import javax.xml.ws.soap.SOAPBinding;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.spring.BusApplicationContext;
 import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
@@ -56,41 +55,12 @@ import org.apache.cxf.tools.common.ToolC
 import org.apache.cxf.tools.common.ToolException;
 import org.apache.cxf.tools.java2wsdl.processor.internal.ServiceBuilderFactory;
 import org.apache.cxf.tools.util.AnnotationUtil;
-import org.springframework.beans.factory.BeanDefinitionStoreException;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.FileSystemResource;
 
 public class JavaToJSProcessor implements Processor {
     private static final Logger LOG = LogUtils.getL7dLogger(JavaToJSProcessor.class);
     private static final String JAVA_CLASS_PATH = "java.class.path";
     private static final Charset UTF8 = Charset.forName("utf-8");
     private ToolContext context;
-    private ApplicationContext applicationContext;
-
-    /**
-     * This is factored out to permit use in a unit test.
-     * 
-     * @param bus
-     * @return
-     */
-    public static ApplicationContext getApplicationContext(Bus bus, List<String> additionalFilePathnames)
{
-        BusApplicationContext busApplicationContext = bus.getExtension(BusApplicationContext.class);
-        GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
-        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
-        reader.loadBeanDefinitions(new ClassPathResource("META-INF/cxf/java2wsbeans.xml"));
-        for (String pathname : additionalFilePathnames) {
-            try {
-                reader.loadBeanDefinitions(new FileSystemResource(pathname));
-            } catch (BeanDefinitionStoreException bdse) {
-                throw new ToolException("Unable to open bean definition file " + pathname,
bdse.getCause());
-            }
-        }
-
-        return appContext;
-    }
 
     public void process() throws ToolException {
         String oldClassPath = System.getProperty(JAVA_CLASS_PATH);
@@ -117,10 +87,10 @@ public class JavaToJSProcessor implement
             if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) {
                 JavascriptQueryHandler.writeUtilsToResponseStream(JavaToJSProcessor.class,
fileOutputStream);
             }
-            
+
             OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream,
UTF8);
             BufferedWriter writer = new BufferedWriter(outputStreamWriter);
-                
+
             for (SchemaInfo schema : schemata) {
                 SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo
                     .getXmlSchemaCollection(), prefixManager, nameManager);
@@ -128,10 +98,8 @@ public class JavaToJSProcessor implement
                 writer.append(allThatJavascript);
             }
 
-            ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo,

-                                                                                   null,
-                                                                                   prefixManager,
-                                                                                   nameManager);
+            ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo,
null,
+                                                                                 prefixManager,
nameManager);
             serviceBuilder.walk();
             String serviceJavascript = serviceBuilder.getCode();
             writer.append(serviceJavascript);
@@ -157,14 +125,13 @@ public class JavaToJSProcessor implement
                 // is there a better way to avoid the warning?
                 beanDefinitions.addAll((List<String>)beanFilesParameter);
             } else {
-                String list[] = (String[]) beanFilesParameter;
+                String list[] = (String[])beanFilesParameter;
                 for (String b : list) {
                     beanDefinitions.add(b);
                 }
             }
         }
-        applicationContext = getApplicationContext(getBus(), beanDefinitions);
-        ServiceBuilderFactory builderFactory = ServiceBuilderFactory.getInstance();
+        ServiceBuilderFactory builderFactory = ServiceBuilderFactory.getInstance(beanDefinitions);
         Class<?> clz = getServiceClass();
         context.put(Class.class, clz);
         if (clz.isInterface()) {
@@ -183,7 +150,7 @@ public class JavaToJSProcessor implement
         builderFactory.setDatabindingName(getDataBindingName());
         // The service class determines the frontend, so no need to pass it in
         // twice.
-        ServiceBuilder builder = builderFactory.newBuilder(applicationContext);
+        ServiceBuilder builder = builderFactory.newBuilder();
 
         builder.validate();
 
@@ -223,13 +190,12 @@ public class JavaToJSProcessor implement
     protected File getOutputDir(File wsdlLocation) {
         String dir = (String)context.get(ToolConstants.CFG_OUTPUTDIR);
         if (dir == null) {
-            if (wsdlLocation == null 
-                || wsdlLocation.getParentFile() == null
+            if (wsdlLocation == null || wsdlLocation.getParentFile() == null
                 || !wsdlLocation.getParentFile().exists()) {
                 dir = "./";
             } else {
                 dir = wsdlLocation.getParent();
-            } 
+            }
         }
         return new File(dir);
     }

Modified: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java?rev=956044&r1=956043&r2=956044&view=diff
==============================================================================
--- cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
(original)
+++ cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
Fri Jun 18 16:40:44 2010
@@ -31,7 +31,6 @@ import javax.xml.ws.soap.SOAPBinding;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.spring.BusApplicationContext;
 import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
@@ -49,12 +48,7 @@ import org.apache.cxf.tools.java2wsdl.ge
 import org.apache.cxf.tools.java2wsdl.generator.wsdl11.WrapperBeanGenerator;
 import org.apache.cxf.tools.java2wsdl.processor.internal.ServiceBuilderFactory;
 import org.apache.cxf.tools.util.AnnotationUtil;
-import org.springframework.beans.factory.BeanDefinitionStoreException;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.FileSystemResource;
+
 
 public class JavaToWSDLProcessor implements Processor {
     private static final Logger LOG = LogUtils.getL7dLogger(JavaToWSDLProcessor.class);
@@ -62,7 +56,6 @@ public class JavaToWSDLProcessor impleme
     private static final String JAVA_CLASS_PATH = "java.class.path";
     private ToolContext context;
     private final List<AbstractGenerator> generators = new ArrayList<AbstractGenerator>();
-    private ApplicationContext applicationContext;
     
     private void customize(ServiceInfo service) {
         if (context.containsKey(ToolConstants.CFG_TNS)) {
@@ -91,26 +84,6 @@ public class JavaToWSDLProcessor impleme
         
     }
     
-    /**
-     * This is factored out to permit use in a unit test.
-     * @param bus
-     * @return
-     */
-    public static ApplicationContext getApplicationContext(Bus bus, List<String> additionalFilePathnames)
{
-        BusApplicationContext busApplicationContext = bus.getExtension(BusApplicationContext.class);
-        GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
-        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
-        reader.loadBeanDefinitions(new ClassPathResource("META-INF/cxf/java2wsbeans.xml"));
-        for (String pathname : additionalFilePathnames) {
-            try {
-                reader.loadBeanDefinitions(new FileSystemResource(pathname));
-            } catch (BeanDefinitionStoreException bdse) {
-                throw new ToolException("Unable to open bean definition file " + pathname,
bdse.getCause());
-            }
-        }
-            
-        return appContext;
-    }
     
     public void process() throws ToolException {
         String oldClassPath = System.getProperty(JAVA_CLASS_PATH);
@@ -199,8 +172,8 @@ public class JavaToWSDLProcessor impleme
                 }
             }
         }
-        applicationContext = getApplicationContext(getBus(), beanDefinitions);
-        ServiceBuilderFactory builderFactory = ServiceBuilderFactory.getInstance();
+        
+        ServiceBuilderFactory builderFactory = ServiceBuilderFactory.getInstance(beanDefinitions);
         Class<?> clz = getServiceClass();
         context.put(Class.class, clz);
         if (clz.isInterface()) {
@@ -218,7 +191,7 @@ public class JavaToWSDLProcessor impleme
         builderFactory.setServiceClass(clz);
         builderFactory.setDatabindingName(getDataBindingName());
         // The service class determines the frontend, so no need to pass it in twice.
-        ServiceBuilder builder = builderFactory.newBuilder(applicationContext);
+        ServiceBuilder builder = builderFactory.newBuilder();
 
         builder.validate();
 

Added: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java?rev=956044&view=auto
==============================================================================
--- cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
(added)
+++ cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
Fri Jun 18 16:40:44 2010
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.processor.internal;
+
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.frontend.AbstractServiceFactory;
+import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxws.JaxwsServiceBuilder;
+import org.apache.cxf.service.ServiceBuilder;
+import org.apache.cxf.simple.SimpleServiceBuilder;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.java2wsdl.processor.FrontendFactory;
+import org.apache.cxf.tools.java2wsdl.processor.FrontendFactory.Style;
+
+/**
+ * This class constructs ServiceBuilder objects. These objects are used to access the services
and the data
+ * bindings to generate the wsdl.
+ */
+public final class DefaultServiceBuilderFactory extends ServiceBuilderFactory {
+
+    @Override
+    public ServiceBuilder newBuilder(FrontendFactory.Style s) {
+        DataBinding dataBinding;
+        final String dbn = getDatabindingName();
+        if (ToolConstants.JAXB_DATABINDING.equals(dbn)) {
+            dataBinding = new JAXBDataBinding();
+        } else if (ToolConstants.AEGIS_DATABINDING.equals(dbn)) {
+            dataBinding = new AegisDatabinding();
+        } else {
+            throw new ToolException("Unsupported databinding: " + s);
+        }
+        AbstractServiceFactory builder = null;
+        if (Style.Jaxws.equals(s)) {
+            builder = new JaxwsServiceBuilder();
+        } else if (Style.Simple.equals(s)) {
+            builder = new SimpleServiceBuilder();
+        } else {
+            throw new ToolException("Unsupported frontend style: " + s);
+        }
+        builder.setDataBinding(dataBinding);
+        builder.setServiceClass(serviceClass);
+        return builder;
+    }
+}

Propchange: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java?rev=956044&r1=956043&r2=956044&view=diff
==============================================================================
--- cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java
(original)
+++ cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java
Fri Jun 18 16:40:44 2010
@@ -19,98 +19,54 @@
 
 package org.apache.cxf.tools.java2wsdl.processor.internal;
 
-import org.apache.cxf.databinding.DataBinding;
-import org.apache.cxf.frontend.AbstractServiceFactory;
+import java.util.List;
+
 import org.apache.cxf.service.ServiceBuilder;
 import org.apache.cxf.tools.common.ToolConstants;
-import org.apache.cxf.tools.common.ToolException;
 import org.apache.cxf.tools.java2wsdl.processor.FrontendFactory;
-import org.apache.cxf.tools.util.NameUtil;
 
-import org.springframework.context.ApplicationContext;
 /**
- * This class constructs ServiceBuilder objects. These objects are used to access the services
- * and the data bindings to generate the wsdl.
+ * This class constructs ServiceBuilder objects. These objects are used to access the services
and the data
+ * bindings to generate the wsdl.
  */
-public final class ServiceBuilderFactory {
-    private static ServiceBuilderFactory instance;
-    private static FrontendFactory frontend;
-    private static String databindingName;
-    private Class serviceClass;
-    
-    private ServiceBuilderFactory() {
+public abstract class ServiceBuilderFactory {
+    protected FrontendFactory frontend;
+    protected String databindingName;
+    protected Class<?> serviceClass;
+
+    protected ServiceBuilderFactory() {
         frontend = FrontendFactory.getInstance();
         databindingName = ToolConstants.DEFAULT_DATA_BINDING_NAME;
     }
-    
-    public static ServiceBuilderFactory getInstance() {
-        if (instance == null) {
-            instance = new ServiceBuilderFactory();
-        }
-        return instance;
-    }
 
-    public ServiceBuilder newBuilder(ApplicationContext applicationContext) {
-        return newBuilder(applicationContext, getStyle());
-    }
-    
-    /**
-     * Convert a parameter value to the name of a bean we'd use for a data binding.
-     * @param databindingName
-     * @return
-     */
-    public static String databindingNameToBeanName(String dbName) {
-        return NameUtil.capitalize(dbName.toLowerCase()) + ToolConstants.DATABIND_BEAN_NAME_SUFFIX;
-    }
-
-    public ServiceBuilder newBuilder(ApplicationContext applicationContext, FrontendFactory.Style
s) {
-        DataBinding dataBinding;
-        String databindingBeanName = databindingNameToBeanName(databindingName);
-        try {
-            dataBinding = (DataBinding)applicationContext.getBean(databindingBeanName);
-        } catch (RuntimeException e) {
-            throw new ToolException("Cannot get databinding bean " + databindingBeanName

-                                    + " for databinding " + databindingName);
-        }
-
-        String beanName = getBuilderBeanName(s);
-        ServiceBuilder builder = null;
-
-        try {
-            builder = (ServiceBuilder) applicationContext.getBean(beanName, ServiceBuilder.class);
-            AbstractServiceFactory serviceFactory = (AbstractServiceFactory)builder;
-            serviceFactory.setDataBinding(dataBinding);
-        } catch (RuntimeException e) {
-            throw new ToolException("Can not get ServiceBuilder bean " + beanName 
-                                    + "to initialize the ServiceBuilder for style: " + s
-                                    + " Reason: \n" + e.getMessage(),
-                                    e);
+    public static ServiceBuilderFactory getInstance(List<String> beanDefinitions) {
+        ServiceBuilderFactory factory;
+        if (beanDefinitions == null || beanDefinitions.isEmpty()) {
+            factory = new DefaultServiceBuilderFactory();
+        } else {
+            factory = new SpringServiceBuilderFactory(beanDefinitions);
         }
-        builder.setServiceClass(serviceClass);
-        return builder;
+        return factory;
     }
 
-    /**
-     * Return the name of a prototype bean from Spring that can provide the service. The
use of a bean
-     * allows for the possibility of an override.
-     * @param s Style of service
-     * @return name of bean.
-     */
-    protected String getBuilderBeanName(FrontendFactory.Style s) {
-        return s + "ServiceBuilderBean";
+    public ServiceBuilder newBuilder() {
+        return newBuilder(getStyle());
     }
 
+    public abstract ServiceBuilder newBuilder(FrontendFactory.Style s);
+
     public FrontendFactory.Style getStyle() {
         frontend.setServiceClass(this.serviceClass);
         return frontend.discoverStyle();
     }
 
-    public void setServiceClass(Class c) {
+    public void setServiceClass(Class<?> c) {
         this.serviceClass = c;
     }
 
     /**
      * Return the databinding name.
+     * 
      * @return
      */
     public String getDatabindingName() {
@@ -119,6 +75,7 @@ public final class ServiceBuilderFactory
 
     /**
      * Set the databinding name
+     * 
      * @param databindingName
      */
     public void setDatabindingName(String arg) {

Added: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java?rev=956044&view=auto
==============================================================================
--- cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
(added)
+++ cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
Fri Jun 18 16:40:44 2010
@@ -0,0 +1,136 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.processor.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.BusApplicationContext;
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.frontend.AbstractServiceFactory;
+import org.apache.cxf.service.ServiceBuilder;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.java2wsdl.processor.FrontendFactory;
+import org.apache.cxf.tools.util.NameUtil;
+
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.FileSystemResource;
+
+/**
+ * This class constructs ServiceBuilder objects using Spring. These objects are used to access
the services
+ * and the data bindings to generate the wsdl.
+ */
+public final class SpringServiceBuilderFactory extends ServiceBuilderFactory {
+
+    private List<String> beanDefinitions;
+
+    public SpringServiceBuilderFactory(List<String> beanDefinitions) {
+        super();
+        this.beanDefinitions = beanDefinitions;
+    }
+
+    public SpringServiceBuilderFactory() {
+        super();
+        this.beanDefinitions = new ArrayList<String>(0);
+    }
+
+    /**
+     * Convert a parameter value to the name of a bean we'd use for a data binding.
+     * 
+     * @param databindingName
+     * @return
+     */
+    public static String databindingNameToBeanName(String dbName) {
+        return NameUtil.capitalize(dbName.toLowerCase()) + ToolConstants.DATABIND_BEAN_NAME_SUFFIX;
+    }
+
+    @Override
+    public ServiceBuilder newBuilder(FrontendFactory.Style s) {
+        ApplicationContext applicationContext = getApplicationContext(beanDefinitions);
+        DataBinding dataBinding;
+        String databindingBeanName = databindingNameToBeanName(databindingName);
+        try {
+            dataBinding = (DataBinding)applicationContext.getBean(databindingBeanName);
+        } catch (RuntimeException e) {
+            throw new ToolException("Cannot get databinding bean " + databindingBeanName
+                                    + " for databinding " + databindingName);
+        }
+
+        String beanName = getBuilderBeanName(s);
+        ServiceBuilder builder = null;
+
+        try {
+            builder = (ServiceBuilder)applicationContext.getBean(beanName, ServiceBuilder.class);
+            AbstractServiceFactory serviceFactory = (AbstractServiceFactory)builder;
+            serviceFactory.setDataBinding(dataBinding);
+        } catch (RuntimeException e) {
+            throw new ToolException("Can not get ServiceBuilder bean " + beanName
+                                    + "to initialize the ServiceBuilder for style: " + s
+ " Reason: \n"
+                                    + e.getMessage(), e);
+        }
+        builder.setServiceClass(serviceClass);
+        return builder;
+    }
+
+    /**
+     * Return the name of a prototype bean from Spring that can provide the service. The
use of a bean allows
+     * for the possibility of an override.
+     * 
+     * @param s Style of service
+     * @return name of bean.
+     */
+    protected String getBuilderBeanName(FrontendFactory.Style s) {
+        return s + "ServiceBuilderBean";
+    }
+
+    /**
+     * This is factored out to permit use in a unit test.
+     * 
+     * @param bus
+     * @return
+     */
+    public static ApplicationContext getApplicationContext(List<String> additionalFilePathnames)
{
+        BusApplicationContext busApplicationContext = BusFactory.getDefaultBus()
+            .getExtension(BusApplicationContext.class);
+        GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
+        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
+        reader.loadBeanDefinitions(new ClassPathResource("META-INF/cxf/java2wsbeans.xml"));
+        for (String pathname : additionalFilePathnames) {
+            try {
+                reader.loadBeanDefinitions(new FileSystemResource(pathname));
+            } catch (BeanDefinitionStoreException bdse) {
+                throw new ToolException("Unable to open bean definition file " + pathname,
bdse.getCause());
+            }
+        }
+
+        return appContext;
+    }
+
+    public void setBeanDefinitions(List<String> beanDefinitions) {
+        this.beanDefinitions = beanDefinitions;
+    }
+
+}

Propchange: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java?rev=956044&r1=956043&r2=956044&view=diff
==============================================================================
--- cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java
(original)
+++ cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java
Fri Jun 18 16:40:44 2010
@@ -21,43 +21,21 @@ package org.apache.cxf.tools.java2wsdl.p
 
 import java.util.ArrayList;
 
-import org.apache.cxf.BusFactory;
 import org.apache.cxf.jaxws.JaxwsServiceBuilder;
 import org.apache.cxf.service.ServiceBuilder;
 import org.apache.cxf.simple.SimpleServiceBuilder;
 import org.apache.cxf.tools.fortest.classnoanno.docbare.Stock;
 import org.apache.cxf.tools.fortest.simple.Hello;
-import org.apache.cxf.tools.java2wsdl.processor.FrontendFactory;
-import org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
-import org.springframework.context.ApplicationContext;
 
 public class ServiceBuilderFactoryTest extends Assert {
-    ServiceBuilderFactory factory = ServiceBuilderFactory.getInstance();
-    private ApplicationContext applicationContext;
-    
-    @Before
-    public void setUp() {
-        applicationContext = JavaToWSDLProcessor.getApplicationContext(BusFactory.getDefaultBus(),

-                                                                       new ArrayList<String>());
-    }
-    
-    @Test
-    public void testGetBuilderBeanName() {
-        assertNotNull(factory);
-        assertEquals("JaxwsServiceBuilderBean",
-                     factory.getBuilderBeanName(FrontendFactory.Style.Jaxws));
-
-        assertEquals("SimpleServiceBuilderBean",
-                     factory.getBuilderBeanName(FrontendFactory.Style.Simple));
-    }
+    ServiceBuilderFactory factory = ServiceBuilderFactory.getInstance(new ArrayList<String>());
 
     @Test
     public void testGetJaxwsBuilder() {
         factory.setServiceClass(Stock.class);
-        ServiceBuilder builder = factory.newBuilder(applicationContext);
+        ServiceBuilder builder = factory.newBuilder();
         assertNotNull(builder);
         assertTrue(builder instanceof JaxwsServiceBuilder);
     }
@@ -65,7 +43,7 @@ public class ServiceBuilderFactoryTest e
     @Test
     public void testGetSimpleBuilder() {
         factory.setServiceClass(Hello.class);
-        ServiceBuilder builder = factory.newBuilder(applicationContext);
+        ServiceBuilder builder = factory.newBuilder();
         assertNotNull(builder);
         assertTrue(builder instanceof SimpleServiceBuilder);
     }



Mime
View raw message