Package org.jboss.modules

# Class ModuleClassLoader

java.lang.Object
java.lang.ClassLoader
org.jboss.modules.NamedClassLoader
org.jboss.modules.ConcurrentClassLoader
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, Richard Opalka, thomas.diesler@jboss.com

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final 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

Constructors
Modifier
Constructor
Description
`protected`
`ModuleClassLoader(ModuleClassLoader.Configuration configuration)`
Construct a new instance.

## Method Summary

Modifier and Type
Method
Description
`final void`
`clearAssertionStatus()`
`protected final Object`
`clone()`
`protected final Package`
`definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)`
Defines a package by name in this `ConcurrentClassLoader`.
`final boolean`
`equals(Object obj)`
`protected final void`
`finalize()`
`protected final Class<?>`
`findClass(String className, boolean exportsOnly, boolean resolve)`
Find a class, possibly delegating to other loader(s).
`protected final String`
`findLibrary(String libname)`
Find a library from one of the resource loaders.
`final URL`
`findResource(String name, boolean exportsOnly)`
Find the resource with the given name and exported status.
`final InputStream`
`findResourceAsStream(String name, boolean exportsOnly)`
Finds the resource with the given name and exported status, returning the resource content as a stream.
`final Enumeration<URL>`
`findResources(String name, boolean exportsOnly)`
Finds the resources with the given name and exported status.
`protected String`
`getClassNotFoundExceptionMessage(String className, Module fromModule)`
Returns an exception message used when producing instances of ClassNotFoundException.
`final Set<String>`
`getLocalPaths()`
Get the (unmodifiable) set of paths which are locally available in this module class loader.
`final Module`
`getModule()`
Get the module for this class loader.
`final String`
`getName()`
Get the name of this module.
`protected final Package`
`getPackageByName(String name)`
Perform the actual work to load a package which is visible to this class loader.
`protected final Package[]`
`getPackages()`
Get all defined packages which are visible to this class loader.
`final int`
`hashCode()`
`final Iterator<Resource>`
`iterateResources(String startName, boolean recurse)`
Iterate the resources within this module class loader.
`Class<?>`
`loadClassLocal(String className)`
Load a class from this class loader.
`Class<?>`
`loadClassLocal(String className, boolean resolve)`
Load a local class from this class loader.
`List<Resource>`
`loadResourceLocal(String name)`
Load a local exported resource from this class loader.
`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.
`final void`
`setClassAssertionStatus(String className, boolean enabled)`
`final void`
`setDefaultAssertionStatus(boolean enabled)`
`final void`
`setPackageAssertionStatus(String packageName, boolean enabled)`
`final String`
`toString()`
Get a string representation of this class loader.

### Methods inherited from class org.jboss.modules.ConcurrentClassLoader

`defineOrLoadClass, defineOrLoadClass, findClass, findClass, findLoadedPackage, findResource, findResource, findResources, getPackage, getResource, getResourceAsStream, getResources, loadClass, loadClass, loadExportedClass, loadExportedClass`

### Methods inherited from class java.lang.ClassLoader

`defineClass, defineClass, defineClass, defineClass, findLoadedClass, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, setSigners`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

## Constructor Details

### ModuleClassLoader

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

Parameters:
  `configuration` - the module class loader configuration to use

## Method Details

### 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`.

If a class is to be defined by this method, it should be done via one of the atomic `defineOrLoadClass` methods rather than `defineClass()` in order to avoid spurious exceptions.

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

### getClassNotFoundExceptionMessage

protected String getClassNotFoundExceptionMessage(String className, Module fromModule)
Returns an exception message used when producing instances of ClassNotFoundException. This can be overridden by subclasses to customise the error message.

Parameters:
  `className` - the name of the class which is missing
  `fromModule` - the module from which the class could not be found
Returns:
  an exception message used when producing instances of ClassNotFoundException

### loadClassLocal

public Class<?> loadClassLocal(String className) throws ClassNotFoundException
Load a class from this class loader.

Parameters:
  `className` - the class name to load
Returns:
  the loaded class or `null` if it was not found
Throws:
  `ClassNotFoundException` - if an exception occurs while loading the class or its dependencies

### loadClassLocal

public Class<?> loadClassLocal(String className, boolean resolve) throws ClassNotFoundException
Load a local class from this class loader.

Parameters:
  `className` - the class name
  `resolve` - `true` to resolve the loaded class
Returns:
  the loaded class or `null` if it was not found
Throws:
  `ClassNotFoundException` - if an error occurs while loading the class

### loadResourceLocal

public List<Resource> loadResourceLocal(String name)
Load a local exported resource from this class loader.

Parameters:
  `name` - the resource name
Returns:
  the list of resources

### 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)
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
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

### getName

public final String getName()
Get the name of this module. This method is used by Java 9 in debug output.

Overrides:
  `getName` in class `NamedClassLoader`
Returns:
  the name of this module

### toString

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

Overrides:
  `toString` in class `Object`
Returns:
  the string

### definePackage

protected final Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException
Defines a package by name in this `ConcurrentClassLoader`. If the package was already defined, the existing package is returned instead.

Overrides:
  `definePackage` in class `ConcurrentClassLoader`
Parameters:
  `name` - the package name
  `specTitle` - the specification title
  `specVersion` - the specification version
  `specVendor` - the specification vendor
  `implTitle` - the implementation title
  `implVersion` - the implementation version
  `implVendor` - the implementation vendor
  `sealBase` - if not `null`, then this package is sealed with respect to the given code source URL
Returns:
  the newly defined package, or the existing one if one was already defined
Throws:
  `IllegalArgumentException`

### getPackageByName

protected final Package getPackageByName(String name)
Perform the actual work to load a package which is visible to this class loader. By default, uses a simple parent-first delegation strategy.

Overrides:
  `getPackageByName` in class `ConcurrentClassLoader`
Parameters:
  `name` - the package name
Returns:
  the package, or `null` if no such package is visible to this class loader

### getPackages

protected final Package[] getPackages()
Get all defined packages which are visible to this class loader.

Overrides:
  `getPackages` in class `ConcurrentClassLoader`
Returns:
  the packages

### 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`

### iterateResources

public final Iterator<Resource> iterateResources(String startName, boolean recurse)
Iterate the resources within this module class loader. Only resource roots which are inherently iterable will be checked, thus the result of this method may only be a subset of the actual loadable resources. The returned resources are not sorted or grouped in any particular way.

Parameters:
  `startName` - the directory name to search
  `recurse` - `true` to recurse into subdirectories, `false` otherwise
Returns:
  the resource iterator

### getLocalPaths

public final Set<String> getLocalPaths()
Get the (unmodifiable) set of paths which are locally available in this module class loader. The set will include all paths defined by the module's resource loaders, minus any paths excluded by filters. The set will generally always contain an empty entry (""). The set is unordered and unsorted, and is iterable in O(n) time and accessible in O(1) time.

Returns:
  the set of local paths