org.jboss.classloader.spi.base
Class BaseClassLoaderDomain

java.lang.Object
  extended by org.jboss.classloader.spi.base.BaseClassLoaderDomain
All Implemented Interfaces:
Loader
Direct Known Subclasses:
ClassLoaderDomain

public abstract class BaseClassLoaderDomain
extends Object
implements Loader

BaseClassLoaderDomain.

This class hides some of the implementation details and allows package access to the protected methods.

Version:
$Revision: 1.1 $
Author:
Adrian Brock

Constructor Summary
BaseClassLoaderDomain()
           
 
Method Summary
protected abstract  Package afterGetPackage(String name)
          Invoked after getPackage is attempted to allow a postload attempt, e.g.
protected abstract  void afterGetPackages(Set<Package> packages)
          Invoked after getPackages is attempted to allow a postload attempt, e.g.
protected abstract  URL afterGetResource(String name)
          Invoked after getResource is attempted to allow a postload attempt, e.g.
protected abstract  void afterGetResources(String name, Set<URL> urls)
          Invoked after getResources is attempted to allow a postload attempt, e.g.
protected  void afterRegisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
          Invoked after adding a classloader policy
protected  void afterUnregisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
          Invoked after adding a classloader policy
protected abstract  Package beforeGetPackage(String name)
          Invoked before getPackage is attempted to allow a preload attempt, e.g.
protected abstract  void beforeGetPackages(Set<Package> packages)
          Invoked before getPackages is attempted to allow a preload attempt, e.g.
protected abstract  URL beforeGetResource(String name)
          Invoked before getResource is attempted to allow a preload attempt, e.g.
protected abstract  void beforeGetResources(String name, Set<URL> urls)
          Invoked before getResources is attempted to allow a preload attempt, e.g.
protected  void beforeRegisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
          Invoked before adding a classloader policy
protected  void beforeUnregisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
          Invoked before adding a classloader policy
protected  Class<?> checkClassCacheAndBlackList(BaseClassLoader classLoader, String name, String path, boolean allExports, boolean failIfBlackListed)
          Check the cache and blacklist
protected  void clearBlackList(String name)
          Cleans the entry with the given name from the blackList
protected abstract  Loader findAfterLoader(String name)
          Invoked after classloading is attempted to allow a postload attempt, e.g.
protected abstract  Loader findBeforeLoader(String name)
          Invoked before classloading is attempted to allow a preload attempt, e.g.
protected  Loader findLoader(String name)
          Find a loader for a class
 void flushCaches()
          Flush the internal caches
protected  List<ClassLoader> getAllClassLoaders()
          Get all the classloaders
 int getClassBlackListSize()
           
 int getClassCacheSize()
           
protected  List<ClassLoader> getClassLoaders(String packageName)
           
protected  Map<String,List<ClassLoader>> getClassLoadersByPackage()
          Get a map of packages to classloader
protected  BaseClassLoaderSystem getClassLoaderSystem()
          Get the classloader system
 Package getPackage(String name)
          Get a package
 void getPackages(Set<Package> packages)
          Get all the packages visible from this loader
protected  ClassLoader getParentClassLoader()
          Get the parent classloader
 URL getResource(String name)
          Get a resource
 int getResourceBlackListSize()
           
 int getResourceCacheSize()
           
 void getResources(String name, Set<URL> urls)
          Get resources
 boolean hasClassLoaders()
          Whether the domain has classloaders
abstract  boolean isUseLoadClassForParent()
          Whether to use load class for parent
 Set<String> listClassBlackList()
           
 Map<String,String> listClassCache()
           
 Set<String> listResourceBlackList()
           
 Map<String,URL> listResourceCache()
           
protected  Class<?> loadClass(BaseClassLoader classLoader, String name, boolean allExports)
          Load a class from the domain
 Class<?> loadClass(String name)
          Load a class
protected abstract  Class<?> loadClassAfter(String name)
          Invoked after classloading is attempted to allow a postload attempt, e.g.
protected abstract  Class<?> loadClassBefore(String name)
          Invoked before classloading is attempted to allow a preload attempt, e.g.
protected  void shutdownDomain()
          Shutdown the domain
 String toLongString()
          A long version of toString()
protected  void toLongString(StringBuilder builder)
          For subclasses to add information for toLongString()
protected  byte[] transform(ClassLoader classLoader, String className, byte[] byteCode, ProtectionDomain protectionDomain)
          Transform the byte code
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseClassLoaderDomain

public BaseClassLoaderDomain()
Method Detail

flushCaches

public void flushCaches()
Flush the internal caches


getClassBlackListSize

public int getClassBlackListSize()

getClassCacheSize

public int getClassCacheSize()

getResourceBlackListSize

public int getResourceBlackListSize()

getResourceCacheSize

public int getResourceCacheSize()

listClassBlackList

public Set<String> listClassBlackList()

listClassCache

public Map<String,String> listClassCache()

listResourceBlackList

public Set<String> listResourceBlackList()

listResourceCache

public Map<String,URL> listResourceCache()

getClassLoaderSystem

protected BaseClassLoaderSystem getClassLoaderSystem()
Get the classloader system

Returns:
the classloader system

shutdownDomain

protected void shutdownDomain()
Shutdown the domain

The default implementation just unregisters all classloaders


hasClassLoaders

public boolean hasClassLoaders()
Whether the domain has classloaders

Returns:
true when the domain has classloaders

isUseLoadClassForParent

public abstract boolean isUseLoadClassForParent()
Whether to use load class for parent

Returns:
true to load class on the parent loader

transform

protected byte[] transform(ClassLoader classLoader,
                           String className,
                           byte[] byteCode,
                           ProtectionDomain protectionDomain)
                    throws Exception
Transform the byte code

By default, this delegates to the classloader system

Parameters:
classLoader - the classloader
className - the class name
byteCode - the byte code
protectionDomain - the protection domain
Returns:
the transformed byte code
Throws:
Exception - for any error

loadClass

protected Class<?> loadClass(BaseClassLoader classLoader,
                             String name,
                             boolean allExports)
                      throws ClassNotFoundException
Load a class from the domain

Parameters:
classLoader - the classloader
name - the class name
allExports - whether we should look at all exports
Returns:
the class
Throws:
ClassNotFoundException - for any error

findLoader

protected Loader findLoader(String name)
Find a loader for a class

Parameters:
name - the class resource name
Returns:
the loader

loadClassBefore

protected abstract Class<?> loadClassBefore(String name)
Invoked before classloading is attempted to allow a preload attempt, e.g. from the parent

Parameters:
name - the class name
Returns:
the loader if found or null otherwise

loadClassAfter

protected abstract Class<?> loadClassAfter(String name)
Invoked after classloading is attempted to allow a postload attempt, e.g. from the parent

Parameters:
name - the class name
Returns:
the loader if found or null otherwise

findBeforeLoader

protected abstract Loader findBeforeLoader(String name)
Invoked before classloading is attempted to allow a preload attempt, e.g. from the parent

Parameters:
name - the class resource name
Returns:
the loader if found or null otherwise

findAfterLoader

protected abstract Loader findAfterLoader(String name)
Invoked after classloading is attempted to allow a postload attempt, e.g. from the parent

Parameters:
name - the class resource name
Returns:
the loader if found or null otherwise

beforeGetResources

protected abstract void beforeGetResources(String name,
                                           Set<URL> urls)
                                    throws IOException
Invoked before getResources is attempted to allow a preload attempt, e.g. from the parent

Parameters:
name - the resource name
urls - the urls to add to
Throws:
IOException - for any error

afterGetResources

protected abstract void afterGetResources(String name,
                                          Set<URL> urls)
                                   throws IOException
Invoked after getResources is attempted to allow a postload attempt, e.g. from the parent

Parameters:
name - the resource name
urls - the urls to add to
Throws:
IOException - for any error

beforeGetResource

protected abstract URL beforeGetResource(String name)
Invoked before getResource is attempted to allow a preload attempt, e.g. from the parent

Parameters:
name - the resource name
Returns:
the url if found or null otherwise

afterGetResource

protected abstract URL afterGetResource(String name)
Invoked after getResource is attempted to allow a postload attempt, e.g. from the parent

Parameters:
name - the resource name
Returns:
the url if found or null otherwise

beforeGetPackages

protected abstract void beforeGetPackages(Set<Package> packages)
Invoked before getPackages is attempted to allow a preload attempt, e.g. from the parent

Parameters:
packages - the packages to add to

afterGetPackages

protected abstract void afterGetPackages(Set<Package> packages)
Invoked after getPackages is attempted to allow a postload attempt, e.g. from the parent

Parameters:
packages - the packages to add to

beforeGetPackage

protected abstract Package beforeGetPackage(String name)
Invoked before getPackage is attempted to allow a preload attempt, e.g. from the parent

Parameters:
name - the package name
Returns:
the package if found or null otherwise

afterGetPackage

protected abstract Package afterGetPackage(String name)
Invoked after getPackage is attempted to allow a postload attempt, e.g. from the parent

Parameters:
name - the package name
Returns:
the url if found or null otherwise

loadClass

public Class<?> loadClass(String name)
Description copied from interface: Loader
Load a class

Specified by:
loadClass in interface Loader
Parameters:
name - the class name
Returns:
the class or null if not found

getResource

public URL getResource(String name)
Description copied from interface: Loader
Get a resource

Specified by:
getResource in interface Loader
Parameters:
name - the resource name
Returns:
the url or null if not found

getResources

public void getResources(String name,
                         Set<URL> urls)
                  throws IOException
Description copied from interface: Loader
Get resources

Specified by:
getResources in interface Loader
Parameters:
name - the resource name
urls - the list of urls to add to
Throws:
IOException - for any error

getPackage

public Package getPackage(String name)
Description copied from interface: Loader
Get a package

Specified by:
getPackage in interface Loader
Parameters:
name - the package name
Returns:
the package

getPackages

public void getPackages(Set<Package> packages)
Description copied from interface: Loader
Get all the packages visible from this loader

Specified by:
getPackages in interface Loader
Parameters:
packages - the packages

toLongString

public String toLongString()
A long version of toString()

Returns:
the long string

toLongString

protected void toLongString(StringBuilder builder)
For subclasses to add information for toLongString()

Parameters:
builder - the builder

beforeRegisterClassLoader

protected void beforeRegisterClassLoader(ClassLoader classLoader,
                                         ClassLoaderPolicy policy)
Invoked before adding a classloader policy

Parameters:
classLoader - the classloader
policy - the classloader policy

afterRegisterClassLoader

protected void afterRegisterClassLoader(ClassLoader classLoader,
                                        ClassLoaderPolicy policy)
Invoked after adding a classloader policy

Parameters:
classLoader - the classloader
policy - the classloader policy

beforeUnregisterClassLoader

protected void beforeUnregisterClassLoader(ClassLoader classLoader,
                                           ClassLoaderPolicy policy)
Invoked before adding a classloader policy

Parameters:
classLoader - the classloader
policy - the classloader policy

afterUnregisterClassLoader

protected void afterUnregisterClassLoader(ClassLoader classLoader,
                                          ClassLoaderPolicy policy)
Invoked after adding a classloader policy

Parameters:
classLoader - the classloader
policy - the classloader policy

getParentClassLoader

protected ClassLoader getParentClassLoader()
Get the parent classloader

Returns:
the parent classloader

getAllClassLoaders

protected List<ClassLoader> getAllClassLoaders()
Get all the classloaders

Returns:
the list of classloaders

getClassLoadersByPackage

protected Map<String,List<ClassLoader>> getClassLoadersByPackage()
Get a map of packages to classloader

Returns:
a map of packages to a list of classloaders for that package

getClassLoaders

protected List<ClassLoader> getClassLoaders(String packageName)

checkClassCacheAndBlackList

protected Class<?> checkClassCacheAndBlackList(BaseClassLoader classLoader,
                                               String name,
                                               String path,
                                               boolean allExports,
                                               boolean failIfBlackListed)
                                        throws ClassNotFoundException
Check the cache and blacklist

Parameters:
classLoader - the classloader (possibly null)
name - the name
path - the path of the class resource
allExports - whether to look at all exports
failIfBlackListed - true if a blacklisted class should result in ClassNotFoundException; false if a null return value is acceptable
Returns:
the class when found in the cache
Throws:
ClassNotFoundException - when the class is blacklisted and failIfBlackListed is true

clearBlackList

protected void clearBlackList(String name)
Cleans the entry with the given name from the blackList

Parameters:
name - the name of the resource to clear from the blackList


Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.