[jboss-cvs] JBossAS SVN: r88207 - projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 5 07:05:32 EDT 2009
Author: adrian at jboss.org
Date: 2009-05-05 07:05:32 -0400 (Tue, 05 May 2009)
New Revision: 88207
Modified:
projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
Log:
[JBCL-101] - Synch with head
Modified: projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java 2009-05-05 11:05:10 UTC (rev 88206)
+++ projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java 2009-05-05 11:05:32 UTC (rev 88207)
@@ -43,7 +43,7 @@
/**
* BaseClassLoaderDomain.<p>
- *
+ *
* This class hides some of the implementation details and allows
* package access to the protected methods.
*
@@ -57,31 +57,31 @@
/** The classloader system to which we belong */
private BaseClassLoaderSystem system;
-
+
/** The classloaders in the order they were registered */
private List<ClassLoaderInformation> classLoaders = new CopyOnWriteArrayList<ClassLoaderInformation>();
/** The classloader information by classloader */
private Map<ClassLoader, ClassLoaderInformation> infos = new ConcurrentHashMap<ClassLoader, ClassLoaderInformation>();
-
+
/** The classloaders by package name */
private Map<String, List<ClassLoaderInformation>> classLoadersByPackageName = new ConcurrentHashMap<String, List<ClassLoaderInformation>>();
-
+
/** The global class cache */
private Map<String, ClassCacheItem> globalClassCache = new ConcurrentHashMap<String, ClassCacheItem>();
-
+
/** The global class black list */
private Map<String, String> globalClassBlackList = new ConcurrentHashMap<String, String>();
-
+
/** The global resource cache */
private Map<String, URL> globalResourceCache = new ConcurrentHashMap<String, URL>();
-
+
/** The global resource black list */
private Map<String, String> globalResourceBlackList = new ConcurrentHashMap<String, String>();
-
+
/** Keep track of the added order */
private int order = 0;
-
+
/**
* Flush the internal caches
*/
@@ -115,7 +115,7 @@
{
return globalClassCache.size();
}
-
+
public Set<String> listClassBlackList()
{
return Collections.unmodifiableSet(globalClassBlackList.keySet());
@@ -141,17 +141,17 @@
/**
* Get the classloader system
- *
+ *
* @return the classloader system
*/
protected synchronized BaseClassLoaderSystem getClassLoaderSystem()
{
return system;
}
-
+
/**
* Get the classloader system
- *
+ *
* @param system the classloader system
*/
synchronized void setClassLoaderSystem(BaseClassLoaderSystem system)
@@ -163,7 +163,7 @@
/**
* Shutdown the domain<p>
- *
+ *
* The default implementation just unregisters all classloaders
*/
protected void shutdownDomain()
@@ -184,32 +184,32 @@
unregisterClassLoader(info.getClassLoader());
}
}
-
+
flushCaches();
}
-
+
/**
* Whether the domain has classloaders
- *
+ *
* @return true when the domain has classloaders
*/
public boolean hasClassLoaders()
{
return classLoaders.isEmpty() == false;
}
-
+
/**
* Whether to use load class for parent
- *
+ *
* @return true to load class on the parent loader
*/
public abstract boolean isUseLoadClassForParent();
-
+
/**
* Transform the byte code<p>
- *
+ *
* By default, this delegates to the classloader system
- *
+ *
* @param classLoader the classloader
* @param className the class name
* @param byteCode the byte code
@@ -227,7 +227,7 @@
/**
* Load a class from the domain
- *
+ *
* @param classLoader the classloader
* @param name the class name
* @param allExports whether we should look at all exports
@@ -237,13 +237,14 @@
protected Class<?> loadClass(BaseClassLoader classLoader, String name, boolean allExports) throws ClassNotFoundException
{
boolean trace = log.isTraceEnabled();
-
+
String path = ClassLoaderUtils.classNameToPath(name);
- checkClassBlackList(classLoader, name, path, allExports, true);
-
+ // JBCL-101 TODO need to rework the blacklist
+ //checkClassBlackList(classLoader, name, path, allExports, true);
+
boolean findInParent = (isUseLoadClassForParent() == false);
-
+
// Should we directly load from the parent?
if (findInParent == false)
{
@@ -254,7 +255,7 @@
return clazz;
}
}
-
+
Loader loader = findLoader(classLoader, path, allExports, findInParent);
if (loader != null)
{
@@ -267,7 +268,7 @@
item.clazz = result;
return result;
}
-
+
// Should we directly load from the parent?
if (findInParent == false)
{
@@ -298,14 +299,14 @@
}
}
}
-
+
// Didn't find it
return null;
}
/**
* Find a loader for a class
- *
+ *
* @param name the class resource name
* @return the loader
*/
@@ -316,7 +317,7 @@
/**
* Find a loader for a class
- *
+ *
* @param classLoader the classloader
* @param name the class resource name
* @param allExports whether we should look at all exports
@@ -328,10 +329,10 @@
boolean trace = log.isTraceEnabled();
if (trace)
log.trace(this + " findLoader " + name + " classLoader=" + classLoader + " allExports=" + allExports + " findInParent=" + findInParent);
-
+
if (getClassLoaderSystem() == null)
throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
-
+
// Try the before attempt (e.g. from the parent)
Loader loader = null;
if (findInParent)
@@ -350,7 +351,7 @@
allExports = true;
}
- // Next we try the old "big ball of mud" model
+ // Next we try the old "big ball of mud" model
if (allExports)
{
loader = findLoaderInExports(classLoader, name, trace);
@@ -359,7 +360,7 @@
}
else if (trace)
log.trace(this + " not loading " + name + " from all exports");
-
+
// Next we try the imports
if (info != null)
{
@@ -380,13 +381,13 @@
// Try the after attempt (e.g. from the parent)
if (findInParent)
return findAfterLoader(name);
-
+
return null;
}
-
+
/**
* Load a resource from the domain
- *
+ *
* @param classLoader the classloader
* @param name the resource name
* @param allExports whether we should look at all exports
@@ -429,7 +430,7 @@
allExports = true;
}
- // Next we try the old "big ball of mud" model
+ // Next we try the old "big ball of mud" model
if (allExports)
{
result = getResourceFromExports(classLoader, name, trace);
@@ -438,7 +439,7 @@
}
else if (trace)
log.trace(this + " not getting resource " + name + " from all exports");
-
+
// Next we try the imports
if (info != null)
{
@@ -451,14 +452,14 @@
result = afterGetResource(name);
if (result != null)
return result;
-
+
// Didn't find it
return null;
}
-
+
/**
* Load resources from the domain
- *
+ *
* @param classLoader the classloader
* @param name the resource name
* @param allExports whether we should look at all exports
@@ -486,12 +487,12 @@
allExports = true;
}
- // Next we try the old "big ball of mud" model
+ // Next we try the old "big ball of mud" model
if (allExports)
getResourcesFromExports(classLoader, name, urls, trace);
else if (trace)
log.trace(this + " not getting resource " + name + " from all exports");
-
+
// Next we try the imports
if (info != null)
getResourcesFromImports(info, name, urls, trace);
@@ -507,10 +508,10 @@
// Try the after attempt
afterGetResources(name, urls);
}
-
+
/**
* Load a package from the domain
- *
+ *
* @param classLoader the classloader
* @param name the resource name
* @param allExports whether we should look at all exports
@@ -539,7 +540,7 @@
allExports = true;
}
- // Next we try the old "big ball of mud" model
+ // Next we try the old "big ball of mud" model
if (allExports)
{
result = getPackageFromExports(classLoader, name, trace);
@@ -548,7 +549,7 @@
}
else if (trace)
log.trace(this + " not getting package " + name + " from all exports");
-
+
// Next we try the imports
if (info != null)
{
@@ -575,14 +576,14 @@
result = afterGetPackage(name);
if (result != null)
return result;
-
+
// Didn't find it
return null;
}
-
+
/**
* Load packages from the domain
- *
+ *
* @param classLoader the classloader
* @param packages the packages to add to
* @param allExports whether we should look at all exports
@@ -608,12 +609,12 @@
allExports = true;
}
- // Next we try the old "big ball of mud" model
+ // Next we try the old "big ball of mud" model
if (allExports)
getPackagesFromExports(classLoader, packages, trace);
else if (trace)
log.trace(this + " not getting packages from all exports");
-
+
// Next we try the imports
if (info != null)
getPackagesFromImports(info, packages, trace);
@@ -629,10 +630,10 @@
// Try the after attempt
afterGetPackages(packages);
}
-
+
/**
* Find a loader for class in exports
- *
+ *
* @param classLoader the classloader
* @param name the class resource name
* @param trace whether trace is enabled
@@ -660,7 +661,7 @@
}
boolean canCache = true;
boolean canBlackList = true;
-
+
String packageName = ClassLoaderUtils.getResourcePackageName(name);
List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
if (trace)
@@ -670,7 +671,7 @@
for (ClassLoaderInformation info : list)
{
BaseDelegateLoader exported = info.getExported();
-
+
// See whether the policies allow caching/blacklisting
BaseClassLoaderPolicy loaderPolicy = exported.getPolicy();
if (loaderPolicy == null || loaderPolicy.isCacheable() == false)
@@ -689,13 +690,13 @@
// Here is not found in the exports so can we blacklist it?
if (canBlackList)
globalClassBlackList.put(name, name);
-
+
return null;
}
-
+
/**
* Load a resource from the exports
- *
+ *
* @param classLoader the classloader
* @param name the resource name
* @param trace whether trace is enabled
@@ -709,7 +710,7 @@
if (trace)
log.trace(this + " got resource from cache " + name);
}
-
+
if (globalResourceBlackList.containsKey(name))
{
if (trace)
@@ -718,7 +719,7 @@
}
boolean canCache = true;
boolean canBlackList = true;
-
+
String packageName = ClassLoaderUtils.getResourcePackageName(name);
List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
if (trace)
@@ -728,7 +729,7 @@
for (ClassLoaderInformation info : list)
{
BaseDelegateLoader loader = info.getExported();
-
+
// See whether the policies allow caching/blacklisting
BaseClassLoaderPolicy loaderPolicy = loader.getPolicy();
if (loaderPolicy == null || loaderPolicy.isCacheable() == false)
@@ -750,10 +751,10 @@
globalResourceBlackList.put(name, name);
return null;
}
-
+
/**
* Load resources from the exports
- *
+ *
* @param classLoader the classloader
* @param name the resource name
* @param urls the urls to add to
@@ -775,10 +776,10 @@
}
}
}
-
+
/**
* Load a package from the exports
- *
+ *
* @param classLoader the classloader
* @param name the package name
* @param trace whether trace is enabled
@@ -802,10 +803,10 @@
}
return null;
}
-
+
/**
* Load packages from the exports
- *
+ *
* @param classLoader the classloader
* @param packages the packages to add to
* @param trace whether trace is enabled
@@ -827,7 +828,7 @@
/**
* Find a loader for a class in imports
- *
+ *
* @param info the classloader information
* @param name the class resource name
* @param trace whether trace is enabled
@@ -850,14 +851,14 @@
log.trace(this + " found in import cache " + name);
return loader;
}
-
+
if (info.isBlackListedClass(name))
{
if (trace)
log.trace(this + " class is black listed in imports " + name);
return null;
}
-
+
for (DelegateLoader delegate : delegates)
{
if (trace)
@@ -871,10 +872,10 @@
info.blackListClass(name);
return null;
}
-
+
/**
* Load a resource from the imports
- *
+ *
* @param info the classloader information
* @param name the resource name
* @param trace whether trace is enabled
@@ -897,7 +898,7 @@
log.trace(this + " found resource in import cache " + name);
return url;
}
-
+
if (info.isBlackListedResource(name))
{
if (trace)
@@ -920,10 +921,10 @@
info.blackListResource(name);
return null;
}
-
+
/**
* Load resources from the imports
- *
+ *
* @param info the classloader info
* @param name the resource name
* @param urls the urls to add to
@@ -944,10 +945,10 @@
for (DelegateLoader delegate : delegates)
delegate.getResources(name, urls);
}
-
+
/**
* Load a package from the imports
- *
+ *
* @param info the classloader information
* @param name the pacakge name
* @param trace whether trace is enabled
@@ -974,10 +975,10 @@
}
return null;
}
-
+
/**
* Load packages from the imports
- *
+ *
* @param info the classloader info
* @param packages the packages to add to
* @param trace whether trace is enabled
@@ -999,15 +1000,15 @@
/**
* Invoked before classloading is attempted to allow a preload attempt, e.g. from the parent
- *
+ *
* @param name the class name
* @return the loader if found or null otherwise
*/
protected abstract Class<?> loadClassBefore(String name);
-
+
/**
* Invoked after classloading is attempted to allow a postload attempt, e.g. from the parent
- *
+ *
* @param name the class name
* @return the loader if found or null otherwise
*/
@@ -1015,84 +1016,84 @@
/**
* Invoked before classloading is attempted to allow a preload attempt, e.g. from the parent
- *
+ *
* @param name the class resource name
* @return the loader if found or null otherwise
*/
protected abstract Loader findBeforeLoader(String name);
-
+
/**
* Invoked after classloading is attempted to allow a postload attempt, e.g. from the parent
- *
+ *
* @param name the class resource name
* @return the loader if found or null otherwise
*/
protected abstract Loader findAfterLoader(String name);
-
+
/**
* Invoked before getResources is attempted to allow a preload attempt, e.g. from the parent
- *
+ *
* @param name the resource name
* @param urls the urls to add to
* @throws IOException for any error
*/
protected abstract void beforeGetResources(String name, Set<URL> urls) throws IOException;
-
+
/**
* Invoked after getResources is attempted to allow a postload attempt, e.g. from the parent
- *
+ *
* @param name the resource name
* @param urls the urls to add to
* @throws IOException for any error
*/
protected abstract void afterGetResources(String name, Set<URL> urls) throws IOException;
-
+
/**
* Invoked before getResource is attempted to allow a preload attempt, e.g. from the parent
- *
+ *
* @param name the resource name
* @return the url if found or null otherwise
*/
protected abstract URL beforeGetResource(String name);
-
+
/**
* Invoked after getResource is attempted to allow a postload attempt, e.g. from the parent
- *
+ *
* @param name the resource name
* @return the url if found or null otherwise
*/
protected abstract URL afterGetResource(String name);
-
+
/**
* Invoked before getPackages is attempted to allow a preload attempt, e.g. from the parent
- *
+ *
* @param packages the packages to add to
*/
protected abstract void beforeGetPackages(Set<Package> packages);
-
+
/**
* Invoked after getPackages is attempted to allow a postload attempt, e.g. from the parent
- *
+ *
* @param packages the packages to add to
*/
protected abstract void afterGetPackages(Set<Package> packages);
-
+
/**
* Invoked before getPackage is attempted to allow a preload attempt, e.g. from the parent
- *
+ *
* @param name the package name
* @return the package if found or null otherwise
*/
protected abstract Package beforeGetPackage(String name);
-
+
/**
* Invoked after getPackage is attempted to allow a postload attempt, e.g. from the parent
- *
+ *
* @param name the package name
* @return the url if found or null otherwise
*/
protected abstract Package afterGetPackage(String name);
-
+
public Class<?> loadClass(String name)
{
try
@@ -1104,10 +1105,10 @@
return null;
}
}
-
+
/**
* Load a class from the domain
- *
+ *
* @param classLoader the classloader
* @param name the class name
* @return the class
@@ -1117,15 +1118,15 @@
{
return loadClass(classLoader, name, false);
}
-
+
public URL getResource(String name)
{
return getResource(null, name, true);
}
-
+
/**
* Get a resource from the domain
- *
+ *
* @param classLoader the classloader
* @param name the resource name
* @return the url
@@ -1134,15 +1135,15 @@
{
return getResource(classLoader, name, false);
}
-
+
public void getResources(String name, Set<URL> urls) throws IOException
{
getResources(null, name, urls, true);
}
-
+
/**
* Get a resource from the domain
- *
+ *
* @param classLoader the classloader
* @param name the resource name
* @param urls the urls to add to
@@ -1152,15 +1153,15 @@
{
getResources(classLoader, name, urls, false);
}
-
+
public Package getPackage(String name)
{
return getPackage(null, name, true);
}
-
+
/**
* Get a package from the specified classloader
- *
+ *
* @param classLoader the classloader
* @param name the package name
* @return the package
@@ -1169,15 +1170,15 @@
{
return getPackage(classLoader, name, false);
}
-
+
public void getPackages(Set<Package> packages)
{
getPackages(null, packages, true);
}
-
+
/**
- * Get the packages from a specified classloader
- *
+ * Get the packages from a specified classloader
+ *
* @param classLoader the classloader
* @param packages the packages
*/
@@ -1188,7 +1189,7 @@
/**
* A long version of toString()
- *
+ *
* @return the long string
*/
public String toLongString()
@@ -1201,19 +1202,19 @@
builder.append('}');
return builder.toString();
}
-
+
/**
* For subclasses to add information for toLongString()
- *
+ *
* @param builder the builder
*/
protected void toLongString(StringBuilder builder)
{
}
-
+
/**
- * Invoked before adding a classloader policy
- *
+ * Invoked before adding a classloader policy
+ *
* @param classLoader the classloader
* @param policy the classloader policy
*/
@@ -1223,8 +1224,8 @@
}
/**
- * Invoked after adding a classloader policy
- *
+ * Invoked after adding a classloader policy
+ *
* @param classLoader the classloader
* @param policy the classloader policy
*/
@@ -1232,10 +1233,10 @@
{
// nothing
}
-
+
/**
- * Invoked before adding a classloader policy
- *
+ * Invoked before adding a classloader policy
+ *
* @param classLoader the classloader
* @param policy the classloader policy
*/
@@ -1243,10 +1244,10 @@
{
// nothing
}
-
+
/**
- * Invoked after adding a classloader policy
- *
+ * Invoked after adding a classloader policy
+ *
* @param classLoader the classloader
* @param policy the classloader policy
*/
@@ -1257,7 +1258,7 @@
/**
* Get the parent classloader
- *
+ *
* @return the parent classloader
*/
protected ClassLoader getParentClassLoader()
@@ -1266,8 +1267,8 @@
}
/**
- * Register a classloader
- *
+ * Register a classloader
+ *
* @param classLoader the classloader
*/
void registerClassLoader(BaseClassLoader classLoader)
@@ -1276,12 +1277,12 @@
if (getClassLoaderSystem() == null)
throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
-
+
ClassLoaderPolicy policy = classLoader.getPolicy();
BaseDelegateLoader exported = policy.getExported();
if (exported != null && exported.getPolicy() == null)
throw new IllegalStateException("The exported delegate " + exported + " is too lazy for " + policy.toLongString());
-
+
try
{
beforeRegisterClassLoader(classLoader, policy);
@@ -1290,7 +1291,7 @@
{
log.warn("Error in beforeRegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
}
-
+
BaseClassLoaderPolicy basePolicy = classLoader.getPolicy();
basePolicy.setClassLoaderDomain(this);
@@ -1317,7 +1318,7 @@
log.trace("Registered " + policy + " as providing package=" + packageName);
}
}
-
+
flushCaches();
}
@@ -1330,10 +1331,10 @@
log.warn("Error in afterRegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
}
}
-
+
/**
- * Remove a classloader
- *
+ * Remove a classloader
+ *
* @param classLoader the classloader
*/
void unregisterClassLoader(BaseClassLoader classLoader)
@@ -1357,7 +1358,7 @@
// Remove the classloader
ClassLoaderInformation info = infos.remove(classLoader);
classLoaders.remove(info);
-
+
// Remove the package index
String[] packageNames = policy.getPackageNames();
if (packageNames != null && info.getExported() != null)
@@ -1390,7 +1391,7 @@
/**
* Get all the classloaders
- *
+ *
* @return the list of classloaders
*/
protected List<ClassLoader> getAllClassLoaders()
@@ -1403,7 +1404,7 @@
/**
* Get a map of packages to classloader
- *
+ *
* @return a map of packages to a list of classloaders for that package
*/
protected Map<String, List<ClassLoader>> getClassLoadersByPackage()
@@ -1423,7 +1424,7 @@
{
if (packageName == null)
throw new IllegalArgumentException("Null package name");
-
+
List<ClassLoader> result = new ArrayList<ClassLoader>();
List<ClassLoaderInformation> infos = classLoadersByPackageName.get(packageName);
if (infos != null)
@@ -1436,7 +1437,7 @@
/**
* Check the class cache
- *
+ *
* @param classLoader the reference classloader (possibly null)
* @param name the name of the class
* @param path the path of the class resource
@@ -1460,7 +1461,7 @@
/**
* Check the class blacklist
- *
+ *
* @param classLoader the classloader (possibly null)
* @param name the name
* @param path the path of the class resource
@@ -1482,10 +1483,10 @@
}
}
}
-
+
/**
* Check the cache and blacklist
- *
+ *
* @param classLoader the classloader (possibly null)
* @param name the name
* @param path the path of the class resource
@@ -1494,20 +1495,20 @@
* result in ClassNotFoundException; <code>false</code>
* if a <code>null</code> return value is acceptable
* @return the class when found in the cache
- * @throws ClassNotFoundException when the class is blacklisted and
+ * @throws ClassNotFoundException when the class is blacklisted and
* <code>failIfBlackListed</code> is <code>true</code>
*/
protected Class<?> checkClassCacheAndBlackList(BaseClassLoader classLoader, String name, String path, boolean allExports, boolean failIfBlackListed) throws ClassNotFoundException
{
if (path == null)
path = ClassLoaderUtils.classNameToPath(name);
-
+
Class<?> result = checkClassCache(classLoader, name, path, allExports);
if (result != null)
return result;
-
+
checkClassBlackList(classLoader, name, path, allExports, failIfBlackListed);
-
+
return null;
}
@@ -1532,7 +1533,7 @@
for (ClassLoaderInformation info : infos)
info.clearBlackList(name);
}
-
+
/**
* ClassCacheItem.
*/
@@ -1540,12 +1541,12 @@
{
Loader loader;
Class<?> clazz;
-
+
public ClassCacheItem(Loader loader)
{
this.loader = loader;
}
-
+
public ClassCacheItem(Class<?> clazz)
{
this.clazz = clazz;
More information about the jboss-cvs-commits
mailing list