The abstract module provides a default implementation of the module interface.
The module can be specified in an external property file. The file name of this
specification defaults to "module.properties". This file is no real property file,
it follows a more complex rule set.
Lines starting with '#' are considered comments.
Section headers start at the beginning of the line, section properties
are indented with at least one whitespace.
The first section is always the module info and contains the basic module
properties like name, version and a short description.
The properties name, producer and description are simple strings. They may
span multiple lines, but may not contain a colon (':').
The version properties are integer values.
This section may be followed by one or more "depends" sections. These
sections describe the base modules that are required to be active to make this
module work. The package manager will enforce this policy and will deactivate this
module if one of the base modules is missing.
The property module references to the module implementation of the module package.
| Method from org.jfree.base.modules.AbstractModule Detail: |
public void configure(SubSystem subSystem) {
final InputStream in = ObjectUtilities.getResourceRelativeAsStream
("configuration.properties", getClass());
if (in == null)
{
return;
}
try
{
subSystem.getPackageManager().getPackageConfiguration().load(in);
}
finally
{
try
{
in.close();
}
catch (IOException e)
{
// can be ignored ...
}
}
}
Configures the module by loading the configuration properties and
adding them to the package configuration. |
public String getDescription() {
return this.description;
}
Returns the module description. |
public String getName() {
return this.name;
}
Returns the name of this module. |
public ModuleInfo[] getOptionalModules() {
final ModuleInfo[] retval = new ModuleInfo[this.optionalModules.length];
System.arraycopy(this.optionalModules, 0, retval, 0, this.optionalModules.length);
return retval;
}
Returns a copy of the required modules array. This array contains all
description of the optional modules that may improve the modules functonality. |
public String getProducer() {
return this.producer;
}
Returns the producer of the module. |
public ModuleInfo[] getRequiredModules() {
final ModuleInfo[] retval = new ModuleInfo[this.requiredModules.length];
System.arraycopy(this.requiredModules, 0, retval, 0, this.requiredModules.length);
return retval;
}
Returns a copy of the required modules array. This array contains all
description of the modules that need to be present to make this module work. |
public String getSubSystem() {
if (this.subsystem == null)
{
return getName();
}
return this.subsystem;
}
Returns the modules subsystem. If this module is not part of an subsystem
then return the modules name, but never null. |
protected static boolean isClassLoadable(String name) {
try
{
final ClassLoader loader = ObjectUtilities.getClassLoader(AbstractModule.class);
if (loader == null)
{
// this should not happen .. If it happens, it measn we dont even have a system-classloader.
return false;
}
loader.loadClass(name);
return true;
}
catch (Exception e)
{
return false;
}
} Deprecated! use - the method that passes in a context-class.
Tries to load a class to indirectly check for the existence
of a certain library. |
protected static boolean isClassLoadable(String name,
Class context) {
try
{
ObjectUtilities.getClassLoader(context).loadClass(name);
return true;
}
catch (Exception e)
{
return false;
}
}
Tries to load a class to indirectly check for the existence
of a certain library. |
protected void loadModuleInfo() throws ModuleInitializeException {
final InputStream in = ObjectUtilities.getResourceRelativeAsStream
("module.properties", getClass());
if (in == null)
{
throw new ModuleInitializeException
("File 'module.properties' not found in module package.");
}
loadModuleInfo(in);
}
Loads the default module description from the file "module.properties". This file
must be in the same package as the implementing class. |
protected void loadModuleInfo(InputStream in) throws ModuleInitializeException {
if (in == null)
{
throw new NullPointerException
("Given InputStream is null.");
}
try
{
final ArrayList optionalModules = new ArrayList();
final ArrayList dependendModules = new ArrayList();
final ReaderHelper rh = new ReaderHelper(new BufferedReader
(new InputStreamReader(in, "ISO-8859-1")));
try
{
while (rh.hasNext())
{
final String lastLineRead = rh.next();
if (lastLineRead.startsWith("module-info:"))
{
readModuleInfo(rh);
}
else if (lastLineRead.startsWith("depends:"))
{
dependendModules.add(readExternalModule(rh));
}
else if (lastLineRead.startsWith("optional:"))
{
optionalModules.add(readExternalModule(rh));
}
else
{
// we dont understand the current line, so we skip it ...
// should we throw a parse exception instead?
}
}
}
finally
{
rh.close();
}
this.optionalModules = (ModuleInfo[])
optionalModules.toArray(new ModuleInfo[optionalModules.size()]);
this.requiredModules = (ModuleInfo[])
dependendModules.toArray(new ModuleInfo[dependendModules.size()]);
}
catch (IOException ioe)
{
throw new ModuleInitializeException("Failed to load properties", ioe);
}
}
Loads the module descriptiong from the given input stream. The module description
must conform to the rules define in the class description. The file must be encoded
with "ISO-8859-1" (like property files). |
protected void performExternalInitialize(String classname) throws ModuleInitializeException {
try
{
final ModuleInitializer mi =
(ModuleInitializer) ObjectUtilities.loadAndInstantiate(classname, AbstractModule.class, ModuleInitializer.class);
if (mi == null)
{
throw new ModuleInitializeException("Failed to load specified initializer class.");
}
mi.performInit();
}
catch (ModuleInitializeException mie)
{
throw mie;
}
catch (Exception e)
{
throw new ModuleInitializeException("Failed to load specified initializer class.", e);
}
} Deprecated! Use - the method that provides a class-context instead.
Tries to load an module initializer and uses this initializer to initialize
the module. |
protected void performExternalInitialize(String classname,
Class context) throws ModuleInitializeException {
try
{
final ModuleInitializer mi =
(ModuleInitializer) ObjectUtilities.loadAndInstantiate(classname, context, ModuleInitializer.class);
if (mi == null)
{
throw new ModuleInitializeException("Failed to load specified initializer class.");
}
mi.performInit();
}
catch (ModuleInitializeException mie)
{
throw mie;
}
catch (Exception e)
{
throw new ModuleInitializeException("Failed to load specified initializer class.", e);
}
}
|
protected void setDescription(String description) {
this.description = description;
}
Defines the description of the module. |
protected void setName(String name) {
this.name = name;
}
Defines the name of the module. |
public void setOptionalModules(ModuleInfo[] optionalModules) {
this.optionalModules = new ModuleInfo[optionalModules.length];
System.arraycopy(optionalModules, 0, this.optionalModules, 0, optionalModules.length);
}
Defines the optional module descriptions for this module. |
protected void setProducer(String producer) {
this.producer = producer;
}
Defines the producer of the module. |
protected void setRequiredModules(ModuleInfo[] requiredModules) {
this.requiredModules = new ModuleInfo[requiredModules.length];
System.arraycopy(requiredModules, 0, this.requiredModules, 0, requiredModules.length);
}
Defines the required module descriptions for this module. |
protected void setSubSystem(String name) {
this.subsystem = name;
}
Defines the subsystem name for this module. |
public String toString() {
final StringBuffer buffer = new StringBuffer();
buffer.append("Module : ");
buffer.append(getName());
buffer.append("\n");
buffer.append("ModuleClass : ");
buffer.append(getModuleClass());
buffer.append("\n");
buffer.append("Version: ");
buffer.append(getMajorVersion());
buffer.append(".");
buffer.append(getMinorVersion());
buffer.append(".");
buffer.append(getPatchLevel());
buffer.append("\n");
buffer.append("Producer: ");
buffer.append(getProducer());
buffer.append("\n");
buffer.append("Description: ");
buffer.append(getDescription());
buffer.append("\n");
return buffer.toString();
}
Returns a string representation of this module. |