org.ungoverned.moduleloader
Class Module

java.lang.Object
  extended by org.ungoverned.moduleloader.Module

public class Module
extends java.lang.Object

The Module class is a grouping mechanism for application classes and resources. Conceptually, most applications are grouped into entities such as JAR files (containing classes and resources) and native libraries. In some cases, these entities are core application classes and resources, while in other cases, these entities are ancillary, such as dynamically loaded plug-ins. Applications place some level of semantics onto these types of entities or modules, but for the ModuleLoader, no particular semantics are attached to modules (other than they are a grouping mechanism for classes and resources). This means that the application is free to map itself into modules any way that is appropriate.

A module has the following features:

A module's identifier must be unique within the scope of its ModuleManager, but there is no meaning associated with it. The set of attribute-value pairs attached to the module have no meaning to the ModuleManager, nor does it consult them at all. The point of these attributes is to attach meta-data for use by SearchPolicy implementations. Attributes are represented as an array of Object arrays, i.e., Object[][]. Each element in the attribute array is a two-element Object array, where Module.KEY_IDX is the attribute's key and Module.VALUE_IDX is the attribute's value.

The actual contents of a module is contained in two sets of sources for its resources and native libraries, ResourceSources and LibrarySources, respectively. Each module also has a ModuleClassLoader associated with it. The ModuleClassLoader consults these two types of sources to find classes, resources, and native libraries.

See Also:
ModuleManager, ModuleClassLoader, ResourceSource, LibrarySource

Field Summary
static int KEY_IDX
          This is the index used to retrieve the key of an attribute; an attribute is represented as an Object[] instance.
static int VALUE_IDX
          This is the index used to retrieve the value of an attribute; an attribute is represented as an Object[] instance.
 
Constructor Summary
Module(ModuleManager mgr, java.lang.String id, java.lang.Object[][] attributes, ResourceSource[] resSources, LibrarySource[] libSources)
           Constructs a Module instance that will be associated with the specified ModuleManager and will have the specified identifier, attributes, resource sources, and library sources.
 
Method Summary
protected  void dispose()
           Disposes the module by closing all resource and library sources.
 java.lang.Object getAttribute(java.lang.String key)
           Returns the attribute value associated with the specified key.
 java.lang.Object[][] getAttributes()
           Returns the attribute set associated with this module.
 ModuleClassLoader getClassLoader()
           Returns the ModuleClassLoader associated with this module.
 java.lang.String getId()
           Returns the identifier of the module.
 LibrarySource[] getLibrarySources()
           Returns the array of LibrarySources associated with the module.
 ResourceSource[] getResourceSources()
           Returns the array of ResourceSources associated with the module.
protected  void reset(java.lang.Object[][] attributes, ResourceSource[] resSources, LibrarySource[] libSources)
           Resets the module by throwing away its associated class loader and re-initializing its attributes, resource sources, and library sources with the specified values.
 void setAttribute(java.lang.String key, java.lang.Object value)
           Sets the attribute value associated with the specified key.
 java.lang.String toString()
           Returns the module's identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_IDX

public static final int KEY_IDX
This is the index used to retrieve the key of an attribute; an attribute is represented as an Object[] instance.

See Also:
Constant Field Values

VALUE_IDX

public static final int VALUE_IDX
This is the index used to retrieve the value of an attribute; an attribute is represented as an Object[] instance.

See Also:
Constant Field Values
Constructor Detail

Module

public Module(ModuleManager mgr,
              java.lang.String id,
              java.lang.Object[][] attributes,
              ResourceSource[] resSources,
              LibrarySource[] libSources)

Constructs a Module instance that will be associated with the specified ModuleManager and will have the specified identifier, attributes, resource sources, and library sources. In general, modules should not be created directly, but should be created by making a call to ModuleManager.addModule().

Parameters:
mgr - the ModuleManager that will be associated to the instance.
id - the identifier of the instance.
attributes - the set of attributes associated with the instance.
resSources - the set of ResourceSources associated with the instance.
libSources - the set of LibrarySources associated with the instance.
See Also:
ModuleManager, ResourceSource, LibrarySource
Method Detail

getId

public java.lang.String getId()

Returns the identifier of the module.

Returns:
the identifier of the module.

getAttributes

public java.lang.Object[][] getAttributes()

Returns the attribute set associated with this module. Attributes are represented as an array of Object arrays, i.e., Object[][]. Each element in the attribute array is two-element Object array, where Module.KEY_IDX is the index to the attribute key and Module.VALUE_IDX is the index to the attribute value. The returned array is a copy and may be freely modified.

Returns:
the attribute set associated with this module.

getAttribute

public java.lang.Object getAttribute(java.lang.String key)

Returns the attribute value associated with the specified key.

Parameters:
key - the key of the attribute whose value is to be retrieved.
Returns:
the attribute's value or null.

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object value)

Sets the attribute value associated with the specified key. The attribute will be added if it does not currently exist.

Parameters:
key - the key of the attribute whose value is to be set.
value - the new value to be associated with the attribute key.

getResourceSources

public ResourceSource[] getResourceSources()

Returns the array of ResourceSources associated with the module. The returned array is not a copy and therefore should not be modified.

Returns:
the array of ResourceSources associated with the module.
See Also:
ResourceSource

getLibrarySources

public LibrarySource[] getLibrarySources()

Returns the array of LibrarySources associated with the module. The returned array is not a copy and therefore should not be modified.

Returns:
the array of LibrarySources associated with the module.
See Also:
LibrarySource

getClassLoader

public ModuleClassLoader getClassLoader()

Returns the ModuleClassLoader associated with this module. If a security manager is installed, then this method uses a privileged action to avoid a security exception being thrown to the caller.

Returns:
the ModuleClassLoader associated with this module.
See Also:
ModuleClassLoader

toString

public java.lang.String toString()

Returns the module's identifier.

Overrides:
toString in class java.lang.Object
Returns:
the module's identifier.

reset

protected void reset(java.lang.Object[][] attributes,
                     ResourceSource[] resSources,
                     LibrarySource[] libSources)

Resets the module by throwing away its associated class loader and re-initializing its attributes, resource sources, and library sources with the specified values.

Parameters:
attributes - the new attributes to be associated with the module.
resSources - the new resource sources to be associated with the module.
libSources - the new library sources to be associated with the module.
See Also:
ResourceSource, LibrarySource

dispose

protected void dispose()

Disposes the module by closing all resource and library sources.