You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by as...@apache.org on 2010/06/22 10:05:20 UTC
svn commit: r956802 - in /cxf/branches/2.2.x-fixes: ./ tools/javato/ws/
tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/
tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/
tools/javato/ws/src/main/java/org/apac...
Author: asoldano
Date: Tue Jun 22 08:05:20 2010
New Revision: 956802
URL: http://svn.apache.org/viewvc?rev=956802&view=rev
Log:
Merged revisions 956044 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r956044 | asoldano | 2010-06-18 18:40:44 +0200 (ven, 18 giu 2010) | 2 lines
[CXF-2852] Refactor java2ws tools for requiring Spring just when a spring bean configuration file is actually specified
........
Added:
cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
- copied unchanged from r956044, cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
- copied unchanged from r956044, cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/tools/javato/ws/pom.xml
cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java
cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java
cxf/branches/2.2.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 22 08:05:20 2010
@@ -1 +1 @@
-/cxf/trunk:956088,956658
+/cxf/trunk:956044,956088,956658
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.2.x-fixes/tools/javato/ws/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/javato/ws/pom.xml?rev=956802&r1=956801&r2=956802&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/javato/ws/pom.xml (original)
+++ cxf/branches/2.2.x-fixes/tools/javato/ws/pom.xml Tue Jun 22 08:05:20 2010
@@ -140,7 +140,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/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java?rev=956802&r1=956801&r2=956802&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java (original)
+++ cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2js/processor/JavaToJSProcessor.java Tue Jun 22 08:05:20 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/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java?rev=956802&r1=956801&r2=956802&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java (original)
+++ cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java Tue Jun 22 08:05:20 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();
Modified: cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java?rev=956802&r1=956801&r2=956802&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java (original)
+++ cxf/branches/2.2.x-fixes/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactory.java Tue Jun 22 08:05:20 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) {
Modified: cxf/branches/2.2.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java?rev=956802&r1=956801&r2=956802&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java (original)
+++ cxf/branches/2.2.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/ServiceBuilderFactoryTest.java Tue Jun 22 08:05:20 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);
}