public final class Module extends Object
ModuleLoader
s which build modules from
various configuration information and resource roots.Modifier and Type | Method and Description |
---|---|
static Module |
forClass(Class<?> clazz)
Get the module for a loaded class, or
null if the class did not come from any module. |
static Module |
forClassLoader(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.
|
static ModuleLoader |
getContextModuleLoader()
Get the current thread's context module loader.
|
DependencySpec[] |
getDependencies()
Get the current dependencies of this module.
|
Set<String> |
getExportedPaths()
Get all the paths exported by this module.
|
URL |
getExportedResource(String name)
Get an exported resource URL.
|
Resource |
getExportedResource(String rootPath,
String resourcePath)
Get an exported resource from a specific root in this module.
|
Enumeration<URL> |
getExportedResources(String name)
Get all exported resource URLs for a resource name.
|
ModuleIdentifier |
getIdentifier()
Get this module's identifier.
|
Set<String> |
getImportedPaths()
Get the (unmodifiable) set of paths which are imported into this module class loader, including local paths.
|
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.
|
static String |
getPlatformIdentifier()
Get the platform identifier.
|
static ModulesPrivateAccess |
getPrivateAccess()
Private access for module internal code.
|
String |
getProperty(String name)
Get the property with the given name, or
null if none was defined. |
String |
getProperty(String name,
String defaultVal)
Get the property with the given name, or a default value if none was defined.
|
List<String> |
getPropertyNames()
Get a copy of the list of property names.
|
static long |
getStartTime()
Return the start time in millis when Module.class was loaded.
|
Iterator<Resource> |
globResources(String glob)
Enumerate all imported resources in this module which match the given glob expression.
|
Iterator<Resource> |
iterateResources(PathFilter filter)
Enumerate all the imported resources in this module, subject to a path filter.
|
static Class<?> |
loadClassFromBootModuleLoader(ModuleIdentifier moduleIdentifier,
String className)
Load a class from a module in the system module loader.
|
static Class<?> |
loadClassFromCallerModuleLoader(ModuleIdentifier moduleIdentifier,
String className)
Load a class from a module in the caller's module loader.
|
<S> ServiceLoader<S> |
loadService(Class<S> serviceType)
Load a service loader from this module.
|
static <S> ServiceLoader<S> |
loadServiceFromCallerModuleLoader(ModuleIdentifier identifier,
Class<S> serviceType)
Load a service loader from a module in the caller's module loader.
|
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.
|
void |
run(String[] args)
Run a module's main class, if any.
|
static void |
setModuleLogger(ModuleLogger logger)
Change the logger used by the module system.
|
String |
toString()
Get the string representation of this module.
|
public static ModulesPrivateAccess getPrivateAccess()
SecurityException
for user code.SecurityException
- alwayspublic DependencySpec[] getDependencies() throws SecurityException
SecurityException
- if a security manager is enabled and the caller does not have the getDependencies
RuntimePermission
public Resource getExportedResource(String rootPath, String resourcePath)
rootPath
- the module root to searchresourcePath
- the path of the resourcepublic void run(String[] args) throws NoSuchMethodException, InvocationTargetException, ClassNotFoundException
args
- the arguments to passNoSuchMethodException
- if there is no main methodInvocationTargetException
- if the main method failedClassNotFoundException
- if the main class is not foundpublic ModuleIdentifier getIdentifier()
public ModuleLoader getModuleLoader()
public <S> ServiceLoader<S> loadService(Class<S> serviceType)
S
- the service typeserviceType
- the service type classpublic static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(ModuleIdentifier identifier, 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 Set<String> getExportedPaths()
public static Module forClass(Class<?> clazz)
null
if the class did not come from any module.clazz
- the classpublic static Module forClassLoader(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.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 Class<?> loadClassFromBootModuleLoader(ModuleIdentifier moduleIdentifier, String className) throws ModuleLoadException, 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 loadedClassNotFoundException
- if the class could not be loadedgetBootModuleLoader()
public static Class<?> loadClassFromCallerModuleLoader(ModuleIdentifier moduleIdentifier, String className) throws ModuleLoadException, 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 loadedClassNotFoundException
- if the class could not be loadedgetCallerModuleLoader()
public URL getExportedResource(String name)
name
- the resource namenull
if it was not foundpublic Enumeration<URL> getExportedResources(String name)
name
- the resource namepublic Iterator<Resource> iterateResources(PathFilter filter) throws ModuleLoadException
filter
- the filter to apply to the searchModuleLoadException
- if linking a dependency module fails for some reasonpublic Iterator<Resource> globResources(String glob) throws ModuleLoadException
glob
- the glob to applyModuleLoadException
- if linking a dependency module fails for some reasonpublic final Set<String> getImportedPaths() throws ModuleLoadException
ModuleLoadException
- if the module was previously unlinked, and there was an exception while linkingpublic String getProperty(String name)
null
if none was defined.name
- the property namepublic String getProperty(String name, String defaultVal)
name
- the property namedefaultVal
- the default valuepublic List<String> getPropertyNames()
public String toString()
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 String getPlatformIdentifier()
Copyright © 2017 JBoss by Red Hat. All rights reserved.