public class ModuleClassLoader extends ConcurrentClassLoader
Module
, which has API methods to access the exported view of classes and resources.Modifier and Type | Class and Description |
---|---|
static class |
ModuleClassLoader.Configuration
An opaque configuration used internally to create a module class loader.
|
Modifier and Type | Field and Description |
---|---|
private LocalLoader |
localLoader |
private Module |
module |
(package private) static ResourceLoaderSpec[] |
NO_RESOURCE_LOADERS |
private java.util.concurrent.atomic.AtomicReference<Paths<ResourceLoader,ResourceLoaderSpec>> |
paths |
private java.util.IdentityHashMap<java.security.CodeSource,java.security.ProtectionDomain> |
protectionDomains |
private java.lang.instrument.ClassFileTransformer |
transformer |
EMPTY_ENUMERATION
Modifier | Constructor and Description |
---|---|
protected |
ModuleClassLoader(ModuleClassLoader.Configuration configuration)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
clearAssertionStatus() |
protected java.lang.Object |
clone() |
private java.lang.Class<?> |
defineClass(java.lang.String name,
ClassSpec classSpec,
ResourceLoader resourceLoader)
Define a class from a class name and class spec.
|
private java.lang.Package |
definePackage(java.lang.String name,
PackageSpec spec)
Define a package from a package spec.
|
protected java.lang.Package |
definePackage(java.lang.String name,
java.lang.String specTitle,
java.lang.String specVersion,
java.lang.String specVendor,
java.lang.String implTitle,
java.lang.String implVersion,
java.lang.String implVendor,
java.net.URL sealBase)
Defines a package by name in this ConcurrentClassLoader.
|
private java.lang.Class<?> |
doDefineOrLoadClass(java.lang.String className,
byte[] bytes,
int off,
int len,
java.security.ProtectionDomain protectionDomain) |
boolean |
equals(java.lang.Object obj) |
protected void |
finalize() |
protected java.lang.Class<?> |
findClass(java.lang.String className,
boolean exportsOnly,
boolean resolve)
Find a class, possibly delegating to other loader(s).
|
protected java.lang.String |
findLibrary(java.lang.String libname)
Find a library from one of the resource loaders.
|
java.net.URL |
findResource(java.lang.String name,
boolean exportsOnly)
Find the resource with the given name and exported status.
|
java.io.InputStream |
findResourceAsStream(java.lang.String name,
boolean exportsOnly)
Finds the resource with the given name and exported status, returning the resource content as a stream.
|
java.util.Enumeration<java.net.URL> |
findResources(java.lang.String name,
boolean exportsOnly)
Finds the resources with the given name and exported status.
|
protected java.lang.String |
getClassNotFoundExceptionMessage(java.lang.String className,
Module fromModule)
Returns an exception message used when producing instances of ClassNotFoundException.
|
(package private) LocalLoader |
getLocalLoader()
Get the local loader which refers to this module class loader.
|
java.util.Set<java.lang.String> |
getLocalPaths()
Get the (unmodifiable) set of paths which are locally available in this module class loader.
|
Module |
getModule()
Get the module for this class loader.
|
protected java.lang.Package |
getPackageByName(java.lang.String name)
Perform the actual work to load a package which is visible to this class loader.
|
protected java.lang.Package[] |
getPackages()
Get all defined packages which are visible to this class loader.
|
(package private) java.util.Set<java.lang.String> |
getPaths() |
private java.security.ProtectionDomain |
getProtectionDomain(java.security.CodeSource codeSource) |
(package private) ResourceLoader[] |
getResourceLoaders() |
int |
hashCode() |
java.util.Iterator<Resource> |
iterateResources(java.lang.String startName,
boolean recurse)
Iterate the resources within this module class loader.
|
java.lang.Class<?> |
loadClassLocal(java.lang.String className)
Load a class from this class loader.
|
java.lang.Class<?> |
loadClassLocal(java.lang.String className,
boolean resolve)
Load a local class from this class loader.
|
java.util.List<Resource> |
loadResourceLocal(java.lang.String name)
Load a local resource from this class loader.
|
(package private) Resource |
loadResourceLocal(java.lang.String root,
java.lang.String name)
Load a local resource from a specific root from this module class loader.
|
protected void |
postDefine(ClassSpec classSpec,
java.lang.Class<?> definedClass)
A hook which is invoked after a class is defined.
|
protected void |
preDefine(ClassSpec classSpec,
java.lang.String className)
A hook which is invoked before a class is defined.
|
(package private) boolean |
recalculate()
Recalculate the path maps for this module class loader.
|
void |
setClassAssertionStatus(java.lang.String className,
boolean enabled) |
void |
setDefaultAssertionStatus(boolean enabled) |
void |
setPackageAssertionStatus(java.lang.String packageName,
boolean enabled) |
private boolean |
setResourceLoaders(Paths<ResourceLoader,ResourceLoaderSpec> paths,
ResourceLoaderSpec[] resourceLoaders) |
(package private) boolean |
setResourceLoaders(ResourceLoaderSpec[] resourceLoaders)
Change the set of resource loaders for this module class loader, and recalculate the path maps.
|
java.lang.String |
toString()
Get a string representation of this class loader.
|
defineOrLoadClass, defineOrLoadClass, findClass, findLoadedPackage, findResource, findResources, getPackage, getResource, getResourceAsStream, getResources, loadClass, loadClass, loadExportedClass, loadExportedClass
defineClass, defineClass, defineClass, defineClass, findLoadedClass, findSystemClass, getClassLoadingLock, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, registerAsParallelCapable, resolveClass, setSigners
static final ResourceLoaderSpec[] NO_RESOURCE_LOADERS
private final Module module
private final java.lang.instrument.ClassFileTransformer transformer
private final java.util.concurrent.atomic.AtomicReference<Paths<ResourceLoader,ResourceLoaderSpec>> paths
private final LocalLoader localLoader
private final java.util.IdentityHashMap<java.security.CodeSource,java.security.ProtectionDomain> protectionDomains
protected ModuleClassLoader(ModuleClassLoader.Configuration configuration)
configuration
- the module class loader configuration to useboolean recalculate()
true
if the paths were recalculated, or false
if another thread finished recalculating
before the calling threadboolean setResourceLoaders(ResourceLoaderSpec[] resourceLoaders)
resourceLoaders
- the new resource loaderstrue
if the paths were recalculated, or false
if another thread finished recalculating
before the calling threadprivate boolean setResourceLoaders(Paths<ResourceLoader,ResourceLoaderSpec> paths, ResourceLoaderSpec[] resourceLoaders)
LocalLoader getLocalLoader()
protected final java.lang.Class<?> findClass(java.lang.String className, boolean exportsOnly, boolean resolve) throws java.lang.ClassNotFoundException
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.
findClass
in class ConcurrentClassLoader
className
- the class nameexportsOnly
- true
if only exported classes should be consideredresolve
- true
if the class should be linked after loadingjava.lang.ClassNotFoundException
- if the class is not foundprotected java.lang.String getClassNotFoundExceptionMessage(java.lang.String className, Module fromModule)
className
- the name of the class which is missingfromModule
- the module from which the class could not be foundpublic java.lang.Class<?> loadClassLocal(java.lang.String className) throws java.lang.ClassNotFoundException
className
- the class name to loadnull
if it was not foundjava.lang.ClassNotFoundException
- if an exception occurs while loading the class or its dependenciespublic java.lang.Class<?> loadClassLocal(java.lang.String className, boolean resolve) throws java.lang.ClassNotFoundException
className
- the class nameresolve
- true
to resolve the loaded classnull
if it was not foundjava.lang.ClassNotFoundException
- if an error occurs while loading the classResource loadResourceLocal(java.lang.String root, java.lang.String name)
root
- the root namename
- the resource namenull
if it was not foundpublic java.util.List<Resource> loadResourceLocal(java.lang.String name)
name
- the resource nameprivate java.lang.Class<?> doDefineOrLoadClass(java.lang.String className, byte[] bytes, int off, int len, java.security.ProtectionDomain protectionDomain)
private java.security.ProtectionDomain getProtectionDomain(java.security.CodeSource codeSource)
private java.lang.Class<?> defineClass(java.lang.String name, ClassSpec classSpec, ResourceLoader resourceLoader)
Package
instances,
and performs any sealed-package checks.name
- the class nameclassSpec
- the class specresourceLoader
- the resource loader of the class specprotected void preDefine(ClassSpec classSpec, java.lang.String className)
classSpec
- the class spec of the defined classclassName
- the class to be definedprotected void postDefine(ClassSpec classSpec, java.lang.Class<?> definedClass)
classSpec
- the class spec of the defined classdefinedClass
- the class that was definedprivate java.lang.Package definePackage(java.lang.String name, PackageSpec spec)
name
- the package namespec
- the package specificationprotected final java.lang.String findLibrary(java.lang.String libname)
findLibrary
in class java.lang.ClassLoader
libname
- the library namepublic final java.net.URL findResource(java.lang.String name, boolean exportsOnly)
findResource
in class ConcurrentClassLoader
name
- the resource nameexportsOnly
- true
to consider only exported resources or false
to consider all resourcesConcurrentClassLoader.getResource(String)
public final java.util.Enumeration<java.net.URL> findResources(java.lang.String name, boolean exportsOnly) throws java.io.IOException
findResources
in class ConcurrentClassLoader
name
- the resource nameexportsOnly
- true
to consider only exported resources or false
to consider all resourcesjava.io.IOException
- if an I/O error occursConcurrentClassLoader.getResources(String)
public final java.io.InputStream findResourceAsStream(java.lang.String name, boolean exportsOnly)
findResourceAsStream
in class ConcurrentClassLoader
name
- the resource nameexportsOnly
- true
to consider only exported resources or false
to consider all resourcesnull
if the resource is not foundpublic final Module getModule()
public final java.lang.String toString()
toString
in class java.lang.Object
java.util.Set<java.lang.String> getPaths()
protected final java.lang.Package definePackage(java.lang.String name, java.lang.String specTitle, java.lang.String specVersion, java.lang.String specVendor, java.lang.String implTitle, java.lang.String implVersion, java.lang.String implVendor, java.net.URL sealBase) throws java.lang.IllegalArgumentException
definePackage
in class ConcurrentClassLoader
name
- the package namespecTitle
- the specification titlespecVersion
- the specification versionspecVendor
- the specification vendorimplTitle
- the implementation titleimplVersion
- the implementation versionimplVendor
- the implementation vendorsealBase
- if not null
, then this package is sealed with respect to the given code source URLjava.lang.IllegalArgumentException
protected final java.lang.Package getPackageByName(java.lang.String name)
getPackageByName
in class ConcurrentClassLoader
name
- the package namenull
if no such package is visible to this class loaderprotected final java.lang.Package[] getPackages()
getPackages
in class ConcurrentClassLoader
public final void setDefaultAssertionStatus(boolean enabled)
setDefaultAssertionStatus
in class java.lang.ClassLoader
public final void setPackageAssertionStatus(java.lang.String packageName, boolean enabled)
setPackageAssertionStatus
in class java.lang.ClassLoader
public final void setClassAssertionStatus(java.lang.String className, boolean enabled)
setClassAssertionStatus
in class java.lang.ClassLoader
public final void clearAssertionStatus()
clearAssertionStatus
in class java.lang.ClassLoader
public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
protected final java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
protected final void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
ResourceLoader[] getResourceLoaders()
public final java.util.Iterator<Resource> iterateResources(java.lang.String startName, boolean recurse)
startName
- the directory name to searchrecurse
- true
to recurse into subdirectories, false
otherwisepublic final java.util.Set<java.lang.String> getLocalPaths()