public final class Module extends Object
ModuleLoader
s which build modules from
various configuration information and resource roots.Modifier and Type | Method | 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) |
Deprecated.
Resource root names are deprecated.
|
Enumeration<URL> |
getExportedResources(String name) |
Get all exported resource URLs for a resource name.
|
ModuleIdentifier |
getIdentifier() |
Deprecated.
Use
getName() instead. |
Set<String> |
getImportedPaths() |
Get the (unmodifiable) set of paths which are imported into this module class loader, including local paths.
|
Module |
getModule(String name) |
Get the module with the given identifier from the module loader used by this module.
|
Module |
getModule(ModuleIdentifier identifier) |
Deprecated.
Use
getModule(String) instead. |
static Module |
getModuleFromCallerModuleLoader(String name) |
Get a module from the current module loader.
|
static Module |
getModuleFromCallerModuleLoader(ModuleIdentifier identifier) |
Deprecated.
Use
getModuleFromCallerModuleLoader(String) instead. |
ModuleLoader |
getModuleLoader() |
Get the module loader which created this module.
|
static ModuleLogger |
getModuleLogger() |
Get the logger used by the module system.
|
String |
getName() |
Get this module's name.
|
PermissionCollection |
getPermissionCollection() |
Get the module's configured permission collection.
|
static String |
getPlatformIdentifier() |
Get the platform identifier.
|
static org.jboss.modules._private.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.
|
static ModuleLoader |
getSystemModuleLoader() |
Get the system module loader.
|
Version |
getVersion() |
Get the module version.
|
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(String name,
String className) |
Load a class from a module in the system module loader.
|
static Class<?> |
loadClassFromBootModuleLoader(ModuleIdentifier moduleIdentifier,
String className) |
Deprecated.
Use
loadClassFromBootModuleLoader(String, String) instead. |
static Class<?> |
loadClassFromCallerModuleLoader(String name,
String className) |
Load a class from a module in the caller's module loader.
|
static Class<?> |
loadClassFromCallerModuleLoader(ModuleIdentifier moduleIdentifier,
String className) |
Deprecated.
Use
loadClassFromCallerModuleLoader(String, String) instead. |
<S> ServiceLoader<S> |
loadService(Class<S> serviceType) |
Load a service loader from this module.
|
<S> ServiceLoader<S> |
loadServiceDirectly(Class<S> serviceType) |
Load a service loader from this module, without looking at dependencies.
|
static <S> ServiceLoader<S> |
loadServiceFromCallerModuleLoader(String name,
Class<S> serviceType) |
Load a service loader from a module in the caller's module loader.
|
static <S> ServiceLoader<S> |
loadServiceFromCallerModuleLoader(ModuleIdentifier identifier,
Class<S> serviceType) |
Deprecated.
Use
loadServiceFromCallerModuleLoader(String, Class) instead. |
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.
|
void |
run(String className,
String[] args) |
Run the given main class in this module.
|
static void |
setModuleLogger(ModuleLogger logger) |
Change the logger used by the module system.
|
String |
toString() |
Get the string representation of this module.
|
public static org.jboss.modules._private.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
@Deprecated 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 void run(String className, String[] args) throws NoSuchMethodException, InvocationTargetException, ClassNotFoundException
className
- the class name to run (must not be null
)args
- the arguments to passNoSuchMethodException
- if there is no main methodInvocationTargetException
- if the main method failedClassNotFoundException
- if the main class is not found@Deprecated public ModuleIdentifier getIdentifier()
getName()
instead.public String getName()
public ModuleLoader getModuleLoader()
public <S> ServiceLoader<S> loadService(Class<S> serviceType)
S
- the service typeserviceType
- the service type classpublic <S> ServiceLoader<S> loadServiceDirectly(Class<S> serviceType)
S
- the service typeserviceType
- the service type class@Deprecated public static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(ModuleIdentifier identifier, Class<S> serviceType) throws ModuleLoadException
loadServiceFromCallerModuleLoader(String, Class)
instead.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 static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(String name, Class<S> serviceType) throws ModuleLoadException
loadService(Class)
is more efficient since it does not need to crawl
the stack.S
- the the service typename
- the module name 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 getSystemModuleLoader()
org.jboss.modules
.public static ModuleLoader getCallerModuleLoader()
null
if this method is called outside of a modulepublic static ModuleLoader getContextModuleLoader()
null
is returned.null
if none is set@Deprecated public static Module getModuleFromCallerModuleLoader(ModuleIdentifier identifier) throws ModuleLoadException
getModuleFromCallerModuleLoader(String)
instead.identifier
- the module identifierModuleLoadException
- if the module could not be loadedgetCallerModuleLoader()
public static Module getModuleFromCallerModuleLoader(String name) throws ModuleLoadException
name
- the module nameModuleLoadException
- if the module could not be loadedgetCallerModuleLoader()
public static Module getCallerModule()
@Deprecated public Module getModule(ModuleIdentifier identifier) throws ModuleLoadException
getModule(String)
instead.identifier
- the module identifierModuleLoadException
- if an error occurspublic Module getModule(String name) throws ModuleLoadException
name
- the module nameModuleLoadException
- if an error occurs@Deprecated public static Class<?> loadClassFromBootModuleLoader(ModuleIdentifier moduleIdentifier, String className) throws ModuleLoadException, ClassNotFoundException
loadClassFromBootModuleLoader(String, String)
instead.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<?> loadClassFromBootModuleLoader(String name, String className) throws ModuleLoadException, ClassNotFoundException
name
- the name 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
loadClassFromCallerModuleLoader(String, String)
instead.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 static Class<?> loadClassFromCallerModuleLoader(String name, String className) throws ModuleLoadException, ClassNotFoundException
name
- the name 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 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 Version getVersion()
null
if none was setpublic 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()
public PermissionCollection getPermissionCollection()
Copyright © 2022 JBoss by Red Hat. All rights reserved.