geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r428844 - in /geronimo/xbean/trunk: xbean-kernel/src/main/java/org/apache/xbean/kernel/ xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ xbean-kernel/src/test/java/org/apache/xbean/kernel/ xbean-kernel/src/test/java/org/apache/x...
Date Fri, 04 Aug 2006 18:49:47 GMT
Author: gnodet
Date: Fri Aug  4 11:49:46 2006
New Revision: 428844

URL: http://svn.apache.org/viewvc?rev=428844&view=rev
Log:
XBEAN-29: getClassLoaderFor used on spring based configuration with <classpath> does
not return the custom classloader

Modified:
    geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/Kernel.java
    geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/ServiceFactory.java
    geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/StaticServiceFactory.java
    geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManager.java
    geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerFactory.java
    geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerRegistry.java
    geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/StandardKernel.java
    geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/KernelMonitorBroadcasterTest.java
    geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerRegistryTest.java
    geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerTest.java
    geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/StandardKernelTest.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/deployer/FileDeployer.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/main/KernelMain.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfiguration.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfigurationServiceFactory.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/loader/SpringLoader.java

Modified: geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/Kernel.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/Kernel.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/Kernel.java (original)
+++ geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/Kernel.java Fri
Aug  4 11:49:46 2006
@@ -71,11 +71,10 @@
      *
      * @param serviceName the unique name of the service in the kernel
      * @param serviceFactory the factory used to create the service
-     * @param classLoader the class loader to use for this service
      * @throws ServiceAlreadyExistsException if service is already registered with the specified
name
      * @throws ServiceRegistrationException if the service is not restartable and an error
occured while starting the service
      */
-    void registerService(ServiceName serviceName, ServiceFactory serviceFactory, ClassLoader
classLoader) throws ServiceAlreadyExistsException, ServiceRegistrationException;
+    void registerService(ServiceName serviceName, ServiceFactory serviceFactory) throws ServiceAlreadyExistsException,
ServiceRegistrationException;
 
     /**
      * Unregisters a service from this kernel.  The kernel will attempt to stop the service
using the

Modified: geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/ServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/ServiceFactory.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/ServiceFactory.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/ServiceFactory.java
Fri Aug  4 11:49:46 2006
@@ -130,4 +130,11 @@
      * @param serviceContext the context information for the service
      */
     void destroyService(ServiceContext serviceContext);
+    
+    /**
+     * Gets the class loader associated with this service.
+     *
+     * @return the class loader associated with the service
+     */
+    ClassLoader getClassLoader();
 }

Modified: geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/StaticServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/StaticServiceFactory.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/StaticServiceFactory.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/StaticServiceFactory.java
Fri Aug  4 11:49:46 2006
@@ -28,6 +28,7 @@
  */
 public class StaticServiceFactory extends AbstractServiceFactory {
     private final Object service;
+    private final ClassLoader classLoader;
 
     /**
      * Creates a non-restartable service factory which will simply returns the specified
service from the createService
@@ -39,6 +40,26 @@
     public StaticServiceFactory(Object service) throws NullPointerException {
         if (service == null) throw new NullPointerException("service is null");
         this.service = service;
+        ClassLoader cl = service.getClass().getClassLoader();
+        if (cl == null) {
+            cl = ClassLoader.getSystemClassLoader();
+        }
+        this.classLoader = cl;
+    }
+
+    /**
+     * Creates a non-restartable service factory which will simply returns the specified
service from the createService
+     * method.
+     *
+     * @param service the static to which this factory "creates"
+     * @param classLoader the classLoader used to load the service class
+     * @throws NullPointerException if service or classLoader is null
+     */
+    public StaticServiceFactory(Object service, ClassLoader classLoader) throws NullPointerException
{
+        if (service == null) throw new NullPointerException("service is null");
+        if (classLoader == null) throw new NullPointerException("classLoader is null");
+        this.service = service;
+        this.classLoader = classLoader;
     }
 
     public Class[] getTypes() {
@@ -76,4 +97,12 @@
      */
     public void destroyService(ServiceContext serviceContext) {
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ClassLoader getClassLoader() {
+        return classLoader;
+    }
+    
 }

Modified: geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManager.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManager.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManager.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManager.java
Fri Aug  4 11:49:46 2006
@@ -31,7 +31,6 @@
 import org.apache.xbean.kernel.Kernel;
 import org.apache.xbean.kernel.KernelOperationInterruptedException;
 import org.apache.xbean.kernel.KernelOperationTimoutException;
-import org.apache.xbean.kernel.ServiceCondition;
 import org.apache.xbean.kernel.ServiceEvent;
 import org.apache.xbean.kernel.ServiceFactory;
 import org.apache.xbean.kernel.ServiceMonitor;
@@ -82,11 +81,6 @@
     private final Set serviceTypes;
 
     /**
-     * The class loader for this service.
-     */
-    private final ClassLoader classLoader;
-
-    /**
      * The monitor to which we fire service events.  The ServiceManager requires an asynchronous
monitor becuse events are
      * fired from within the lock.  This helps to reduce complexity but will cause more services
to sit in the
      * {@link ServiceState#STARTING} and {@link ServiceState#STOPPING} states since events
are propagated in a separate
@@ -162,7 +156,6 @@
      * @param serviceId the unique id of this service in the kernel
      * @param serviceName the unique name of this service in the kernel
      * @param serviceFactory the factory used to create and destroy the service instance
-     * @param classLoader the class loader for this service
      * @param serviceMonitor the monitor of service events
      * @param timeoutDuration the maximum duration to wait for a lock
      * @param timeoutUnits the unit of measure for the timeoutDuration
@@ -171,7 +164,6 @@
             long serviceId,
             ServiceName serviceName,
             ServiceFactory serviceFactory,
-            ClassLoader classLoader,
             ServiceMonitor serviceMonitor,
             long timeoutDuration,
             TimeUnit timeoutUnits) {
@@ -180,11 +172,10 @@
         this.serviceId = serviceId;
         this.serviceName = serviceName;
         this.serviceFactory = serviceFactory;
-        this.classLoader = classLoader;
         this.serviceMonitor = serviceMonitor;
         this.timeoutDuration = timeoutDuration;
         this.timeoutUnits = timeoutUnits;
-        standardServiceContext = new StandardServiceContext(kernel, serviceName, classLoader);
+        standardServiceContext = new StandardServiceContext(kernel, serviceName, serviceFactory.getClassLoader());
         serviceTypes = Collections.unmodifiableSet(new LinkedHashSet(Arrays.asList(serviceFactory.getTypes())));
     }
 
@@ -225,7 +216,7 @@
             // method is called.  This should cause the stop logic of a stop condition to
fire.
             lock("initialize");
             try {
-                stopCondition = new NonRestartableStopCondition(kernel, serviceName, classLoader,
lock, serviceFactory);
+                stopCondition = new NonRestartableStopCondition(kernel, serviceName, serviceFactory.getClassLoader(),
lock, serviceFactory);
             } finally {
                 unlock();
             }
@@ -325,7 +316,7 @@
      * @see Kernel#getClassLoaderFor(ServiceName)
      */
     public ClassLoader getClassLoader() {
-        return classLoader;
+        return serviceFactory.getClassLoader();
     }
 
     /**
@@ -405,7 +396,7 @@
                         serviceMonitor.serviceStarting(createServiceEvent());
 
                         // initialize the start conditions
-                        startCondition = new AggregateCondition(kernel, serviceName, classLoader,
lock, serviceFactory.getStartConditions());
+                        startCondition = new AggregateCondition(kernel, serviceName, serviceFactory.getClassLoader(),
lock, serviceFactory.getStartConditions());
                         startCondition.initialize();
                     }
 
@@ -572,7 +563,7 @@
                         state = ServiceState.STOPPING;
 
                         // initialize all of the stop conditions
-                        stopCondition = new AggregateCondition(kernel, serviceName, classLoader,
lock, serviceFactory.getStopConditions());
+                        stopCondition = new AggregateCondition(kernel, serviceName, serviceFactory.getClassLoader(),
lock, serviceFactory.getStopConditions());
                         stopCondition.initialize();
                     }
 
@@ -694,15 +685,15 @@
     }
 
     private ServiceEvent createServiceEvent() {
-        return new ServiceEvent(eventId.getAndIncrement(), kernel, serviceName, serviceFactory,
classLoader, service, null, null);
+        return new ServiceEvent(eventId.getAndIncrement(), kernel, serviceName, serviceFactory,
serviceFactory.getClassLoader(), service, null, null);
     }
 
     private ServiceEvent createWaitingServiceEvent(Set unsatisfiedConditions) {
-        return new ServiceEvent(eventId.getAndIncrement(), kernel, serviceName, serviceFactory,
classLoader, service, null, unsatisfiedConditions);
+        return new ServiceEvent(eventId.getAndIncrement(), kernel, serviceName, serviceFactory,
serviceFactory.getClassLoader(), service, null, unsatisfiedConditions);
     }
 
     private ServiceEvent createErrorServiceEvent(Throwable cause) {
-        return new ServiceEvent(eventId.getAndIncrement(), kernel, serviceName, serviceFactory,
classLoader, null, cause, null);
+        return new ServiceEvent(eventId.getAndIncrement(), kernel, serviceName, serviceFactory,
serviceFactory.getClassLoader(), null, cause, null);
     }
 
     public int hashCode() {

Modified: geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerFactory.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerFactory.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerFactory.java
Fri Aug  4 11:49:46 2006
@@ -81,12 +81,11 @@
      * @param classLoader the classloader for the service
      * @return a new service manager
      */
-    public ServiceManager createServiceManager(long serviceId, ServiceName serviceName, ServiceFactory
serviceFactory, ClassLoader classLoader) {
+    public ServiceManager createServiceManager(long serviceId, ServiceName serviceName, ServiceFactory
serviceFactory) {
         return new ServiceManager(kernel,
                 serviceId,
                 serviceName,
                 serviceFactory,
-                classLoader,
                 new AsyncServiceMonitor(serviceMonitor, serviceExecutor),
                 timeoutDuration,
                 timeoutUnits);

Modified: geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerRegistry.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerRegistry.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerRegistry.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/ServiceManagerRegistry.java
Fri Aug  4 11:49:46 2006
@@ -338,14 +338,12 @@
      *
      * @param serviceName the unique name of the service
      * @param serviceFactory the factory used to create the service
-     * @param classLoader the class loader to use for this service
      * @throws ServiceAlreadyExistsException if service is already registered with the specified
name
      * @throws ServiceRegistrationException if the service is not restartable and an error
occured while starting the service
      */
-    public void registerService(ServiceName serviceName, ServiceFactory serviceFactory, ClassLoader
classLoader) throws ServiceAlreadyExistsException, ServiceRegistrationException {
+    public void registerService(ServiceName serviceName, ServiceFactory serviceFactory) throws
ServiceAlreadyExistsException, ServiceRegistrationException {
         if (serviceName == null) throw new NullPointerException("serviceName is null");
         if (serviceFactory == null) throw new NullPointerException("serviceFactory is null");
-        if (classLoader == null) throw new NullPointerException("classLoader is null");
 
         if (!serviceFactory.isEnabled()) {
             throw new ServiceRegistrationException(serviceName,
@@ -386,8 +384,7 @@
                     existingRegistration = null;
                     ServiceManager serviceManager = serviceManagerFactory.createServiceManager(serviceId.getAndIncrement(),
                             serviceName,
-                            serviceFactory,
-                            classLoader);
+                            serviceFactory);
                     registrationTask = RegistryFutureTask.createRegisterTask(serviceManager);
                     serviceManagers.put(serviceName, registrationTask);
                     addTypeIndex(serviceManager, registrationTask);

Modified: geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/StandardKernel.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/StandardKernel.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/StandardKernel.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/main/java/org/apache/xbean/kernel/standard/StandardKernel.java
Fri Aug  4 11:49:46 2006
@@ -210,15 +210,14 @@
     /**
      * {@inheritDoc}
      */
-    public void registerService(ServiceName serviceName, ServiceFactory serviceFactory, ClassLoader
classLoader) throws ServiceAlreadyExistsException, ServiceRegistrationException {
+    public void registerService(ServiceName serviceName, ServiceFactory serviceFactory) throws
ServiceAlreadyExistsException, ServiceRegistrationException {
         if (serviceName == null) throw new NullPointerException("serviceName is null");
         if (serviceFactory == null) throw new NullPointerException("serviceFactory is null");
-        if (classLoader == null) throw new NullPointerException("classLoader is null");
         if (!isRunning()) {
             throw new ServiceRegistrationException(serviceName, new IllegalStateException("Kernel
is destroyed"));
         }
 
-        serviceManagerRegistry.registerService(serviceName, serviceFactory, classLoader);
+        serviceManagerRegistry.registerService(serviceName, serviceFactory);
     }
 
     /**

Modified: geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/KernelMonitorBroadcasterTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/KernelMonitorBroadcasterTest.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/KernelMonitorBroadcasterTest.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/KernelMonitorBroadcasterTest.java
Fri Aug  4 11:49:46 2006
@@ -32,7 +32,7 @@
     private static final ServiceEvent SERVICE_EVENT = new ServiceEvent(0,
             new StandardKernel("test"),
             new StringServiceName("service-name"),
-            new StaticServiceFactory(new Object()),
+            new StaticServiceFactory(new Object(), KernelMonitorBroadcasterTest.class.getClassLoader()),
             ClassLoader.getSystemClassLoader(), 
             null,
             null,
@@ -172,4 +172,4 @@
             assertSame(THROWABLE, throwable);
         }
     }
-}
\ No newline at end of file
+}

Modified: geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerRegistryTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerRegistryTest.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerRegistryTest.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerRegistryTest.java
Fri Aug  4 11:49:46 2006
@@ -146,7 +146,7 @@
     public void testDoubleRegister() throws Exception {
         register();
         try {
-            registry.registerService(SERVICE_NAME, SERVICE_FACTORY, CLASS_LOADER);
+            registry.registerService(SERVICE_NAME, SERVICE_FACTORY);
             fail("should have thrown an exception");
         } catch (ServiceAlreadyExistsException expected) {
             // expected
@@ -592,7 +592,7 @@
         serviceManager.setInitializeException(throwable);
         serviceManagerFactory.addServiceManager(serviceManager);
         try {
-            registry.registerService(SERVICE_NAME, SERVICE_FACTORY, CLASS_LOADER);
+            registry.registerService(SERVICE_NAME, SERVICE_FACTORY);
             assertNull(throwable);
         } catch (ServiceRegistrationException expected) {
             // expected
@@ -722,10 +722,9 @@
             super(null, null, null, 0, null);
         }
 
-        public ServiceManager createServiceManager(long serviceId, ServiceName serviceName,
ServiceFactory serviceFactory, ClassLoader classLoader) {
+        public ServiceManager createServiceManager(long serviceId, ServiceName serviceName,
ServiceFactory serviceFactory) {
             assertEquals(SERVICE_NAME, serviceName);
             assertEquals(SERVICE_FACTORY, serviceFactory);
-            assertEquals(CLASS_LOADER, classLoader);
             synchronized (serviceManagers) {
                 return (ServiceManager) serviceManagers.removeFirst();
             }
@@ -756,7 +755,6 @@
                     0,
                     new StringServiceName("MockService"),
                     new StaticServiceFactory(new Object()),
-                    null,
                     new NullServiceMonitor(),
                     0,
                     null);

Modified: geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerTest.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerTest.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/ServiceManagerTest.java
Fri Aug  4 11:49:46 2006
@@ -67,7 +67,7 @@
     private final MockStartCondition startCondition = new MockStartCondition();
     private final MockStopCondition stopCondition = new MockStopCondition();
     private final MockServiceFactory serviceFactory = new MockServiceFactory();
-    private final ClassLoader classLoader = new URLClassLoader(new URL[0]);
+    private static final ClassLoader CLASSLOADER = new URLClassLoader(new URL[0]);
     private final MockServiceMonitor serviceMonitor = new MockServiceMonitor();
     private ServiceManager serviceManager;
 
@@ -77,7 +77,7 @@
     public void testInitialState() {
         assertSame(serviceName, serviceManager.getServiceName());
         assertSame(serviceFactory, serviceManager.getServiceFactory());
-        assertSame(classLoader, serviceManager.getClassLoader());
+        assertSame(CLASSLOADER, serviceManager.getClassLoader());
         assertEquals(0, serviceManager.getStartTime());
         assertNull(serviceManager.getService());
         assertSame(ServiceState.STOPPED, serviceManager.getState());
@@ -705,7 +705,7 @@
         assertSame(ServiceState.RUNNING, serviceManager.getState());
         assertSame(serviceName, serviceManager.getServiceName());
         assertSame(serviceFactory, serviceManager.getServiceFactory());
-        assertSame(classLoader, serviceManager.getClassLoader());
+        assertSame(CLASSLOADER, serviceManager.getClassLoader());
         assertTrue(serviceManager.getStartTime() > 0);
         assertNotNull(serviceManager.getService());
         assertNull(serviceMonitor.registered);
@@ -773,7 +773,7 @@
 
         assertSame(serviceName, serviceManager.getServiceName());
         assertSame(serviceFactory, serviceManager.getServiceFactory());
-        assertSame(classLoader, serviceManager.getClassLoader());
+        assertSame(CLASSLOADER, serviceManager.getClassLoader());
 
         if (serviceFactory.restartable) {
             assertSame(ServiceState.STOPPED, serviceManager.getState());
@@ -876,7 +876,7 @@
 
         assertSame(serviceName, serviceManager.getServiceName());
         assertSame(serviceFactory, serviceManager.getServiceFactory());
-        assertSame(classLoader, serviceManager.getClassLoader());
+        assertSame(CLASSLOADER, serviceManager.getClassLoader());
 
         // these events should never fire in response to start
         assertNull(serviceMonitor.registered);
@@ -1069,7 +1069,7 @@
 
         assertSame(serviceName, serviceManager.getServiceName());
         assertSame(serviceFactory, serviceManager.getServiceFactory());
-        assertSame(classLoader, serviceManager.getClassLoader());
+        assertSame(CLASSLOADER, serviceManager.getClassLoader());
 
         // these events should never fire in response to start
         assertNull(serviceMonitor.registered);
@@ -1254,7 +1254,7 @@
             assertSame(ServiceState.STOPPED, serviceManager.getState());
             assertSame(serviceName, serviceManager.getServiceName());
             assertSame(serviceFactory, serviceManager.getServiceFactory());
-            assertSame(classLoader, serviceManager.getClassLoader());
+            assertSame(CLASSLOADER, serviceManager.getClassLoader());
             assertEquals(0, serviceManager.getStartTime());
             assertNull(serviceManager.getService());
             // verify expected events fired
@@ -1272,7 +1272,7 @@
             assertSame(ServiceState.RUNNING, serviceManager.getState());
             assertSame(serviceName, serviceManager.getServiceName());
             assertSame(serviceFactory, serviceManager.getServiceFactory());
-            assertSame(classLoader, serviceManager.getClassLoader());
+            assertSame(CLASSLOADER, serviceManager.getClassLoader());
             assertTrue(serviceManager.getStartTime() > 0);
             assertNotNull(serviceManager.getService());
             assertNull(serviceMonitor.registered);
@@ -1356,7 +1356,6 @@
                 0,
                 serviceName,
                 serviceFactory,
-                classLoader,
                 serviceMonitor,
                 10,
                 TimeUnit.SECONDS);
@@ -1411,11 +1410,15 @@
             if (throwExceptionFromDestroy) throw destroyException;
             super.destroyService(serviceContext);
         }
+        
+        public ClassLoader getClassLoader() {
+            return CLASSLOADER;
+        }
 
         private void assertValidServiceContext(ServiceContext serviceContext) {
             assertSame(serviceName, serviceContext.getServiceName());
             assertSame(kernel, serviceContext.getKernel());
-            assertSame(classLoader, serviceContext.getClassLoader());
+            assertSame(CLASSLOADER, serviceContext.getClassLoader());
         }
 
     }
@@ -1501,7 +1504,7 @@
     private void assertValidServiceConditionContext(ServiceConditionContext context) {
         assertSame(serviceName, context.getServiceName());
         assertSame(kernel, context.getKernel());
-        assertSame(classLoader, context.getClassLoader());
+        assertSame(CLASSLOADER, context.getClassLoader());
     }
 
     private class MockServiceMonitor implements ServiceMonitor {
@@ -1582,7 +1585,7 @@
         private void assertValidEvent(ServiceEvent serviceEvent, boolean mustHaveService)
{
             assertSame(serviceName, serviceEvent.getServiceName());
             assertSame(kernel, serviceEvent.getKernel());
-            assertSame(classLoader, serviceEvent.getClassLoader());
+            assertSame(CLASSLOADER, serviceEvent.getClassLoader());
             assertSame(serviceFactory, serviceEvent.getServiceFactory());
             if (mustHaveService) {
                 assertSame(SERVICE, serviceEvent.getService());
@@ -1640,7 +1643,7 @@
             throw new UnsupportedOperationException();
         }
 
-        public void registerService(ServiceName serviceName, ServiceFactory serviceFactory,
ClassLoader classLoader) throws ServiceAlreadyExistsException, ServiceRegistrationException
{
+        public void registerService(ServiceName serviceName, ServiceFactory serviceFactory)
throws ServiceAlreadyExistsException, ServiceRegistrationException {
             throw new UnsupportedOperationException();
         }
 

Modified: geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/StandardKernelTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/StandardKernelTest.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/StandardKernelTest.java
(original)
+++ geronimo/xbean/trunk/xbean-kernel/src/test/java/org/apache/xbean/kernel/standard/StandardKernelTest.java
Fri Aug  4 11:49:46 2006
@@ -41,7 +41,7 @@
     private final StringServiceName serviceName = new StringServiceName("Service");
 //    private final StringServiceName ownedServiceName = new StringServiceName("OwnedService");
     private final MockServiceFactory serviceFactory = new MockServiceFactory();
-    private final ClassLoader classLoader = new URLClassLoader(new URL[0]);
+    private static final ClassLoader CLASSLOADER = new URLClassLoader(new URL[0]);
 
     /**
      * Tests the initial state of the kernel is as expected.
@@ -233,10 +233,10 @@
      * @throws Exception if a problem occurs
      */ 
     public void testSimpleLifecycle() throws Exception {
-        kernel.registerService(serviceName, serviceFactory, classLoader);
+        kernel.registerService(serviceName, serviceFactory);
         assertTrue(kernel.isRegistered(serviceName));
         assertSame(serviceFactory, kernel.getServiceFactory(serviceName));
-        assertSame(classLoader, kernel.getClassLoaderFor(serviceName));
+        assertSame(CLASSLOADER, kernel.getClassLoaderFor(serviceName));
         assertSame(ServiceState.STOPPED, kernel.getServiceState(serviceName));
         assertNull(kernel.getService(serviceName));
         assertEquals(0, kernel.getServiceStartTime(serviceName));
@@ -247,7 +247,7 @@
         private boolean restartable = true;
 
         private MockServiceFactory() throws NullPointerException {
-            super(SERVICE);
+            super(SERVICE, CLASSLOADER);
         }
 
         public boolean isRestartable() {

Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/deployer/FileDeployer.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/deployer/FileDeployer.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/deployer/FileDeployer.java
(original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/deployer/FileDeployer.java
Fri Aug  4 11:49:46 2006
@@ -29,7 +29,6 @@
 import org.apache.xbean.spring.context.SpringApplicationContext;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 import org.springframework.core.io.FileSystemResource;
@@ -46,7 +45,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Set;
 import java.util.StringTokenizer;
 
 /**
@@ -348,14 +346,7 @@
 
                 log.info("Registering spring services service: " + name + " from: " + file.getAbsolutePath()
+ " into the Kernel");
 
-                // TODO should we use the classLaoder we used to load the
-                // context
-                // or, if the XBean config file defined a new classloader,
-                // should we use the one
-                // from the ApplicationContext?
-                // classLoader = applicationContext.getClassLoader();
-
-                kernel.registerService(new StringServiceName(name), serviceFactory, classLoader);
+                kernel.registerService(new StringServiceName(name), serviceFactory);
             }
             finally {
                 Thread.currentThread().setContextClassLoader(oldClassLoader);

Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/main/KernelMain.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/main/KernelMain.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/main/KernelMain.java
(original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/main/KernelMain.java
Fri Aug  4 11:49:46 2006
@@ -155,7 +155,7 @@
 
                     try {
                         ServiceName serviceName = new StringServiceName(name);
-                        kernel.registerService(serviceName, new StaticServiceFactory(service),
classLoader);
+                        kernel.registerService(serviceName, new StaticServiceFactory(service,
classLoader));
                         kernel.startService(serviceName);
                     } catch (Exception e) {
                         throw new FatalStartupError("Unable to bind bootstrap service '"
+ name + "' into the kernel", e);

Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfiguration.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfiguration.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfiguration.java
(original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfiguration.java
Fri Aug  4 11:49:46 2006
@@ -59,6 +59,10 @@
 
         // read the configuration file from source
         applicationContext.refresh();
+        
+        // If the class loader was modified by an xml preprocessor,
+        // make sure we have the right one
+        classLoader = getClassLoader(applicationContext);
 
         try {
 
@@ -73,7 +77,7 @@
                 ServiceName serviceName = (ServiceName) entry.getValue();
 
                 Object bean = applicationContext.getBean(beanName);
-                StaticServiceFactory serviceFactory = new StaticServiceFactory(bean);
+                StaticServiceFactory serviceFactory = new StaticServiceFactory(bean, classLoader);
                 factories.put(serviceName, serviceFactory);
             }
             serviceFactories = Collections.unmodifiableMap(factories);
@@ -83,7 +87,7 @@
                 Map.Entry entry = (Map.Entry) iterator.next();
                 ServiceName serviceName = (ServiceName) entry.getKey();
                 StaticServiceFactory serviceFactory = (StaticServiceFactory) entry.getValue();
-                kernel.registerService(serviceName, serviceFactory, classLoader);
+                kernel.registerService(serviceName, serviceFactory);
             }
 
         } catch (ServiceAlreadyExistsException e) {
@@ -148,7 +152,7 @@
         return serviceNameIndex;
     }
 
-    private static ClassLoader getClassLoader(SpringApplicationContext applicationContext)
{
+    protected static ClassLoader getClassLoader(SpringApplicationContext applicationContext)
{
         ClassLoader classLoader = applicationContext.getClassLoader();
         if (classLoader == null) {
             classLoader = Thread.currentThread().getContextClassLoader();

Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfigurationServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfigurationServiceFactory.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfigurationServiceFactory.java
(original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/SpringConfigurationServiceFactory.java
Fri Aug  4 11:49:46 2006
@@ -130,6 +130,13 @@
         applicationContext.close();
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public ClassLoader getClassLoader() {
+        return SpringConfiguration.getClassLoader(applicationContext);
+    }
+    
     private static class ConfigurationStopCondition implements ServiceCondition {
         private final List ownedServiceConditions = new ArrayList();
 

Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/loader/SpringLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/loader/SpringLoader.java?rev=428844&r1=428843&r2=428844&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/loader/SpringLoader.java
(original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/loader/SpringLoader.java
Fri Aug  4 11:49:46 2006
@@ -146,7 +146,7 @@
 
         ServiceName serviceName = new StringServiceName("configuration:" + location);
         ServiceFactory springConfigurationServiceFactory = new SpringConfigurationServiceFactory(applicationContext);
-        kernel.registerService(serviceName, springConfigurationServiceFactory, classLoader);
+        kernel.registerService(serviceName, springConfigurationServiceFactory);
         return serviceName;
     }
 }



Mime
View raw message