📄 abstractmodule.java
字号:
return;
}
final String line = lastLineRead.trim();
final String key = parseKey(line);
if (key != null)
{
// parse error: Non data line does not contain a colon
final String b = readValue(reader, parseValue(line.trim()));
if (key.equals("name"))
{
setName(b);
}
else if (key.equals("producer"))
{
setProducer(b);
}
else if (key.equals("description"))
{
setDescription(b);
}
else if (key.equals("subsystem"))
{
setSubSystem(b);
}
else if (key.equals("version.major"))
{
setMajorVersion(b);
}
else if (key.equals("version.minor"))
{
setMinorVersion(b);
}
else if (key.equals("version.patchlevel"))
{
setPatchLevel(b);
}
}
}
}
/**
* Parses an string to find the key section of the line. This section ends with
* an colon.
*
* @param line the line which to parse
* @return the key or null if no key is found.
*/
private String parseKey(final String line)
{
final int idx = line.indexOf(':');
if (idx == -1)
{
return null;
}
return line.substring(0, idx);
}
/**
* Parses the value section of the given line.
*
* @param line the line that should be parsed
* @return the value, never null
*/
private String parseValue(final String line)
{
final int idx = line.indexOf(':');
if (idx == -1)
{
return line;
}
if ((idx + 1) == line.length())
{
return "";
}
return line.substring(idx + 1);
}
/**
* Reads an external module description. This describes either an optional or
* a required module.
*
* @param reader the reader from where to read the module
* @return the read module, never null
* @throws IOException if an error occures.
*/
private DefaultModuleInfo readExternalModule(final ReaderHelper reader)
throws IOException
{
final DefaultModuleInfo mi = new DefaultModuleInfo();
while (reader.hasNext())
{
final String lastLineRead = reader.next();
if (Character.isWhitespace(lastLineRead.charAt(0)) == false)
{
// break if the current character is no whitespace ...
reader.pushBack(lastLineRead);
return mi;
}
final String line = lastLineRead.trim();
final String key = parseKey(line);
if (key != null)
{
final String b = readValue(reader, parseValue(line));
if (key.equals("module"))
{
mi.setModuleClass(b);
}
else if (key.equals("version.major"))
{
mi.setMajorVersion(b);
}
else if (key.equals("version.minor"))
{
mi.setMinorVersion(b);
}
else if (key.equals("version.patchlevel"))
{
mi.setPatchLevel(b);
}
}
}
return mi;
}
/**
* Returns the name of this module.
*
* @see Module#getName()
*
* @return the module name
*/
public String getName()
{
return this.name;
}
/**
* Defines the name of the module.
*
* @param name the module name.
*/
protected void setName(final String name)
{
this.name = name;
}
/**
* Returns the module description.
* @see Module#getDescription()
*
* @return the description of the module.
*/
public String getDescription()
{
return this.description;
}
/**
* Defines the description of the module.
*
* @param description the module's desciption.
*/
protected void setDescription(final String description)
{
this.description = description;
}
/**
* Returns the producer of the module.
*
* @see Module#getProducer()
*
* @return the producer.
*/
public String getProducer()
{
return this.producer;
}
/**
* Defines the producer of the module.
*
* @param producer the producer.
*/
protected void setProducer(final String producer)
{
this.producer = producer;
}
/**
* 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.
* @see Module#getRequiredModules()
*
* @return an array of all required modules.
*/
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 optional modules that may improve the modules functonality.
* @see Module#getRequiredModules()
*
* @return an array of all required modules.
*/
public ModuleInfo[] getOptionalModules()
{
final ModuleInfo[] retval = new ModuleInfo[this.optionalModules.length];
System.arraycopy(this.optionalModules, 0, retval, 0, this.optionalModules.length);
return retval;
}
/**
* Defines the required module descriptions for this module.
*
* @param requiredModules the required modules.
*/
protected void setRequiredModules(final ModuleInfo[] requiredModules)
{
this.requiredModules = new ModuleInfo[requiredModules.length];
System.arraycopy(requiredModules, 0, this.requiredModules, 0, requiredModules.length);
}
/**
* Defines the optional module descriptions for this module.
*
* @param optionalModules the optional modules.
*/
public void setOptionalModules(final ModuleInfo[] optionalModules)
{
this.optionalModules = new ModuleInfo[optionalModules.length];
System.arraycopy(optionalModules, 0, this.optionalModules, 0, optionalModules.length);
}
/**
* Returns a string representation of this module.
* @see java.lang.Object#toString()
*
* @return the string representation of this module for debugging purposes.
*/
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();
}
/**
* Tries to load a class to indirectly check for the existence
* of a certain library.
*
* @param name the name of the library class.
* @return true, if the class could be loaded, false otherwise.
*/
protected static boolean isClassLoadable(final String name)
{
try
{
Thread.currentThread().getContextClassLoader().loadClass(name);
return true;
}
catch (Exception e)
{
return false;
}
}
/**
* Configures the module by loading the configuration properties and
* adding them to the package configuration.
*
* @param subSystem the subsystem.
*/
public void configure(final SubSystem subSystem)
{
final InputStream in = ObjectUtilities.getResourceRelativeAsStream
("configuration.properties", getClass());
if (in == null)
{
return;
}
subSystem.getPackageManager().getPackageConfiguration().load(in);
}
/**
* Tries to load an module initializer and uses this initializer to initialize
* the module.
*
* @param classname the class name of the initializer.
* @throws ModuleInitializeException if an error occures
*/
protected void performExternalInitialize(final String classname)
throws ModuleInitializeException
{
try
{
final Class c = Thread.currentThread().getContextClassLoader().loadClass(classname);
final ModuleInitializer mi = (ModuleInitializer) c.newInstance();
mi.performInit();
}
catch (ModuleInitializeException mie)
{
throw mie;
}
catch (Exception e)
{
throw new ModuleInitializeException("Failed to load specified initializer class.", e);
}
}
/**
* Returns the modules subsystem. If this module is not part of an subsystem
* then return the modules name, but never null.
*
* @return the name of the subsystem.
*/
public String getSubSystem()
{
if (this.subsystem == null)
{
return getName();
}
return this.subsystem;
}
/**
* Defines the subsystem name for this module.
*
* @param name the new name of the subsystem.
*/
protected void setSubSystem (final String name)
{
this.subsystem = name;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -