public class ScopedModuleManager extends ModuleManager implements Module, XMLOptionsHandler
A module manager that can be placed inside other module managers in a hierarchical fashion. Each child module manager can import modules from the direct parent manager using import elements. Otherwise, child managers are isolated from the parent, or sibling, managers. This makes it practical to import module bundles that implement specific features without worry of them conflicting with existing modules.
The ScopedModuleManager itself is a Module and can be placed in any other module manager, scoped or otherwise. Its dependencies will be all the modules that are specifically imported into it. All the contained modules that are marked for autostart are started when the module manager itself is started and stopped when the manager is stopped. The child modules are initialised when the manager is initialised.
Modifier and Type | Class and Description |
---|---|
static class |
ScopedModuleManager.Import |
ModuleManager.ModuleSettings
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<ScopedModuleManager.Import> |
imports |
protected boolean |
initialized |
protected ModuleManager |
parentManager |
protected boolean |
running |
isRequiredBy, log, moduleListeners, moduleParams, modules, moduleSettings, variables
Constructor and Description |
---|
ScopedModuleManager() |
Modifier and Type | Method and Description |
---|---|
void |
addImport(java.lang.Class<? extends Module> cls,
boolean optional) |
void |
addImport(ScopedModuleManager.Import im) |
<A extends Module> |
findModule(Module context,
java.lang.String instanceName,
java.lang.Class<A> cls)
Finds a module that is of the specified class or one extending it.
|
<A extends Module> |
findModulesRecursive(java.lang.Class<A> cls) |
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> parameters)
Initialises the module.
|
boolean |
isInitialized()
Checks if the module is initialised.
|
boolean |
isRunning()
Checks if the module is running.
|
java.util.Collection<Module> |
parseXMLConfigElement(org.w3c.dom.Node doc,
java.lang.String source)
Parses an XML element as if it was the root element of
a full configuration file.
|
protected void |
parseXMLImport(org.w3c.dom.Element e) |
java.util.HashMap<java.lang.String,java.lang.Object> |
parseXMLOptionsElement(ModuleManager manager,
org.w3c.dom.Element e,
java.lang.String source)
Parses the given module element and returns a map containing the
module parameters.
|
void |
setParentManager(ModuleManager manager) |
void |
start(ModuleManager manager)
Starts the module.
|
void |
stop(ModuleManager manager)
Stops the module.
|
addModule, addModule, addModule, addModule, addModule, addModuleListener, autostartModules, autostartModules, findModule, findModule, findModule, findModules, getAllModules, getLogger, getModuleName, getModuleSettings, getVariable, initAllModules, isModuleAutoStart, moduleToString, moduleToString, optionalModule, optionalModule, optionalModule, optionalModule, optionalModules, parseXMLInclude, parseXMLModuleElement, parseXMLModuleSettings, parseXMLOptionsElement, parseXMLParamElement, parseXMLVariable, readXMLOptionsFile, removeModule, removeModuleListener, replaceVariables, requireModule, requireModule, requireModule, requireModule, setLogging, setVariable, startAllModules, startModule, startModuleWithDependencies, stopAllModules, stopCascading, stopModule
protected boolean running
protected boolean initialized
protected ModuleManager parentManager
protected final java.util.ArrayList<ScopedModuleManager.Import> imports
public <A extends Module> A findModule(Module context, java.lang.String instanceName, java.lang.Class<A> cls)
ModuleManager
findModule
in class ModuleManager
context
- The module which is requesting the module. This may affect
what module is returned.instanceName
- The instance name of the requested module.cls
- The class or interface that the module has to implement or extend or
be a direct instance of.public <A extends Module> java.util.ArrayList<A> findModulesRecursive(java.lang.Class<A> cls)
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> parameters) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
manager
- The module manager handling this module.ModuleException
public void start(ModuleManager manager) throws ModuleException
Module
start
in interface Module
manager
- The module manager handling this module.ModuleException
public void stop(ModuleManager manager)
Module
public boolean isInitialized()
Module
isInitialized
in interface Module
public boolean isRunning()
Module
public void addImport(ScopedModuleManager.Import im)
public void addImport(java.lang.Class<? extends Module> cls, boolean optional)
protected void parseXMLImport(org.w3c.dom.Element e)
public java.util.Collection<Module> parseXMLConfigElement(org.w3c.dom.Node doc, java.lang.String source)
ModuleManager
parseXMLConfigElement
in class ModuleManager
doc
- The element which contains the config definitions.source
- The source identifier, e.g. file name, where this element
came from.public java.util.HashMap<java.lang.String,java.lang.Object> parseXMLOptionsElement(ModuleManager manager, org.w3c.dom.Element e, java.lang.String source) throws java.lang.ReflectiveOperationException, javax.script.ScriptException
XMLOptionsHandler
parseXMLOptionsElement
in interface XMLOptionsHandler
manager
- The module manager handling this module.e
- The module element which is to be parsed.source
- The source identifier for the module, could be the file name
where the module comes from or something else.java.lang.ReflectiveOperationException
javax.script.ScriptException
public void setParentManager(ModuleManager manager)
Copyright 2004-2015 Wandora Team