Author: slaws
Date: Sat Jul  4 07:37:12 2009
New Revision: 791072

URL: http://svn.apache.org/viewvc?rev=791072&view=rev
Log:
TUSCANY-3128 - force the bean factory classloader to be the contribution 
classloader as it's reset by the application context on refresh. 

Modified:
    
tuscany/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java

Modified: 
tuscany/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java?rev=791072&r1=791071&r2=791072&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
 Sat Jul  4 07:37:12 2009
@@ -36,8 +36,10 @@
 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.context.support.AbstractApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.context.support.GenericApplicationContext;
@@ -57,6 +59,28 @@
     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 {
         this.implementation = implementation;
         this.isAnnotationSupported = annotationSupport;
@@ -134,8 +158,13 @@
         
         // use the generic application context as default 
         if (isAnnotationSupported)
+        {            
                includeAnnotationProcessors(beanFactory);
-        appContext = new GenericApplicationContext(beanFactory, 
scaParentContext);
+        }
+        
+        appContext = new LocalGenericApplicationContext(beanFactory, 
+                                                        scaParentContext,
+                                                        
implementation.getClassLoader());
         return appContext;
     }
 


Reply via email to