summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-spring-sca/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules/implementation-spring-sca/src/main')
-rw-r--r--java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java81
-rw-r--r--java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java14
2 files changed, 52 insertions, 43 deletions
diff --git a/java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java b/java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
index 3c36b04ba8..18517755d5 100644
--- a/java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
+++ b/java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
@@ -77,54 +77,51 @@ public class SpringContextTie {
/**
* Include BeanPostProcessor to deal with SCA Annotations in Spring Bean
*/
-// private Object createApplicationContext(SCAParentApplicationContext scaParentContext) {
-
private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, URL resource) {
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();
- if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1 ||
- beanClassName.indexOf(".FileSystemXmlApplicationContext") != -1)
- {
- BeanDefinition beanDef = beanFactory.getBeanDefinition(bean);
- String[] listValues = 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)
- listValues = 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(next.getValue());
- values.append("~");
- }
- }
- listValues = (values.toString()).split("~");
- }
- }
-
- if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1) {
- appContext = new ClassPathXmlApplicationContext(listValues, false, scaParentContext);
- appContext.refresh(); // TODO why is this needed here now?
- includeAnnotationProcessors(appContext.getBeanFactory());
- return appContext;
- } else {
- appContext = new FileSystemXmlApplicationContext(listValues, false, scaParentContext);
- appContext.refresh(); // TODO why is this needed here now?
- includeAnnotationProcessors(appContext.getBeanFactory());
- return appContext;
+ String beanClassName = (beanFactory.getType(bean)).getName();
+ if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1 ||
+ beanClassName.indexOf(".FileSystemXmlApplicationContext") != -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("~");
+ }
+ }
+
+ if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1) {
+ appContext = new ClassPathXmlApplicationContext(configLocations, true, scaParentContext);
+ includeAnnotationProcessors(appContext.getBeanFactory());
+ return appContext;
+ } else {
+ appContext = new FileSystemXmlApplicationContext(configLocations, true, scaParentContext);
+ includeAnnotationProcessors(appContext.getBeanFactory());
+ return appContext;
+ }
+ }
}
// use the generic application context as default
@@ -165,4 +162,4 @@ public class SpringContextTie {
beanFactory.addBeanPostProcessor(constructorProcessor);
}
-}
+} \ No newline at end of file
diff --git a/java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java b/java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java
index abf9d55e86..af39869522 100644
--- a/java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java
+++ b/java/sca/modules/implementation-spring-sca/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java
@@ -39,6 +39,7 @@ public class SpringImplementationStub {
Method getComponentName;
Method getComponentTie;
Method getPropertyValueTie;
+ Method getClassLoader;
public SpringImplementationStub(Object tie) {
this.tie = tie;
@@ -49,6 +50,7 @@ public class SpringImplementationStub {
getComponentName = tieClass.getMethod("getComponentName");
getComponentTie = tieClass.getMethod("getComponentTie");
getPropertyValueTie = tieClass.getMethod("getPropertyValueTie");
+ getClassLoader = tieClass.getMethod("getClassLoader");
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -114,4 +116,14 @@ public class SpringImplementationStub {
throw new RuntimeException(e);
}
}
-}
+
+ public ClassLoader getClassLoader() {
+ try {
+
+ return (ClassLoader) getClassLoader.invoke(tie);
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+} \ No newline at end of file