public final class Module
extends java.lang.Object
ModuleLoader
s which build modules from
various configuration information and resource roots.Modifier and Type | Class and Description |
---|---|
(package private) static class |
Module.Visited |
Modifier and Type | Field and Description |
---|---|
private static java.lang.RuntimePermission |
ACCESS_MODULE_LOGGER |
private static java.lang.RuntimePermission |
ADD_CONTENT_HANDLER_FACTORY |
private static java.lang.RuntimePermission |
ADD_URL_STREAM_HANDLER_FACTORY |
private static java.util.concurrent.atomic.AtomicReference<ModuleLoader> |
BOOT_MODULE_LOADER |
private static FastCopyHashSet<ClassFilter> |
EMPTY_CLASS_FILTERS |
private static FastCopyHashSet<PathFilter> |
EMPTY_PATH_FILTERS |
private LocalLoader |
fallbackLoader
The fallback local loader, if any is defined.
|
private static java.lang.RuntimePermission |
GET_BOOT_MODULE_LOADER |
private static java.lang.RuntimePermission |
GET_CLASS_LOADER |
private static java.lang.RuntimePermission |
GET_DEPENDENCIES |
private ModuleIdentifier |
identifier
The identifier of this module.
|
private Linkage |
linkage
The linkage state.
|
(package private) static ModuleLogger |
log
The system-wide module logger, which may be changed via
setModuleLogger(org.jboss.modules.log.ModuleLogger) . |
private java.lang.String |
mainClassName
The name of the main class, if any (may be
null ). |
private ModuleClassLoader |
moduleClassLoader
The module class loader for this module.
|
private ModuleLoader |
moduleLoader
The module loader which created this module.
|
private static java.security.PermissionCollection |
NO_PERMISSIONS |
private java.security.PermissionCollection |
permissionCollection
The assigned permission collection.
|
(package private) static ModulesPrivateAccess |
PRIVATE_ACCESS |
private java.util.Map<java.lang.String,java.lang.String> |
properties
The properties map specified when this module was defined.
|
(package private) static java.lang.String[] |
systemPackages |
(package private) static java.lang.String[] |
systemPaths |
Constructor and Description |
---|
Module(ConcreteModuleSpec spec,
ModuleLoader moduleLoader)
Construct a new instance from a module specification.
|
Modifier and Type | Method and Description |
---|---|
private long |
addExportedPaths(Dependency[] dependencies,
java.util.Map<java.lang.String,java.util.List<LocalLoader>> map,
FastCopyHashSet<PathFilter> filterStack,
FastCopyHashSet<ClassFilter> classFilterStack,
FastCopyHashSet<PathFilter> resourceFilterStack,
java.util.Set<Module.Visited> visited) |
private long |
addPaths(Dependency[] dependencies,
java.util.Map<java.lang.String,java.util.List<LocalLoader>> map,
FastCopyHashSet<PathFilter> filterStack,
FastCopyHashSet<ClassFilter> classFilterStack,
FastCopyHashSet<PathFilter> resourceFilterStack,
java.util.Set<Module.Visited> visited) |
private Dependency[] |
calculateDependencies(DependencySpec[] dependencySpecs) |
private static java.security.PermissionCollection |
copyPermissions(java.security.PermissionCollection permissionCollection) |
private LocalLoader |
createClassFilteredLocalLoader(ClassFilter filter,
LocalLoader localLoader) |
private LocalLoader |
createPathFilteredLocalLoader(PathFilter filter,
LocalLoader localLoader) |
(package private) static java.lang.String |
fileNameOfClass(java.lang.String className)
Get the file name of a class.
|
static Module |
forClass(java.lang.Class<?> clazz)
Get the module for a loaded class, or
null if the class did not come from any module. |
static Module |
forClassLoader(java.lang.ClassLoader cl,
boolean search)
Get the module for a class loader, or
null if the class loader is not associated with any module. |
static ModuleLoader |
getBootModuleLoader()
Gets the boot module loader.
|
static Module |
getCallerModule()
Get the caller's module.
|
static ModuleLoader |
getCallerModuleLoader()
Gets the current module loader.
|
ModuleClassLoader |
getClassLoader()
Get the class loader for a module.
|
(package private) ModuleClassLoader |
getClassLoaderPrivate() |
static ModuleLoader |
getContextModuleLoader()
Get the current thread's context module loader.
|
DependencySpec[] |
getDependencies()
Get the current dependencies of this module.
|
(package private) Dependency[] |
getDependenciesInternal() |
(package private) DependencySpec[] |
getDependencySpecsInternal() |
java.util.Set<java.lang.String> |
getExportedPaths()
Get all the paths exported by this module.
|
java.net.URL |
getExportedResource(java.lang.String name)
Get an exported resource URL.
|
Resource |
getExportedResource(java.lang.String rootPath,
java.lang.String resourcePath)
Get an exported resource from a specific root in this module.
|
java.util.Enumeration<java.net.URL> |
getExportedResources(java.lang.String name)
Get all exported resource URLs for a resource name.
|
(package private) LocalLoader |
getFallbackLoader() |
ModuleIdentifier |
getIdentifier()
Get this module's identifier.
|
java.util.Set<java.lang.String> |
getImportedPaths()
Get the (unmodifiable) set of paths which are imported into this module class loader, including local paths.
|
(package private) java.lang.String |
getMainClass() |
Module |
getModule(ModuleIdentifier identifier)
Get the module with the given identifier from the module loader used by this module.
|
static Module |
getModuleFromCallerModuleLoader(ModuleIdentifier identifier)
Get a module from the current module loader.
|
ModuleLoader |
getModuleLoader()
Get the module loader which created this module.
|
static ModuleLogger |
getModuleLogger()
Get the logger used by the module system.
|
(package private) java.lang.Package |
getPackage(java.lang.String name) |
(package private) java.lang.Package[] |
getPackages() |
(package private) java.util.Map<java.lang.String,java.util.List<LocalLoader>> |
getPaths() |
(package private) java.util.Map<java.lang.String,java.util.List<LocalLoader>> |
getPathsUnchecked() |
java.security.PermissionCollection |
getPermissionCollection()
Get the module's configured permission collection.
|
static java.lang.String |
getPlatformIdentifier()
Get the platform identifier.
|
static ModulesPrivateAccess |
getPrivateAccess()
Private access for module internal code.
|
java.lang.String |
getProperty(java.lang.String name)
Get the property with the given name, or
null if none was defined. |
java.lang.String |
getProperty(java.lang.String name,
java.lang.String defaultVal)
Get the property with the given name, or a default value if none was defined.
|
java.util.List<java.lang.String> |
getPropertyNames()
Get a copy of the list of property names.
|
(package private) java.net.URL |
getResource(java.lang.String name)
Load a resource from a local loader.
|
(package private) java.io.InputStream |
getResourceAsStream(java.lang.String name)
Load a resource from a local loader.
|
(package private) java.util.Enumeration<java.net.URL> |
getResources(java.lang.String name)
Load all resources of a given name from a local loader.
|
static long |
getStartTime()
Return the start time in millis when Module.class was loaded.
|
java.util.Iterator<Resource> |
globResources(java.lang.String glob)
Enumerate all imported resources in this module which match the given glob expression.
|
(package private) static void |
initBootModuleLoader(ModuleLoader loader) |
java.util.Iterator<Resource> |
iterateResources(PathFilter filter)
Enumerate all the imported resources in this module, subject to a path filter.
|
(package private) void |
link(Linkage linkage) |
static java.lang.Class<?> |
loadClassFromBootModuleLoader(ModuleIdentifier moduleIdentifier,
java.lang.String className)
Load a class from a module in the system module loader.
|
static java.lang.Class<?> |
loadClassFromCallerModuleLoader(ModuleIdentifier moduleIdentifier,
java.lang.String className)
Load a class from a module in the caller's module loader.
|
(package private) java.lang.Class<?> |
loadModuleClass(java.lang.String className,
boolean resolve)
Load a class from a local loader.
|
<S> java.util.ServiceLoader<S> |
loadService(java.lang.Class<S> serviceType)
Load a service loader from this module.
|
<S> java.util.ServiceLoader<S> |
loadServiceDirectly(java.lang.Class<S> serviceType)
Load a service loader from this module, without looking at dependencies.
|
static <S> java.util.ServiceLoader<S> |
loadServiceFromCallerModuleLoader(ModuleIdentifier identifier,
java.lang.Class<S> serviceType)
Load a service loader from a module in the caller's module loader.
|
private static java.security.PermissionCollection |
noPermissions() |
(package private) static java.lang.String |
pathOf(java.lang.String resourceName)
Get the path name of a resource.
|
(package private) static java.lang.String |
pathOfClass(java.lang.String className)
Get the path name of a class.
|
static void |
registerContentHandlerFactoryModule(Module module)
Register an additional module which contains content handlers.
|
static void |
registerURLStreamHandlerFactoryModule(Module module)
Register an additional module which contains URL handlers.
|
(package private) void |
relink() |
(package private) void |
relinkIfNecessary() |
void |
run(java.lang.String[] args)
Run a module's main class, if any.
|
(package private) void |
setDependencies(DependencySpec[] dependencySpecs) |
(package private) void |
setDependencies(java.util.List<DependencySpec> dependencySpecs) |
static void |
setModuleLogger(ModuleLogger logger)
Change the logger used by the module system.
|
java.lang.String |
toString()
Get the string representation of this module.
|
private static final java.util.concurrent.atomic.AtomicReference<ModuleLoader> BOOT_MODULE_LOADER
static final java.lang.String[] systemPackages
static final java.lang.String[] systemPaths
static final ModulesPrivateAccess PRIVATE_ACCESS
static volatile ModuleLogger log
setModuleLogger(org.jboss.modules.log.ModuleLogger)
.private static final FastCopyHashSet<ClassFilter> EMPTY_CLASS_FILTERS
private static final FastCopyHashSet<PathFilter> EMPTY_PATH_FILTERS
private final ModuleIdentifier identifier
private final java.lang.String mainClassName
null
).private final ModuleClassLoader moduleClassLoader
private final ModuleLoader moduleLoader
private final LocalLoader fallbackLoader
private final java.util.Map<java.lang.String,java.lang.String> properties
private final java.security.PermissionCollection permissionCollection
private volatile Linkage linkage
private static final java.lang.RuntimePermission GET_DEPENDENCIES
private static final java.lang.RuntimePermission GET_CLASS_LOADER
private static final java.lang.RuntimePermission GET_BOOT_MODULE_LOADER
private static final java.lang.RuntimePermission ACCESS_MODULE_LOGGER
private static final java.lang.RuntimePermission ADD_CONTENT_HANDLER_FACTORY
private static final java.lang.RuntimePermission ADD_URL_STREAM_HANDLER_FACTORY
private static final java.security.PermissionCollection NO_PERMISSIONS
Module(ConcreteModuleSpec spec, ModuleLoader moduleLoader)
spec
- the module specificationmoduleLoader
- the module loaderpublic static ModulesPrivateAccess getPrivateAccess()
SecurityException
for user code.java.lang.SecurityException
- alwaysprivate static java.security.PermissionCollection noPermissions()
private static java.security.PermissionCollection copyPermissions(java.security.PermissionCollection permissionCollection)
LocalLoader getFallbackLoader()
Dependency[] getDependenciesInternal()
DependencySpec[] getDependencySpecsInternal()
ModuleClassLoader getClassLoaderPrivate()
public DependencySpec[] getDependencies() throws java.lang.SecurityException
java.lang.SecurityException
- if a security manager is enabled and the caller does not have the getDependencies
RuntimePermission
public Resource getExportedResource(java.lang.String rootPath, java.lang.String resourcePath)
rootPath
- the module root to searchresourcePath
- the path of the resourcepublic void run(java.lang.String[] args) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.ClassNotFoundException
args
- the arguments to passjava.lang.NoSuchMethodException
- if there is no main methodjava.lang.reflect.InvocationTargetException
- if the main method failedjava.lang.ClassNotFoundException
- if the main class is not foundpublic ModuleIdentifier getIdentifier()
public ModuleLoader getModuleLoader()
public <S> java.util.ServiceLoader<S> loadService(java.lang.Class<S> serviceType)
S
- the service typeserviceType
- the service type classpublic <S> java.util.ServiceLoader<S> loadServiceDirectly(java.lang.Class<S> serviceType)
S
- the service typeserviceType
- the service type classpublic static <S> java.util.ServiceLoader<S> loadServiceFromCallerModuleLoader(ModuleIdentifier identifier, java.lang.Class<S> serviceType) throws ModuleLoadException
loadService(Class)
is more efficient since it does not need to crawl
the stack.S
- the the service typeidentifier
- the module identifier containing the service loaderserviceType
- the service type classModuleLoadException
- if the named module failed to loadpublic ModuleClassLoader getClassLoader()
If a security manager is present, then this method invokes the security manager's checkPermission
method
with a RuntimePermission("getClassLoader")
permission to verify access to the class loader. If
access is not granted, a SecurityException
will be thrown.
public java.util.Set<java.lang.String> getExportedPaths()
public static Module forClass(java.lang.Class<?> clazz)
null
if the class did not come from any module.clazz
- the classpublic static Module forClassLoader(java.lang.ClassLoader cl, boolean search)
null
if the class loader is not associated with any module. If
the class loader is unknown, it is possible to check the parent class loader up the chain, and so on until a module is found.cl
- the class loadersearch
- true
to search up the delegation chainpublic static ModuleLoader getBootModuleLoader()
boot.module.loader
system
property.static void initBootModuleLoader(ModuleLoader loader)
public static ModuleLoader getCallerModuleLoader()
null
if this method is called outside of a modulepublic static ModuleLoader getContextModuleLoader()
null
is returned.null
if none is setpublic static Module getModuleFromCallerModuleLoader(ModuleIdentifier identifier) throws ModuleLoadException
identifier
- the module identifierModuleLoadException
- if the module could not be loadedgetCallerModuleLoader()
public static Module getCallerModule()
public Module getModule(ModuleIdentifier identifier) throws ModuleLoadException
identifier
- the module identifierModuleLoadException
- if an error occurspublic static java.lang.Class<?> loadClassFromBootModuleLoader(ModuleIdentifier moduleIdentifier, java.lang.String className) throws ModuleLoadException, java.lang.ClassNotFoundException
moduleIdentifier
- the identifier of the module from which the class
should be loadedclassName
- the class name to loadModuleLoadException
- if the module could not be loadedjava.lang.ClassNotFoundException
- if the class could not be loadedgetBootModuleLoader()
public static java.lang.Class<?> loadClassFromCallerModuleLoader(ModuleIdentifier moduleIdentifier, java.lang.String className) throws ModuleLoadException, java.lang.ClassNotFoundException
moduleIdentifier
- the identifier of the module from which the class
should be loadedclassName
- the class name to loadModuleLoadException
- if the module could not be loadedjava.lang.ClassNotFoundException
- if the class could not be loadedgetCallerModuleLoader()
java.lang.Class<?> loadModuleClass(java.lang.String className, boolean resolve) throws java.lang.ClassNotFoundException
className
- the class nameresolve
- true
to resolve the class after definitionjava.lang.ClassNotFoundException
java.net.URL getResource(java.lang.String name)
name
- the resource namenull
if not foundjava.io.InputStream getResourceAsStream(java.lang.String name) throws java.io.IOException
name
- the resource namenull
if not foundjava.io.IOException
java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
name
- the resource namepublic java.net.URL getExportedResource(java.lang.String name)
name
- the resource namenull
if it was not foundpublic java.util.Enumeration<java.net.URL> getExportedResources(java.lang.String name)
name
- the resource namepublic java.util.Iterator<Resource> iterateResources(PathFilter filter) throws ModuleLoadException
filter
- the filter to apply to the searchModuleLoadException
- if linking a dependency module fails for some reasonpublic java.util.Iterator<Resource> globResources(java.lang.String glob) throws ModuleLoadException
glob
- the glob to applyModuleLoadException
- if linking a dependency module fails for some reasonpublic java.util.Set<java.lang.String> getImportedPaths() throws ModuleLoadException
ModuleLoadException
- if the module was previously unlinked, and there was an exception while linkingstatic java.lang.String pathOfClass(java.lang.String className)
className
- the binary name of the classstatic java.lang.String pathOf(java.lang.String resourceName)
resourceName
- the resource namestatic java.lang.String fileNameOfClass(java.lang.String className)
className
- the class namepublic java.lang.String getProperty(java.lang.String name)
null
if none was defined.name
- the property namepublic java.lang.String getProperty(java.lang.String name, java.lang.String defaultVal)
name
- the property namedefaultVal
- the default valuepublic java.util.List<java.lang.String> getPropertyNames()
public java.lang.String toString()
toString
in class java.lang.Object
public static ModuleLogger getModuleLogger()
If a security manager is present, then this method invokes the security manager's checkPermission
method
with a RuntimePermission("accessModuleLogger")
permission to verify access to the module logger. If
access is not granted, a SecurityException
will be thrown.
public static void setModuleLogger(ModuleLogger logger)
If a security manager is present, then this method invokes the security manager's checkPermission
method
with a RuntimePermission("accessModuleLogger")
permission to verify access to the module logger. If
access is not granted, a SecurityException
will be thrown.
logger
- the new logger, must not be null
public static long getStartTime()
public static void registerContentHandlerFactoryModule(Module module)
If a security manager is present, then this method invokes the security manager's checkPermission
method
with a RuntimePermission("addContentHandlerFactory")
permission to verify access. If
access is not granted, a SecurityException
will be thrown.
module
- the module to addpublic static void registerURLStreamHandlerFactoryModule(Module module)
If a security manager is present, then this method invokes the security manager's checkPermission
method
with a RuntimePermission("addURLStreamHandlerFactory")
permission to verify access. If
access is not granted, a SecurityException
will be thrown.
module
- the module to addpublic static java.lang.String getPlatformIdentifier()
public java.security.PermissionCollection getPermissionCollection()
private long addPaths(Dependency[] dependencies, java.util.Map<java.lang.String,java.util.List<LocalLoader>> map, FastCopyHashSet<PathFilter> filterStack, FastCopyHashSet<ClassFilter> classFilterStack, FastCopyHashSet<PathFilter> resourceFilterStack, java.util.Set<Module.Visited> visited) throws ModuleLoadException
ModuleLoadException
private LocalLoader createPathFilteredLocalLoader(PathFilter filter, LocalLoader localLoader)
private LocalLoader createClassFilteredLocalLoader(ClassFilter filter, LocalLoader localLoader)
private long addExportedPaths(Dependency[] dependencies, java.util.Map<java.lang.String,java.util.List<LocalLoader>> map, FastCopyHashSet<PathFilter> filterStack, FastCopyHashSet<ClassFilter> classFilterStack, FastCopyHashSet<PathFilter> resourceFilterStack, java.util.Set<Module.Visited> visited) throws ModuleLoadException
ModuleLoadException
java.util.Map<java.lang.String,java.util.List<LocalLoader>> getPaths() throws ModuleLoadException
ModuleLoadException
java.util.Map<java.lang.String,java.util.List<LocalLoader>> getPathsUnchecked()
void link(Linkage linkage) throws ModuleLoadException
ModuleLoadException
void relinkIfNecessary() throws ModuleLoadException
ModuleLoadException
void relink() throws ModuleLoadException
ModuleLoadException
void setDependencies(java.util.List<DependencySpec> dependencySpecs)
void setDependencies(DependencySpec[] dependencySpecs)
private Dependency[] calculateDependencies(DependencySpec[] dependencySpecs)
java.lang.String getMainClass()
java.lang.Package getPackage(java.lang.String name)
java.lang.Package[] getPackages()