[jbosscache-commits] JBoss Cache SVN: r5396 - in core/trunk/src/main/java/org/jboss/cache: factories and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Mar 7 07:30:19 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-03-07 07:30:19 -0500 (Fri, 07 Mar 2008)
New Revision: 5396

Modified:
   core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
   core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
Log:
JBCACHE-1300 - Standardize mechanism for setting defaultClassLoader

Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java	2008-03-07 09:21:32 UTC (rev 5395)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java	2008-03-07 12:30:19 UTC (rev 5396)
@@ -33,6 +33,8 @@
  */
 public class DefaultCacheFactory<K, V> extends ComponentFactory implements CacheFactory<K, V>
 {
+   private ClassLoader defaultClassLoader;
+
    /**
     * Note - this method used to return a singleton instance, and since 2.1.0 returns a new instance.  The method is
     * deprecated and you should use the no-arg constructor to create a new instance of this factory.
@@ -131,7 +133,7 @@
    {
       // injection bootstrap stuff
       componentRegistry = cache.getComponentRegistry();
-
+      componentRegistry.registerDefaultClassLoader(defaultClassLoader);
       this.configuration = configuration;
 
       // make sure we set the CacheImpl and CacheSPI instance in the component registry.
@@ -139,6 +141,16 @@
       componentRegistry.registerComponent(CacheSPI.class.getName(), spi, CacheSPI.class);
    }
 
+   /**
+    * Allows users to specify a default class loader to use for both the construction and running of the cache.
+    *
+    * @param loader class loader to use as a default.
+    */
+   public void setDefaultClassLoader(ClassLoader loader)
+   {
+      this.defaultClassLoader = loader;
+   }
+
    public Cache<K, V> createCache(InputStream is) throws ConfigurationException
    {
       XmlConfigurationParser parser = new XmlConfigurationParser();

Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java	2008-03-07 09:21:32 UTC (rev 5395)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java	2008-03-07 12:30:19 UTC (rev 5396)
@@ -91,11 +91,24 @@
    public ComponentRegistry(Configuration configuration)
    {
       // bootstrap.
-      registerComponent("deployerClassLoader", getClass().getClassLoader(), ClassLoader.class);
+      registerDefaultClassLoader(null);
       registerComponent(this, ComponentRegistry.class);
       registerComponent(configuration, Configuration.class);
    }
 
+   /**
+    * Registers the default class loader.  This method *must* be called before any other components are registered,
+    * typically called by bootstrap code.  Defensively, it is called in the constructor of ComponentRegistry with a null
+    * parameter.
+    *
+    * @param loader a class loader to use by default.  If this is null, the class loader used to load this instance of ComponentRegistry is used.
+    */
+   public void registerDefaultClassLoader(ClassLoader loader)
+   {
+      registerComponent("deployerClassLoader", loader == null ? getClass().getClassLoader() : loader, ClassLoader.class);
+   }
+
+
    public State getOverallState()
    {
       return overallState;




More information about the jbosscache-commits mailing list