Package org.jboss.modules
Class ModuleClassLoader
java.lang.Object
java.lang.ClassLoader
org.jboss.modules.ConcurrentClassLoader
org.jboss.modules.ModuleClassLoader
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn opaque configuration used internally to create a module class loader. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LocalLoaderprivate final Module(package private) static final ResourceLoaderSpec[]private final AtomicReference<Paths<ResourceLoader, ResourceLoaderSpec>> private final IdentityHashMap<CodeSource, ProtectionDomain> private final ClassFileTransformerFields inherited from class org.jboss.modules.ConcurrentClassLoader
EMPTY_ENUMERATION -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedModuleClassLoader(ModuleClassLoader.Configuration configuration) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidprotected final Objectclone()private Class<?> defineClass(String name, ClassSpec classSpec, ResourceLoader resourceLoader) Define a class from a class name and class spec.protected final PackagedefinePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) Defines a package by name in this ConcurrentClassLoader.private PackagedefinePackage(String name, PackageSpec spec) Define a package from a package spec.private Class<?> doDefineOrLoadClass(String className, byte[] bytes, int off, int len, ProtectionDomain protectionDomain) final booleanprotected final voidfinalize()protected final Class<?> Find a class, possibly delegating to other loader(s).protected final StringfindLibrary(String libname) Find a library from one of the resource loaders.final URLfindResource(String name, boolean exportsOnly) Find the resource with the given name and exported status.final InputStreamfindResourceAsStream(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 StringgetClassNotFoundExceptionMessage(String className, Module fromModule) Returns an exception message used when producing instances of ClassNotFoundException.(package private) LocalLoaderGet the local loader which refers to this module class loader.Get the (unmodifiable) set of paths which are locally available in this module class loader.final ModuleGet the module for this class loader.protected final PackagegetPackageByName(String name) Perform the actual work to load a package which is visible to this class loader.protected final Package[]Get all defined packages which are visible to this class loader.getPaths()private ProtectionDomaingetProtectionDomain(CodeSource codeSource) (package private) ResourceLoader[]final inthashCode()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.loadResourceLocal(String name) Load a local resource from this class loader.(package private) ResourceloadResourceLocal(String root, String name) Load a local resource from a specific root from this module class loader.protected voidpostDefine(ClassSpec classSpec, Class<?> definedClass) A hook which is invoked after a class is defined.protected voidA hook which is invoked before a class is defined.(package private) booleanRecalculate the path maps for this module class loader.final voidsetClassAssertionStatus(String className, boolean enabled) final voidsetDefaultAssertionStatus(boolean enabled) final voidsetPackageAssertionStatus(String packageName, boolean enabled) private booleansetResourceLoaders(Paths<ResourceLoader, ResourceLoaderSpec> paths, ResourceLoaderSpec[] resourceLoaders) (package private) booleansetResourceLoaders(ResourceLoaderSpec[] resourceLoaders) Change the set of resource loaders for this module class loader, and recalculate the path maps.final StringtoString()Get a string representation of this class loader.Methods inherited from class org.jboss.modules.ConcurrentClassLoader
defineOrLoadClass, defineOrLoadClass, findClass, findLoadedPackage, findResource, findResources, getPackage, getResource, getResourceAsStream, getResources, loadClass, loadClass, loadExportedClass, loadExportedClassMethods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, defineClass, findClass, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, setSigners
-
Field Details
-
NO_RESOURCE_LOADERS
-
module
-
transformer
-
paths
-
localLoader
-
protectionDomains
-
-
Constructor Details
-
ModuleClassLoader
Construct a new instance.- Parameters:
configuration- the module class loader configuration to use
-
-
Method Details
-
recalculate
boolean recalculate()Recalculate the path maps for this module class loader.- Returns:
trueif the paths were recalculated, orfalseif another thread finished recalculating before the calling thread
-
setResourceLoaders
Change the set of resource loaders for this module class loader, and recalculate the path maps.- Parameters:
resourceLoaders- the new resource loaders- Returns:
trueif the paths were recalculated, orfalseif another thread finished recalculating before the calling thread
-
setResourceLoaders
private boolean setResourceLoaders(Paths<ResourceLoader, ResourceLoaderSpec> paths, ResourceLoaderSpec[] resourceLoaders) -
getLocalLoader
LocalLoader getLocalLoader()Get the local loader which refers to this module class loader.- Returns:
- the local loader
-
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 throwsClassNotFoundException.If a class is to be defined by this method, it should be done via one of the atomic
defineOrLoadClassmethods rather thandefineClass()in order to avoid spurious exceptions.- Overrides:
findClassin classConcurrentClassLoader- Parameters:
className- the class nameexportsOnly-trueif only exported classes should be consideredresolve-trueif the class should be linked after loading- Returns:
- the class
- Throws:
ClassNotFoundException- if the class is not found
-
getClassNotFoundExceptionMessage
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 missingfromModule- the module from which the class could not be found- Returns:
- an exception message used when producing instances of ClassNotFoundException
-
loadClassLocal
Load a class from this class loader.- Parameters:
className- the class name to load- Returns:
- the loaded class or
nullif it was not found - Throws:
ClassNotFoundException- if an exception occurs while loading the class or its dependencies
-
loadClassLocal
Load a local class from this class loader.- Parameters:
className- the class nameresolve-trueto resolve the loaded class- Returns:
- the loaded class or
nullif it was not found - Throws:
ClassNotFoundException- if an error occurs while loading the class
-
loadResourceLocal
Load a local resource from a specific root from this module class loader.- Parameters:
root- the root namename- the resource name- Returns:
- the resource, or
nullif it was not found
-
loadResourceLocal
Load a local resource from this class loader.- Parameters:
name- the resource name- Returns:
- the list of resources
-
doDefineOrLoadClass
private Class<?> doDefineOrLoadClass(String className, byte[] bytes, int off, int len, ProtectionDomain protectionDomain) -
getProtectionDomain
-
defineClass
Define a class from a class name and class spec. Also defines any enclosingPackageinstances, and performs any sealed-package checks.- Parameters:
name- the class nameclassSpec- the class specresourceLoader- the resource loader of the class spec- Returns:
- the new class
-
preDefine
A hook which is invoked before a class is defined.- Parameters:
classSpec- the class spec of the defined classclassName- the class to be defined
-
postDefine
A hook which is invoked after a class is defined.- Parameters:
classSpec- the class spec of the defined classdefinedClass- the class that was defined
-
definePackage
Define a package from a package spec.- Parameters:
name- the package namespec- the package specification- Returns:
- the new package
-
findLibrary
Find a library from one of the resource loaders.- Overrides:
findLibraryin classClassLoader- Parameters:
libname- the library name- Returns:
- the full absolute path to the library
-
findResource
Find the resource with the given name and exported status.- Overrides:
findResourcein classConcurrentClassLoader- Parameters:
name- the resource nameexportsOnly-trueto consider only exported resources orfalseto consider all resources- Returns:
- the resource URL
- See Also:
-
findResources
Finds the resources with the given name and exported status.- Overrides:
findResourcesin classConcurrentClassLoader- Parameters:
name- the resource nameexportsOnly-trueto consider only exported resources orfalseto consider all resources- Returns:
- the resource enumeration
- Throws:
IOException- if an I/O error occurs- See Also:
-
findResourceAsStream
Finds the resource with the given name and exported status, returning the resource content as a stream.- Overrides:
findResourceAsStreamin classConcurrentClassLoader- Parameters:
name- the resource nameexportsOnly-trueto consider only exported resources orfalseto consider all resources- Returns:
- the resource stream, or
nullif the resource is not found
-
getModule
Get the module for this class loader.- Returns:
- the module
-
toString
Get a string representation of this class loader. -
getPaths
-
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:
definePackagein classConcurrentClassLoader- Parameters:
name- the package namespecTitle- the specification titlespecVersion- the specification versionspecVendor- the specification vendorimplTitle- the implementation titleimplVersion- the implementation versionimplVendor- the implementation vendorsealBase- if notnull, 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
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:
getPackageByNamein classConcurrentClassLoader- Parameters:
name- the package name- Returns:
- the package, or
nullif no such package is visible to this class loader
-
getPackages
Get all defined packages which are visible to this class loader.- Overrides:
getPackagesin classConcurrentClassLoader- Returns:
- the packages
-
setDefaultAssertionStatus
public final void setDefaultAssertionStatus(boolean enabled) - Overrides:
setDefaultAssertionStatusin classClassLoader
-
setPackageAssertionStatus
- Overrides:
setPackageAssertionStatusin classClassLoader
-
setClassAssertionStatus
- Overrides:
setClassAssertionStatusin classClassLoader
-
clearAssertionStatus
public final void clearAssertionStatus()- Overrides:
clearAssertionStatusin classClassLoader
-
hashCode
public final int hashCode() -
equals
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
finalize
-
getResourceLoaders
ResourceLoader[] getResourceLoaders() -
iterateResources
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 searchrecurse-trueto recurse into subdirectories,falseotherwise- Returns:
- the resource iterator
-
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
-