diff options
author | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-22 12:08:32 +0000 |
---|---|---|
committer | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-22 12:08:32 +0000 |
commit | 695099482aa984eeb4f499f9de570328f1487b9d (patch) | |
tree | c52be71fcdc1d62ab70a920ccb4f6fefe7a10881 /java/sca/modules/implementation-spring-sca/src | |
parent | 17437a5fab2eae345e1b9ede33d95b97417bcdfa (diff) |
Fixes for spring module classloader changes ref: TUSCANY-3069 in 1.x
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@796684 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-spring-sca/src')
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 |