Module

public class Module extends Component

A Module is described by a module descriptor and contains zero to many components. Each module has its own classloader for loading its components, which are defined in the module descriptor, and its resources.

Author:Hugo Y. K. Lam

See also: Component

Constructors

Module

public Module(String descriptorLocation)

Creates and initializes a new instance of Module.

Parameters:
  • descriptorLocation – the module descriptor.
Throws:
  • ModuleException – if errors encountered when loading the module descriptor.

Module

public Module(String descriptorLocation, boolean shouldInitialize)

Creates a new instance of Module.

Parameters:
  • descriptorLocation – the module descriptor.
  • shouldInitialize – true if the module should be initialized.
Throws:
  • ModuleException – if errors encountered when loading the module descriptor.

Module

public Module(String descriptorLocation, ClassLoader loader)

Creates and initializes a new instance of Module.

Parameters:
  • descriptorLocation – the module descriptor.
  • loader – the class loader for this module.
Throws:
  • ModuleException – if errors encountered when loading the module descriptor.

Module

public Module(String descriptorLocation, ClassLoader loader, boolean shouldInitialize)

Creates a new instance of Module.

Parameters:
  • descriptorLocation – the module descriptor.
  • loader – the class loader for this module.
  • shouldInitialize – true if the module should be initialized.
Throws:
  • ModuleException – if errors encountered when loading the module descriptor.

Methods

createComponents

protected void createComponents()

Creates all the components defined in the module descriptor.

Throws:

getClassLoader

public ClassLoader getClassLoader()

Gets the class loader that this module uses to load classes.

Returns:the class loader for this module.

getComponent

public Component getComponent(String id)

Gets the specified component in this module.

Parameters:
  • id – the ID of the module component.
Returns:

the module component.

getComponentCount

public int getComponentCount()

Gets the number of components in this module.

Returns:the number of components in this module.

getComponents

public Collection getComponents()

Gets all the components in this module.

Returns:all module components

getDescriptor

public URL getDescriptor()

Gets the module descriptor.

Returns:the module descriptor.

getGroup

public ModuleGroup getGroup()

Gets the module group to which this module belongs.

Returns:the module group.

getLogger

public Logger getLogger()

Gets the logger of this module.

Returns:the logger of this module.

getRequiredParameter

protected String getRequiredParameter(String key)

Get the mandatory parameter from the current module, throw ModuleException if not found.

Parameters:
  • key – the key in the parameters list.
Throws:
Returns:

The value of the parameter if found.

getResource

public URL getResource(String name)

Gets a resource as URL.

Parameters:
  • name – the name of the resource.
Returns:

the URL of the resource.

See also: .getResource(String,ClassLoader)

getResource

public static URL getResource(String name, ClassLoader loader)

Gets a resource as URL.

The specified name can be an absolute path or a relative path to the current directory or classpaths.

If the specified name is a relative path, it will be searched through the current directory and then the classpaths.

Parameters:
  • name – the name of the resource.
  • loader – the class loader for finding the resource.
Returns:

the URL of the resource.

getResourceAsStream

public InputStream getResourceAsStream(String name)

Gets a resource as stream.

Parameters:
  • name – the name of the resource.
Returns:

an input stream of the resource.

See also: .getResource(String)

getString

protected String getString(String key)

Gets the string value of the specified key from the module descriptor.

Parameters:
  • key – the key in the resource bundle.
Returns:

the string value.

getVersion

public String getVersion()

Gets the version of this module.

Returns:the version of this module.

init

public void init()

Initializes the module and all its components.

Throws:

initComponents

protected void initComponents()

Initializes all the created components.

Throws:

setComponent

public void setComponent(Component component)

Sets a component to this module.

Parameters:
  • component – the component to be set.

setGroup

public void setGroup(ModuleGroup group)

Sets the module group to which this module belongs.

Parameters:
  • group – the module group.

toString

public String toString()

Returns a string representation of this module.

Returns:a string representation of this module.

See also: java.lang.Object.toString()