org.jboss.modules
Class Module

java.lang.Object
  extended by org.jboss.modules.Module

public final class Module
extends Object

A module is a unit of classes and other resources, along with the specification of what is imported and exported by this module from and to other modules. Modules are created by ModuleLoaders which build modules from various configuration information and resource roots.

Author:
David M. Lloyd, John Bailey, Flavia Rainone, Jason T. Greene, thomas.diesler@jboss.com

Method Summary
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.
static Module getCurrentModule()
          Deprecated. use getCallerModule() instead.
static ModuleLoader getCurrentModuleLoader()
          Deprecated. use getCallerModuleLoader() instead.
 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.
 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.
static Module getModuleFromCurrentLoader(ModuleIdentifier identifier)
          Deprecated. use getModuleFromCallerModuleLoader(ModuleIdentifier) instead.
 ModuleLoader getModuleLoader()
          Get the module loader which created this module.
static ModuleLogger getModuleLogger()
          Get the logger used by the module system.
static long getStartTime()
          Return the start time in millis when Module.class was loaded.
static Module getSystemModule()
          Get the system module.
static ModuleLoader getSystemModuleLoader()
          Deprecated. Use getBootModuleLoader(). This method will be removed.
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.
static Class<?> loadClassFromCurrentLoader(ModuleIdentifier moduleIdentifier, String className)
          Deprecated. use loadClassFromCallerModuleLoader(ModuleIdentifier, String) instead.
static Class<?> loadClassFromSystemLoader(ModuleIdentifier moduleIdentifier, String className)
          Deprecated. use loadClassFromBootModuleLoader(ModuleIdentifier, String) instead.
<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
<S> ServiceLoader<S>
loadServiceFromCurrent(ModuleIdentifier identifier, Class<S> serviceType)
          Deprecated. use loadServiceFromCallerModuleLoader(ModuleIdentifier, 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.
static void setModuleLogger(ModuleLogger logger)
          Change the logger used by the module system.
 String toString()
          Get the string representation of this module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getSystemModule

public static Module getSystemModule()
Get the system module.

Returns:
the system module

getExportedResource

public Resource getExportedResource(String rootPath,
                                    String resourcePath)
Get an exported resource from a specific root in this module.

Parameters:
rootPath - the module root to search
resourcePath - the path of the resource
Returns:
the resource

run

public void run(String[] args)
         throws NoSuchMethodException,
                InvocationTargetException,
                ClassNotFoundException
Run a module's main class, if any.

Parameters:
args - the arguments to pass
Throws:
NoSuchMethodException - if there is no main method
InvocationTargetException - if the main method failed
ClassNotFoundException - if the main class is not found

getIdentifier

public ModuleIdentifier getIdentifier()
Get this module's identifier.

Returns:
the identifier

getModuleLoader

public ModuleLoader getModuleLoader()
Get the module loader which created this module.

Returns:
the module loader of this module

loadService

public <S> ServiceLoader<S> loadService(Class<S> serviceType)
Load a service loader from this module.

Type Parameters:
S - the service type
Parameters:
serviceType - the service type class
Returns:
the service loader

loadServiceFromCallerModuleLoader

public static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(ModuleIdentifier identifier,
                                                                     Class<S> serviceType)
                                                          throws ModuleLoadException
Load a service loader from a module in the caller's module loader. The caller's module loader refers to the loader of the module of the class that calls this method. Note that loadService(Class) is more efficient since it does not need to crawl the stack.

Type Parameters:
S - the the service type
Parameters:
identifier - the module identifier containing the service loader
serviceType - the service type class
Returns:
the loaded service from the caller's module
Throws:
ModuleLoadException - if the named module failed to load

loadServiceFromCurrent

@Deprecated
public static <S> ServiceLoader<S> loadServiceFromCurrent(ModuleIdentifier identifier,
                                                                     Class<S> serviceType)
                                               throws ModuleLoadException
Deprecated. use loadServiceFromCallerModuleLoader(ModuleIdentifier, Class) instead.

Throws:
ModuleLoadException

getClassLoader

public ModuleClassLoader getClassLoader()
Get the class loader for a module. The class loader can be used to access non-exported classes and resources of the module.

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.

Returns:
the module class loader

getExportedPaths

public Set<String> getExportedPaths()
Get all the paths exported by this module.

Returns:
the paths that are exported by this module

forClass

public static Module forClass(Class<?> clazz)
Get the module for a loaded class, or null if the class did not come from any module.

Parameters:
clazz - the class
Returns:
the module it came from

forClassLoader

public 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. 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.

Parameters:
cl - the class loader
search - true to search up the delegation chain
Returns:
the associated module

getBootModuleLoader

public static ModuleLoader getBootModuleLoader()
Gets the boot module loader. The boot module loader is the initial loader that is established by the module framework. It typically is based off of the environmental module path unless it is overridden by specifying a different class name for the boot.module.loader system property.

Returns:
the boot module loader

getSystemModuleLoader

@Deprecated
public static ModuleLoader getSystemModuleLoader()
Deprecated. Use getBootModuleLoader(). This method will be removed.

Returns:
the boot module loader

getCallerModuleLoader

public static ModuleLoader getCallerModuleLoader()
Gets the current module loader. The current module loader is the loader of the module from the calling class. Note that this method must crawl the stack to determine this, so other mechanisms are more efficient

Returns:
the current module loader

getCurrentModuleLoader

@Deprecated
public static ModuleLoader getCurrentModuleLoader()
Deprecated. use getCallerModuleLoader() instead.


getContextModuleLoader

public static ModuleLoader getContextModuleLoader()
Get the current thread's context module loader. This loader is the one which defined the module whose class loader is, or is a parent of, the thread's current context class loader. If there is none, then null is returned.

Returns:
the module loader, or null if none is set

getModuleFromCallerModuleLoader

public static Module getModuleFromCallerModuleLoader(ModuleIdentifier identifier)
                                              throws ModuleLoadException
Get a module from the current module loader. Note that this must crawl the stack to determine this, so other mechanisms are more efficient.

Parameters:
identifier - the module identifier
Returns:
the module
Throws:
ModuleLoadException - if the module could not be loaded
See Also:
getCallerModuleLoader()

getModuleFromCurrentLoader

@Deprecated
public static Module getModuleFromCurrentLoader(ModuleIdentifier identifier)
                                         throws ModuleLoadException
Deprecated. use getModuleFromCallerModuleLoader(ModuleIdentifier) instead.

Throws:
ModuleLoadException

getCallerModule

public static Module getCallerModule()
Get the caller's module. The caller's module is the module containing the method that calls this method. Note that this method crawls the stack so other ways of obtaining the module are more efficient.

Returns:
the current module

getCurrentModule

@Deprecated
public static Module getCurrentModule()
Deprecated. use getCallerModule() instead.


getModule

public Module getModule(ModuleIdentifier identifier)
                 throws ModuleLoadException
Get the module with the given identifier from the module loader used by this module.

Parameters:
identifier - the module identifier
Returns:
the module
Throws:
ModuleLoadException - if an error occurs

loadClassFromBootModuleLoader

public static Class<?> loadClassFromBootModuleLoader(ModuleIdentifier moduleIdentifier,
                                                     String className)
                                              throws ModuleLoadException,
                                                     ClassNotFoundException
Load a class from a module in the system module loader.

Parameters:
moduleIdentifier - the identifier of the module from which the class should be loaded
className - the class name to load
Returns:
the class
Throws:
ModuleLoadException - if the module could not be loaded
ClassNotFoundException - if the class could not be loaded
See Also:
getBootModuleLoader()

loadClassFromSystemLoader

@Deprecated
public static Class<?> loadClassFromSystemLoader(ModuleIdentifier moduleIdentifier,
                                                            String className)
                                          throws ModuleLoadException,
                                                 ClassNotFoundException
Deprecated. use loadClassFromBootModuleLoader(ModuleIdentifier, String) instead.

Throws:
ModuleLoadException
ClassNotFoundException

loadClassFromCallerModuleLoader

public static Class<?> loadClassFromCallerModuleLoader(ModuleIdentifier moduleIdentifier,
                                                       String className)
                                                throws ModuleLoadException,
                                                       ClassNotFoundException
Load a class from a module in the caller's module loader.

Parameters:
moduleIdentifier - the identifier of the module from which the class should be loaded
className - the class name to load
Returns:
the class
Throws:
ModuleLoadException - if the module could not be loaded
ClassNotFoundException - if the class could not be loaded
See Also:
getCallerModuleLoader()

loadClassFromCurrentLoader

@Deprecated
public static Class<?> loadClassFromCurrentLoader(ModuleIdentifier moduleIdentifier,
                                                             String className)
                                           throws ModuleLoadException,
                                                  ClassNotFoundException
Deprecated. use loadClassFromCallerModuleLoader(ModuleIdentifier, String) instead.

Throws:
ModuleLoadException
ClassNotFoundException

getExportedResource

public URL getExportedResource(String name)
Get an exported resource URL.

Parameters:
name - the resource name
Returns:
the resource, or null if it was not found

getExportedResources

public Enumeration<URL> getExportedResources(String name)
Get all exported resource URLs for a resource name.

Parameters:
name - the resource name
Returns:
the resource URLs

toString

public String toString()
Get the string representation of this module.

Overrides:
toString in class Object
Returns:
the string representation

getModuleLogger

public static ModuleLogger getModuleLogger()
Get the logger used by the module system.

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.

Returns:
the module logger

setModuleLogger

public static void setModuleLogger(ModuleLogger logger)
Change the logger used by the module system.

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.

Parameters:
logger - the new logger, must not be null

getStartTime

public static long getStartTime()
Return the start time in millis when Module.class was loaded.

Returns:
start time of Module.class load

registerContentHandlerFactoryModule

public static void registerContentHandlerFactoryModule(Module module)
Register an additional module which contains content handlers.

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.

Parameters:
module - the module to add

registerURLStreamHandlerFactoryModule

public static void registerURLStreamHandlerFactoryModule(Module module)
Register an additional module which contains URL handlers.

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.

Parameters:
module - the module to add


Copyright © 2011. All Rights Reserved.