org.jboss.modules
Class ModuleClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by org.jboss.modules.ConcurrentClassLoader
              extended by org.jboss.modules.ModuleClassLoader

public class ModuleClassLoader
extends ConcurrentClassLoader

A module classloader. Instances of this class implement the complete view of classes and resources available in a module. Contrast with Module, which has API methods to access the exported view of classes and resources.

Author:
John Bailey, David M. Lloyd, thomas.diesler@jboss.com

Nested Class Summary
protected static class ModuleClassLoader.Configuration
          An opaque configuration used internally to create a module class loader.
 
Field Summary
 
Fields inherited from class org.jboss.modules.ConcurrentClassLoader
EMPTY_ENUMERATION
 
Constructor Summary
protected ModuleClassLoader(ModuleClassLoader.Configuration configuration)
          Construct a new instance.
 
Method Summary
 void clearAssertionStatus()
          
protected  Object clone()
          
protected  Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)
          
 boolean equals(Object obj)
          
protected  void finalize()
          
protected  Class<?> findClass(String className, boolean exportsOnly, boolean resolve)
          Find a class, possibly delegating to other loader(s).
protected  String findLibrary(String libname)
          Find a library from one of the resource loaders.
 URL findResource(String name, boolean exportsOnly)
          Find the resource with the given name and exported status.
 InputStream findResourceAsStream(String name, boolean exportsOnly)
          Finds the resource with the given name and exported status, returning the resource content as a stream.
 Enumeration<URL> findResources(String name, boolean exportsOnly)
          Finds the resources with the given name and exported status.
 Module getModule()
          Get the module for this class loader.
protected  Package getPackage(String name)
          
protected  Package[] getPackages()
          
protected  PermissionCollection getPermissions(CodeSource codesource)
          
 int hashCode()
          
protected  void postDefine(ClassSpec classSpec, Class<?> definedClass)
          A hook which is invoked after a class is defined.
protected  void preDefine(ClassSpec classSpec, String className)
          A hook which is invoked before a class is defined.
 void setClassAssertionStatus(String className, boolean enabled)
          
 void setDefaultAssertionStatus(boolean enabled)
          
 void setPackageAssertionStatus(String packageName, boolean enabled)
          
 String toString()
          Get a string representation of this class loader.
 
Methods inherited from class org.jboss.modules.ConcurrentClassLoader
findClass, findResource, findResources, getResource, getResourceAsStream, getResources, loadClass, loadClass, loadExportedClass, loadExportedClass
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, defineClass, findLoadedClass, findSystemClass, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModuleClassLoader

protected ModuleClassLoader(ModuleClassLoader.Configuration configuration)
Construct a new instance.

Parameters:
configuration - the module class loader configuration to use
Method Detail

findClass

protected final Class<?> findClass(String className,
                                   boolean exportsOnly,
                                   boolean resolve)
                            throws ClassNotFoundException
Find a class, possibly delegating to other loader(s). This method should never synchronize across a delegation method call of any sort. The default implementation always throws ClassNotFoundException.

Overrides:
findClass in class ConcurrentClassLoader
Parameters:
className - the class name
exportsOnly - true if only exported classes should be considered
resolve - true if the class should be linked after loading
Returns:
the class
Throws:
ClassNotFoundException - if the class is not found

preDefine

protected void preDefine(ClassSpec classSpec,
                         String className)
A hook which is invoked before a class is defined.

Parameters:
classSpec - the class spec of the defined class
className - the class to be defined

postDefine

protected void postDefine(ClassSpec classSpec,
                          Class<?> definedClass)
A hook which is invoked after a class is defined.

Parameters:
classSpec - the class spec of the defined class
definedClass - the class that was defined

findLibrary

protected final String findLibrary(String libname)
Find a library from one of the resource loaders.

Overrides:
findLibrary in class ClassLoader
Parameters:
libname - the library name
Returns:
the full absolute path to the library

findResource

public final URL findResource(String name,
                              boolean exportsOnly)
Find the resource with the given name and exported status.

Overrides:
findResource in class ConcurrentClassLoader
Parameters:
name - the resource name
exportsOnly - true to consider only exported resources or false to consider all resources
Returns:
the resource URL
See Also:
ConcurrentClassLoader.getResource(String)

findResources

public final Enumeration<URL> findResources(String name,
                                            boolean exportsOnly)
                                     throws IOException
Finds the resources with the given name and exported status.

Overrides:
findResources in class ConcurrentClassLoader
Parameters:
name - the resource name
exportsOnly - true to consider only exported resources or false to consider all resources
Returns:
the resource enumeration
Throws:
IOException - if an I/O error occurs
See Also:
ConcurrentClassLoader.getResources(String)

findResourceAsStream

public final InputStream findResourceAsStream(String name,
                                              boolean exportsOnly)
Finds the resource with the given name and exported status, returning the resource content as a stream.

Overrides:
findResourceAsStream in class ConcurrentClassLoader
Parameters:
name - the resource name
exportsOnly - true to consider only exported resources or false to consider all resources
Returns:
the resource stream, or null if the resource is not found

getModule

public final Module getModule()
Get the module for this class loader.

Returns:
the module

toString

public final String toString()
Get a string representation of this class loader.

Overrides:
toString in class Object
Returns:
the string

getPermissions

protected final PermissionCollection getPermissions(CodeSource codesource)

Overrides:
getPermissions in class SecureClassLoader

definePackage

protected final Package definePackage(String name,
                                      String specTitle,
                                      String specVersion,
                                      String specVendor,
                                      String implTitle,
                                      String implVersion,
                                      String implVendor,
                                      URL sealBase)
                               throws IllegalArgumentException

Overrides:
definePackage in class ClassLoader
Throws:
IllegalArgumentException

getPackage

protected final Package getPackage(String name)

Overrides:
getPackage in class ClassLoader

getPackages

protected final Package[] getPackages()

Overrides:
getPackages in class ClassLoader

setDefaultAssertionStatus

public final void setDefaultAssertionStatus(boolean enabled)

Overrides:
setDefaultAssertionStatus in class ClassLoader

setPackageAssertionStatus

public final void setPackageAssertionStatus(String packageName,
                                            boolean enabled)

Overrides:
setPackageAssertionStatus in class ClassLoader

setClassAssertionStatus

public final void setClassAssertionStatus(String className,
                                          boolean enabled)

Overrides:
setClassAssertionStatus in class ClassLoader

clearAssertionStatus

public final void clearAssertionStatus()

Overrides:
clearAssertionStatus in class ClassLoader

hashCode

public final int hashCode()

Overrides:
hashCode in class Object

equals

public final boolean equals(Object obj)

Overrides:
equals in class Object

clone

protected final Object clone()
                      throws CloneNotSupportedException

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

finalize

protected final void finalize()
                       throws Throwable

Overrides:
finalize in class Object
Throws:
Throwable


Copyright © 2011. All Rights Reserved.