summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime
diff options
context:
space:
mode:
authorramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68>2009-09-04 07:01:10 +0000
committerramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68>2009-09-04 07:01:10 +0000
commit891c195256186adb8717a521bd2af7cbf9d3c851 (patch)
treea63c28e56fd41aca4d973e2622a59c564c48a729 /branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime
parent43abbe736d2724a239d50ff38d43560ebe697b77 (diff)
Fixes for TUSCANY-3250: Support for multiple application context using MANIFEST.MF
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@811232 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime')
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java29
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java110
2 files changed, 57 insertions, 82 deletions
diff --git a/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java b/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java
new file mode 100644
index 0000000000..c1aaf1570f
--- /dev/null
+++ b/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java
@@ -0,0 +1,29 @@
+package org.apache.tuscany.sca.implementation.spring.runtime.context;
+
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+
+public class SCAGenericApplicationContext extends GenericApplicationContext {
+
+ ClassLoader classloader = null;
+
+ public SCAGenericApplicationContext(DefaultListableBeanFactory beanFactory,
+ ApplicationContext parent,
+ ClassLoader classloader) {
+ super(beanFactory, parent);
+ this.classloader = classloader;
+ }
+
+ public SCAGenericApplicationContext(ApplicationContext parent,
+ ClassLoader classloader) {
+ super(parent);
+ this.classloader = classloader;
+ }
+
+ @Override
+ protected void postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory) {
+ beanFactory.setBeanClassLoader(classloader);
+ }
+}
diff --git a/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java b/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
index d53edf2325..c579915970 100644
--- a/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
+++ b/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
@@ -20,7 +20,6 @@
package org.apache.tuscany.sca.implementation.spring.runtime.context;
import java.net.URL;
-import java.util.Iterator;
import java.util.List;
import org.apache.tuscany.sca.implementation.spring.processor.ComponentNameAnnotationProcessor;
@@ -31,17 +30,11 @@ import org.apache.tuscany.sca.implementation.spring.processor.PropertyAnnotation
import org.apache.tuscany.sca.implementation.spring.processor.PropertyValueStub;
import org.apache.tuscany.sca.implementation.spring.processor.ReferenceAnnotationProcessor;
import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.config.ConstructorArgumentValues;
-import org.springframework.beans.factory.config.TypedStringValue;
-import org.springframework.beans.factory.support.DefaultListableBeanFactory;
-import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.XmlBeanFactory;
-import org.springframework.context.ApplicationContext;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.AbstractApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.UrlResource;
import org.springframework.core.SpringVersion;
@@ -59,29 +52,7 @@ public class SpringContextTie {
private boolean isAnnotationSupported;
private String versionSupported;
- // TUSCANY-3128
- // extension of the generic application context just to force the classloader
- // on the bean factory to stay set to the contribution classloader
- // instead of being set back to the application classloader
- private class LocalGenericApplicationContext extends GenericApplicationContext{
-
- ClassLoader classloader = null;
-
- public LocalGenericApplicationContext(DefaultListableBeanFactory beanFactory,
- ApplicationContext parent,
- ClassLoader classloader) {
- super(beanFactory, parent);
- this.classloader = classloader;
- }
-
- @Override
- protected void postProcessBeanFactory(
- ConfigurableListableBeanFactory beanFactory) {
- beanFactory.setBeanClassLoader(classloader);
- }
- }
-
- public SpringContextTie(SpringImplementationStub implementation, URL resource, boolean annotationSupport, String versionSupported) throws Exception {
+ public SpringContextTie(SpringImplementationStub implementation, List<URL> resource, boolean annotationSupport, String versionSupported) throws Exception {
this.implementation = implementation;
this.isAnnotationSupported = annotationSupport;
this.versionSupported = versionSupported;
@@ -110,61 +81,36 @@ public class SpringContextTie {
/**
* Create appropriate ApplicationContext by reading the bean definitions.
*/
- private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, URL resource) {
+ private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, List<URL> resources) {
- XmlBeanFactory beanFactory = new XmlBeanFactory(new UrlResource(resource));
- beanFactory.setBeanClassLoader(implementation.getClassLoader());
- AbstractApplicationContext appContext = null;
-
- for (String bean : beanFactory.getBeanDefinitionNames()) {
- String beanClassName = (beanFactory.getType(bean)).getName();
- // Using FileSystemXmlApplicationContext is not supported, as the
- // SCA runtime does not support paths relative to current VM working directory.
- if (beanClassName.indexOf(".FileSystemXmlApplicationContext") != -1) {
- throw new RuntimeException("Usage of FileSystemXmlApplicationContext Bean is not supported");
- }
-
- if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1) {
- BeanDefinition beanDef = beanFactory.getBeanDefinition(bean);
- String[] configLocations = null;
- List<ConstructorArgumentValues.ValueHolder> conArgs =
- beanDef.getConstructorArgumentValues().getGenericArgumentValues();
- for (ConstructorArgumentValues.ValueHolder conArg : conArgs) {
- if (conArg.getValue() instanceof TypedStringValue) {
- TypedStringValue value = (TypedStringValue) conArg.getValue();
- if (value.getValue().indexOf(".xml") != -1)
- configLocations = new String[]{value.getValue()};
- }
- if (conArg.getValue() instanceof ManagedList) {
- Iterator itml = ((ManagedList)conArg.getValue()).iterator();
- StringBuffer values = new StringBuffer();
- while (itml.hasNext()) {
- TypedStringValue next = (TypedStringValue)itml.next();
- if (next.getValue().indexOf(".xml") != -1) {
- values.append(implementation.getClassLoader().getResource(next.getValue()).toString());
- values.append("~");
- }
- }
- configLocations = (values.toString()).split("~");
- }
- }
-
- appContext = new ClassPathXmlApplicationContext(configLocations, true, scaParentContext);
- if (isAnnotationSupported)
- includeAnnotationProcessors(appContext.getBeanFactory());
- return appContext;
- }
- }
+ XmlBeanFactory beanFactory = null;
+ AbstractApplicationContext appContext = null;
+
+ if (resources.size() > 1)
+ {
+ GenericApplicationContext appCtx =
+ new SCAGenericApplicationContext(scaParentContext, implementation.getClassLoader());
+ XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
+ for (URL resource : resources) {
+ xmlReader.loadBeanDefinitions(new UrlResource(resource));
+ }
+ xmlReader.setBeanClassLoader(implementation.getClassLoader());
+ if (isAnnotationSupported)
+ includeAnnotationProcessors(appCtx.getBeanFactory());
+ return appCtx;
+
+ } else {
+ beanFactory = new XmlBeanFactory(new UrlResource(resources.get(0)));
+ beanFactory.setBeanClassLoader(implementation.getClassLoader());
+ }
// use the generic application context as default
- if (isAnnotationSupported)
- {
+ if (isAnnotationSupported) {
includeAnnotationProcessors(beanFactory);
- }
-
- appContext = new LocalGenericApplicationContext(beanFactory,
- scaParentContext,
- implementation.getClassLoader());
+ }
+ appContext = new SCAGenericApplicationContext(beanFactory,
+ scaParentContext,
+ implementation.getClassLoader());
return appContext;
}