summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/implementation-spring
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 23:44:59 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 23:44:59 +0000
commit71a7cba384b8ae7f4578fb9ab1f725d5ce616074 (patch)
tree98bbc7c066d037a8d9ea1fea7a3ccfa64419ab11 /branches/sca-java-1.x/modules/implementation-spring
parent01a38d872dc2692d2a31f07f9c8f8098aa078853 (diff)
Merge all changes from 1.5.2 branch into trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@830026 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java114
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java6
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java120
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ConfigurationPropertiesExtensionPoint.java2
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/DefaultConfigurationPropertiesExtensionPoint.java8
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java14
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java5
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java5
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java16
9 files changed, 187 insertions, 103 deletions
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 c579915970..6e8f1e8df4 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,6 +20,7 @@
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;
@@ -30,11 +31,17 @@ 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.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
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;
@@ -51,11 +58,35 @@ public class SpringContextTie {
private SpringImplementationStub implementation;
private boolean isAnnotationSupported;
private String versionSupported;
+ private boolean isMultipleContextSupport;
- public SpringContextTie(SpringImplementationStub implementation, List<URL> resource, boolean annotationSupport, String versionSupported) throws Exception {
+ // 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, boolean multipleContextSupport) throws Exception {
this.implementation = implementation;
this.isAnnotationSupported = annotationSupport;
this.versionSupported = versionSupported;
+ this.isMultipleContextSupport = multipleContextSupport;
if (! this.versionSupported.equals("ANY")) {
if ((SpringVersion.getVersion()!= null) && (! SpringVersion.getVersion().equals(versionSupported)))
throw new RuntimeException("Unsupported version: Use only Spring Framework Version " + versionSupported);
@@ -81,36 +112,63 @@ public class SpringContextTie {
/**
* Create appropriate ApplicationContext by reading the bean definitions.
*/
- private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, List<URL> resources) {
+ private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, URL resource) {
- 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());
- }
+ XmlBeanFactory beanFactory = new XmlBeanFactory(new UrlResource(resource));
+ beanFactory.setBeanClassLoader(implementation.getClassLoader());
+ AbstractApplicationContext appContext = null;
+
+ if (isMultipleContextSupport) {
+ 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;
+ }
+ }
+ }
// use the generic application context as default
- if (isAnnotationSupported) {
+ if (isAnnotationSupported)
+ {
includeAnnotationProcessors(beanFactory);
- }
- appContext = new SCAGenericApplicationContext(beanFactory,
- scaParentContext,
- implementation.getClassLoader());
+ }
+
+ appContext = new LocalGenericApplicationContext(beanFactory,
+ scaParentContext,
+ implementation.getClassLoader());
return appContext;
}
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java
index 61b707b1e1..bee0e462fc 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java
@@ -44,7 +44,7 @@ public class SpringImplementation extends ImplementationImpl implements Implemen
// The location attribute which points to the Spring application-context XML file
private String location;
// The application-context file as a Spring Resource
- private List<URL> resource;
+ private URL resource;
private ComponentType componentType;
// Mapping of Services to Beans
private Hashtable<String, SpringBeanElement> serviceMap;
@@ -78,11 +78,11 @@ public class SpringImplementation extends ImplementationImpl implements Implemen
return;
}
- public void setResource(List<URL> resource) {
+ public void setResource(URL resource) {
this.resource = resource;
}
- public List<URL> getResource() {
+ public URL getResource() {
return resource;
}
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java
index 3b73ba00c1..54d42937db 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java
@@ -90,19 +90,22 @@ public class SpringXMLComponentTypeLoader {
private AssemblyFactory assemblyFactory;
private JavaInterfaceFactory javaFactory;
private PolicyFactory policyFactory;
+ private boolean isMultipleContextSupported;
private SpringBeanIntrospector beanIntrospector;
public SpringXMLComponentTypeLoader(ModelFactoryExtensionPoint factories,
AssemblyFactory assemblyFactory,
JavaInterfaceFactory javaFactory,
- PolicyFactory policyFactory) {
+ PolicyFactory policyFactory,
+ boolean multipleContextSupport) {
super();
this.assemblyFactory = assemblyFactory;
this.javaFactory = javaFactory;
this.policyFactory = policyFactory;
this.contributionFactory = factories.getFactory(ContributionFactory.class);
this.xmlInputFactory = factories.getFactory(XMLInputFactory.class);
+ this.isMultipleContextSupported = multipleContextSupport;
}
protected Class<SpringImplementation> getImplementationClass() {
@@ -156,25 +159,23 @@ public class SpringXMLComponentTypeLoader {
List<SpringSCAPropertyElement> scaproperties = new ArrayList<SpringSCAPropertyElement>();
URL resource;
- List<URL> contextResources = new ArrayList<URL>();
+
String contextPath = implementation.getLocation();
try {
resource = resolveLocation(resolver, contextPath);
- contextResources = getApplicationContextResource(resource);
+ resource = getApplicationContextResource(resource);
implementation.setClassLoader(new ContextClassLoader(resolver));
- implementation.setResource(contextResources);
+ implementation.setResource(resource);
// The URI is used to uniquely identify the Implementation
implementation.setURI(resource.toString());
+ reader = xmlInputFactory.createXMLStreamReader(resource.openStream());
+
+ // System.out.println("Spring TypeLoader - starting to read context file");
+ readContextDefinition(resolver, reader, contextPath, beans, services, references, scaproperties);
- for (URL contextResource : contextResources) {
- reader = xmlInputFactory.createXMLStreamReader(contextResource.openStream());
- // System.out.println("Spring TypeLoader - starting to read context file");
- readContextDefinition(resolver, reader, contextPath, beans, services, references, scaproperties);
-
- reader.close();
- }
+ reader.close();
} catch (IOException e) {
throw new ContributionReadException(e);
@@ -218,7 +219,7 @@ public class SpringXMLComponentTypeLoader {
private XMLStreamReader getApplicationContextReader(ModelResolver resolver, String location) throws ContributionReadException {
try {
- URL resource = getApplicationContextResource(resolveLocation(resolver, location)).get(0);
+ URL resource = getApplicationContextResource(resolveLocation(resolver, location));
XMLStreamReader reader =
xmlInputFactory.createXMLStreamReader(resource.openStream());
return reader;
@@ -341,6 +342,13 @@ public class SpringXMLComponentTypeLoader {
if (reader.getAttributeValue(null, "value") != null) {
String value = reader.getAttributeValue(null, "value");
constructorArg.addValue(value);
+ if ((isMultipleContextSupported) && (value.indexOf(".xml") != -1)) {
+ if (bean.getClassName().indexOf(".ClassPathXmlApplicationContext") != -1) {
+ XMLStreamReader creader = getApplicationContextReader(resolver, value);
+ // Read the context definition for the constructor-arg resources
+ readContextDefinition(resolver, creader, contextPath, beans, services, references, scaproperties);
+ }
+ }
}
bean.addCustructorArgs(constructorArg);
} else if (SpringImplementationConstants.REF_ELEMENT.equals(qname)) {
@@ -352,8 +360,17 @@ public class SpringXMLComponentTypeLoader {
} else if (SpringImplementationConstants.VALUE_ELEMENT.equals(qname)) {
String value = reader.getElementText();
// Check if the parent element is a constructor-arg
- if (constructorArg != null)
+ if (constructorArg != null) {
constructorArg.addValue(value);
+ // Identify the XML resource specified for the constructor-arg element
+ if ((isMultipleContextSupported) && (value.indexOf(".xml") != -1)) {
+ if (bean.getClassName().indexOf(".ClassPathXmlApplicationContext") != -1) {
+ XMLStreamReader creader = getApplicationContextReader(resolver, value);
+ // Read the context definition for the constructor-arg resources
+ readContextDefinition(resolver, creader, contextPath, beans, services, references, scaproperties);
+ }
+ }
+ }
} // end if
break;
case END_ELEMENT:
@@ -555,9 +572,9 @@ public class SpringXMLComponentTypeLoader {
Class<?> interfaze = resolveClass(resolver, paramType);
// Create a component type reference/property if the constructor-arg element has a
// type attribute OR index attribute declared...
- if ((conArgElement.getType() != null && paramType.equals(conArgElement.getType())) ||
+ if ((conArgElement.getType() != null && paramType.equals(conArgElement.getType())) ||
(conArgElement.getIndex() != -1 && (conArgElement.getIndex() == parameter.getIndex())))
- {
+ {
if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Reference")) {
Reference theReference = createReference(interfaze, conArgElement.getRef());
componentType.getReferences().add(theReference);
@@ -653,19 +670,19 @@ public class SpringXMLComponentTypeLoader {
* @param locationAttr - the location attribute from the <implementation.spring../> element
* @param cl - the ClassLoader for the Spring implementation
*/
- protected List<URL> getApplicationContextResource(URL url)
+ protected URL getApplicationContextResource(URL url)
throws ContributionReadException {
File manifestFile = null;
File appXmlFile;
File locationFile = null;
- List<URL> appCtxResources = new ArrayList<URL>();
if (url != null) {
String path = url.getPath();
locationFile = new File(path);
} else {
- throw new ContributionReadException("SpringXMLComponentTypeLoader getApplicationContextResource: "
- + "unable to find resource file " + url);
+ throw new ContributionReadException(
+ "SpringXMLLoader getApplicationContextResource: " + "unable to find resource file "
+ + url);
}
if (locationFile.isDirectory()) {
@@ -675,26 +692,21 @@ public class SpringXMLComponentTypeLoader {
Manifest mf = new Manifest(new FileInputStream(manifestFile));
Attributes mainAttrs = mf.getMainAttributes();
String appCtxPath = mainAttrs.getValue("Spring-Context");
- if (appCtxPath != null) {
- String[] cxtPaths = appCtxPath.split(";");
- for (String path : cxtPaths) {
- appXmlFile = new File(locationFile, path);
- if (appXmlFile.exists()) {
- appCtxResources.add(appXmlFile.toURI().toURL());
- }
- }
- return appCtxResources;
+ if (appCtxPath != null) {
+ appXmlFile = new File(locationFile, appCtxPath);
+ if (appXmlFile.exists()) {
+ return appXmlFile.toURL();
+ }
}
}
// no manifest-specified Spring context, use default
appXmlFile = new File(locationFile, "META-INF" + File.separator + "spring"
+ File.separator + SpringImplementationConstants.APPLICATION_CONTEXT);
if (appXmlFile.exists()) {
- appCtxResources.add(appXmlFile.toURI().toURL());
- return appCtxResources;
+ return appXmlFile.toURL();
}
} catch (IOException e) {
- throw new ContributionReadException("Error reading manifest " + manifestFile);
+ throw new ContributionReadException("Error reading manifest inside the folder: ", e);
}
} else {
if (locationFile.isFile() && locationFile.getName().endsWith(".jar")) {
@@ -706,22 +718,18 @@ public class SpringXMLComponentTypeLoader {
Attributes mainAttrs = mf.getMainAttributes();
String appCtxPath = mainAttrs.getValue("Spring-Context");
if (appCtxPath != null) {
- String[] cxtPaths = appCtxPath.split(";");
- for (String path : cxtPaths) {
- je = jf.getJarEntry(path);
- if (je != null) {
- appCtxResources.add(new URL("jar:" + locationFile.toURI().toURL() + "!/" + appCtxPath));
- }
- }
- return appCtxResources;
+ je = jf.getJarEntry(appCtxPath);
+ if (je != null) {
+ // TODO return a Spring specific Resource type for jars
+ return new URL("jar:" + locationFile.toURI().toURL() + "!/" + appCtxPath);
+ }
}
}
// Look for the default applicaiton-context.xml file, when MANIFEST.MF is absent.
je = jf.getJarEntry("META-INF" + "/" + "spring" + "/" + SpringImplementationConstants.APPLICATION_CONTEXT);
if (je != null) {
- appCtxResources.add(new URL("jar:" + locationFile.toURI().toURL() + "!/" +
- "META-INF" + "/" + "spring" + "/" + SpringImplementationConstants.APPLICATION_CONTEXT));
- return appCtxResources;
+ return new URL("jar:" + locationFile.toURI().toURL() + "!/" +
+ "META-INF" + "/" + "spring" + "/" + SpringImplementationConstants.APPLICATION_CONTEXT);
}
} catch (IOException e) {
// TODO: create a more appropriate exception type
@@ -731,14 +739,13 @@ public class SpringXMLComponentTypeLoader {
}
else {
if (locationFile.getName().endsWith(".xml")) {
- appCtxResources.add(url);
- return appCtxResources;
+ return url;
}
else {
// Deal with the directory inside a jar file, in case the contribution itself is a JAR file.
try {
if (locationFile.getPath().indexOf(".jar") > 0) {
- String jarPath = url.getPath().substring(6, url.getPath().indexOf("!"));
+ String jarPath = url.getPath().substring(5, url.getPath().indexOf("!"));
JarFile jf = new JarFile(jarPath);
JarEntry je = jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/")+2)
+ "/" + "META-INF" + "/" + "MANIFEST.MF");
@@ -747,34 +754,29 @@ public class SpringXMLComponentTypeLoader {
Attributes mainAttrs = mf.getMainAttributes();
String appCtxPath = mainAttrs.getValue("Spring-Context");
if (appCtxPath != null) {
- String[] cxtPaths = appCtxPath.split(";");
- for (String path : cxtPaths) {
- je = jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/")+2) + "/" + path);
- if (je != null) {
- appCtxResources.add(new URL("jar:" + url.getPath() + "/" + path));
- return appCtxResources;
- }
- }
+ je = jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/")+2) + "/" + appCtxPath);
+ if (je != null) {
+ return new URL("jar:" + url.getPath() + "/" + appCtxPath);
+ }
}
}
// Look for the default applicaiton-context.xml file, when MANIFEST.MF is absent.
je = jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/")+2) + "/" +
"META-INF" + "/" + "spring" + "/" + SpringImplementationConstants.APPLICATION_CONTEXT);
if (je != null) {
- appCtxResources.add(new URL("jar:" + url.getPath() + "/" +
- "META-INF" + "/" + "spring" + "/" + SpringImplementationConstants.APPLICATION_CONTEXT));
- return appCtxResources;
+ return new URL("jar:" + url.getPath() + "/" +
+ "META-INF" + "/" + "spring" + "/" + SpringImplementationConstants.APPLICATION_CONTEXT);
}
}
} catch (IOException e) {
- throw new ContributionReadException("Error reading manifest " + manifestFile);
+ throw new ContributionReadException("Error reading manifest inside the jar folder: ", e);
}
}
}
}
- throw new ContributionReadException("SpringXMLComponentTypeLoader getApplicationContextResource: "
- + "unable to read resource file " + url);
+ throw new ContributionReadException("SpringXMLLoader getApplicationContextResource: "
+ + "META-INF/spring/" + SpringImplementationConstants.APPLICATION_CONTEXT + " not found");
} // end method getApplicationContextResource
/**
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ConfigurationPropertiesExtensionPoint.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ConfigurationPropertiesExtensionPoint.java
index 0464355565..4fdcb52241 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ConfigurationPropertiesExtensionPoint.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ConfigurationPropertiesExtensionPoint.java
@@ -4,6 +4,8 @@ public interface ConfigurationPropertiesExtensionPoint {
boolean isAnnotationSupported();
+ boolean isMultipleContextSupported();
+
String getSupportedVersion();
}
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/DefaultConfigurationPropertiesExtensionPoint.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/DefaultConfigurationPropertiesExtensionPoint.java
index a0e7186eab..94b8e0eb36 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/DefaultConfigurationPropertiesExtensionPoint.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/DefaultConfigurationPropertiesExtensionPoint.java
@@ -8,11 +8,17 @@ public class DefaultConfigurationPropertiesExtensionPoint implements Configurati
}
// By default SCA annotations for implementation.spring
- // will be supproted.
+ // will be supproted for Tuscany.
public boolean isAnnotationSupported() {
return true;
}
+ // By default multiple application context implementation.spring
+ // will be supproted for Tuscany.
+ public boolean isMultipleContextSupported() {
+ return true;
+ }
+
// By defauly all the Spring version are supported for
// Tuscany.
public String getSupportedVersion() {
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java
index 290bbff171..818bc4e102 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java
@@ -22,7 +22,7 @@ package org.apache.tuscany.sca.implementation.spring.invocation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.List;
+import java.net.URL;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
@@ -47,9 +47,10 @@ public class SpringContextStub {
ProxyFactory proxyService,
JavaPropertyValueObjectFactory propertyValueObjectFactory,
boolean annotationSupport,
- String versionSupported) {
+ String versionSupported,
+ boolean multipleContextSupport) {
- initTie(component, implementation, propertyValueObjectFactory, annotationSupport, versionSupported);
+ initTie(component, implementation, propertyValueObjectFactory, annotationSupport, versionSupported, multipleContextSupport);
}
@@ -57,7 +58,8 @@ public class SpringContextStub {
SpringImplementation implementation,
JavaPropertyValueObjectFactory propertyValueObjectFactory,
boolean annotationSupport,
- String versionSupported) {
+ String versionSupported,
+ boolean multipleContextSupport) {
// TODO: what class loader to use?
ClassLoader cl = Thread.currentThread().getContextClassLoader();
@@ -69,8 +71,8 @@ public class SpringContextStub {
Object stub = stubConstructor.newInstance(new SpringImplementationTie(implementation, component, propertyValueObjectFactory));
Class<?> tieClass = Class.forName("org.apache.tuscany.sca.implementation.spring.runtime.context.SpringContextTie", true, cl);
- Constructor<?> tieConstructor = tieClass.getConstructor(new Class<?>[]{stubClass, List.class, boolean.class, String.class});
- this.tie = tieConstructor.newInstance(stub, implementation.getResource(), annotationSupport, versionSupported);
+ Constructor<?> tieConstructor = tieClass.getConstructor(new Class<?>[]{stubClass, URL.class, boolean.class, String.class, boolean.class});
+ this.tie = tieConstructor.newInstance(stub, implementation.getResource(), annotationSupport, versionSupported, multipleContextSupport);
this.startMethod = tieClass.getMethod("start");
this.closeMethod = tieClass.getMethod("close");
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java
index 1fc01b2627..105bb4a553 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java
@@ -52,13 +52,14 @@ public class SpringImplementationProvider implements ImplementationProvider {
ProxyFactory proxyService,
JavaPropertyValueObjectFactory propertyValueObjectFactory,
boolean annotationSupport,
- String versionSupported) {
+ String versionSupported,
+ boolean multipleContextSupport) {
super();
this.implementation = implementation;
this.component = component;
this.propertyValueObjectFactory = propertyValueObjectFactory;
- springContext = new SpringContextStub(component, implementation, proxyService, propertyValueObjectFactory, annotationSupport, versionSupported);
+ springContext = new SpringContextStub(component, implementation, proxyService, propertyValueObjectFactory, annotationSupport, versionSupported, multipleContextSupport);
} // end constructor
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java
index 4796aa0de9..e0d31203bc 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java
@@ -41,6 +41,7 @@ public class SpringImplementationProviderFactory implements ImplementationProvid
private ConfigurationPropertiesExtensionPoint configProperties;
private boolean annotationSupport;
private String versionSupported;
+ private boolean multipleContextSupport;
/**
* Simple constructor
@@ -58,6 +59,7 @@ public class SpringImplementationProviderFactory implements ImplementationProvid
}
annotationSupport = configProperties.isAnnotationSupported();
versionSupported = configProperties.getSupportedVersion();
+ multipleContextSupport = configProperties.isMultipleContextSupported();
// TODO: could the runtime have a default PropertyValueObjectFactory?
propertyFactory = new JavaPropertyValueObjectFactory(new MediatorImpl(extensionPoints));
@@ -77,7 +79,8 @@ public class SpringImplementationProviderFactory implements ImplementationProvid
proxyFactory,
propertyFactory,
annotationSupport,
- versionSupported);
+ versionSupported,
+ multipleContextSupport);
}
/**
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java
index 1d941e2a4f..29dc0a38a1 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java
@@ -39,11 +39,13 @@ import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
import org.apache.tuscany.sca.implementation.spring.SpringImplementation;
import org.apache.tuscany.sca.implementation.spring.introspect.SpringXMLComponentTypeLoader;
+import org.apache.tuscany.sca.implementation.spring.invocation.ConfigurationPropertiesExtensionPoint;
+import org.apache.tuscany.sca.implementation.spring.invocation.DefaultConfigurationPropertiesExtensionPoint;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
-import org.apache.tuscany.sca.monitor.impl.ProblemImpl;
+import org.apache.tuscany.sca.monitor.impl.ProblemImpl;
import org.apache.tuscany.sca.policy.PolicyFactory;
/**
@@ -63,9 +65,11 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri
private JavaInterfaceFactory javaFactory;
private PolicyFactory policyFactory;
private PolicyAttachPointProcessor policyProcessor;
+ private ConfigurationPropertiesExtensionPoint configProperties;
private Monitor monitor;
-
+
private ModelFactoryExtensionPoint factories;
+ private boolean multipleContextSupport;
public SpringImplementationProcessor(ExtensionPointRegistry extensionPoints, Monitor monitor) {
this.factories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
@@ -73,6 +77,12 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri
this.javaFactory = factories.getFactory(JavaInterfaceFactory.class);
this.policyFactory = factories.getFactory(PolicyFactory.class);
this.policyProcessor = new PolicyAttachPointProcessor(policyFactory);
+
+ this.configProperties = extensionPoints.getExtensionPoint(ConfigurationPropertiesExtensionPoint.class);
+ if (configProperties == null) {
+ configProperties = new DefaultConfigurationPropertiesExtensionPoint();
+ }
+ this.multipleContextSupport = configProperties.isMultipleContextSupported();
this.monitor = monitor;
}
@@ -197,7 +207,7 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri
/* Load the Spring component type by reading the Spring application context */
SpringXMLComponentTypeLoader springLoader =
- new SpringXMLComponentTypeLoader(factories, assemblyFactory, javaFactory, policyFactory);
+ new SpringXMLComponentTypeLoader(factories, assemblyFactory, javaFactory, policyFactory, multipleContextSupport);
try {
// Load the Spring Implementation information from its application context file...
springLoader.load(springImplementation, resolver);