org.openmrs.module
Class ModuleFactory

java.lang.Object
  extended by org.openmrs.module.ModuleFactory

public class ModuleFactory
extends java.lang.Object

Methods for loading, starting, stopping, and storing OpenMRS modules


Field Summary
protected static java.util.Map<java.lang.String,java.util.List<Extension>> extensionMap
           
protected static java.util.Map<java.lang.String,Module> loadedModules
           
protected static java.util.Map<Module,ModuleClassLoader> moduleClassLoaders
           
protected static java.util.Map<java.lang.String,Module> startedModules
           
 
Constructor Summary
ModuleFactory()
           
 
Method Summary
static java.util.Map<java.lang.String,java.util.List<Extension>> getExtensionMap()
          Return the current extension map keyed on extension point id
static java.util.List<Extension> getExtensions(java.lang.String pointId)
          Return all of the extensions associated with the given pointId Returns empty extension list if no modules extend this pointId
static java.util.List<Extension> getExtensions(java.lang.String pointId, Extension.MEDIA_TYPE type)
          Return all of the extensions associated with the given pointId Returns getExtension(pointId) if no modules extend this pointId for given media type
static java.util.List<GlobalProperty> getGlobalProperties()
          Get a list of required GlobalProperties defined by the modules
static java.util.Collection<Module> getLoadedModules()
          Returns all modules found/loaded into the system (started and not started)
static java.util.List<Module> getLoadedModulesCoreFirst()
          Returns all modules found/loaded into the system (started and not started), with the core modules at the start of that list
static java.util.Map<java.lang.String,Module> getLoadedModulesMap()
          Returns all modules found/loaded into the system (started and not started) in the form of a map
static Module getModuleById(java.lang.String moduleId)
           
static Module getModuleByPackage(java.lang.String modulePackage)
           
static ModuleClassLoader getModuleClassLoader(Module mod)
          Get a module's classloader
static ModuleClassLoader getModuleClassLoader(java.lang.String moduleId)
          Get a module's classloader via the module id
static java.util.Map<Module,ModuleClassLoader> getModuleClassLoaderMap()
          Return all current classloaders keyed on module object
static java.util.Collection<ModuleClassLoader> getModuleClassLoaders()
          Returns all module classloaders This method will not return null
static java.util.List<Privilege> getPrivileges()
          Get a list of required Privileges defined by the modules
static Module getStartedModuleById(java.lang.String moduleId)
           
static java.util.Collection<Module> getStartedModules()
          Returns the modules that have been successfully started
static java.util.Map<java.lang.String,Module> getStartedModulesMap()
          Returns the modules that have been successfully started in the form of a map<ModuleId, Module>
static boolean isModuleStarted(Module mod)
          Checks whether the given module is activated
static void loadAdvice(Module module)
          Loop over the given module's advice objects and load them into the Context This needs to be called for all started modules after every restart of the Spring Application Context
static Module loadModule(java.io.File moduleFile)
          Add a module (in the form of a jar file) to the list of openmrs modules Returns null if an error occurred and/or module was not successfully loaded
static Module loadModule(java.io.File moduleFile, java.lang.Boolean replaceIfExists)
          Add a module (in the form of a jar file) to the list of openmrs modules Returns null if an error occurred and/or module was not successfully loaded
static Module loadModule(Module module, java.lang.Boolean replaceIfExists)
          Add a module to the list of openmrs modules
static void loadModules()
          Load OpenMRS modules from OpenmrsUtil.getModuleRepository()
static void loadModules(java.util.List<java.io.File> modulesToLoad)
          Attempt to load the given files as OpenMRS modules
static Module startModule(Module module)
          Runs through extensionPoints and then calls BaseModuleActivator.willStart() on the Module's activator.
static Module startModuleInternal(Module module)
          This method should not be called directly.

The startModule(Module) (and hence Daemon.startModule(Module)) calls this method in a new Thread and is authenticated as the Daemon user

Runs through extensionPoints and then calls BaseModuleActivator.willStart() on the Module's activator.
static void startModules()
          Try to start all of the loaded modules that have the global property moduleId.started is set to "true" or the property does not exist.
static void stopModule(Module mod)
          Runs through the advice and extension points and removes from api.
static void stopModule(Module mod, boolean isShuttingDown)
          Runs through the advice and extension points and removes from api.
Also calls mod.Activator.shutdown()
static java.util.List<Module> stopModule(Module mod, boolean skipOverStartedProperty, boolean isFailedStartup)
          Runs through the advice and extension points and removes from api.
skipOverStartedProperty should only be true when openmrs is stopping modules because it is shutting down.
static void unloadModule(Module mod)
          Removes module from module repository
static Module updateModule(Module mod)
          Update the module: 1) Download the new module 2) Unload the old module 3) Load/start the new module
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loadedModules

protected static java.util.Map<java.lang.String,Module> loadedModules

startedModules

protected static java.util.Map<java.lang.String,Module> startedModules

extensionMap

protected static java.util.Map<java.lang.String,java.util.List<Extension>> extensionMap

moduleClassLoaders

protected static java.util.Map<Module,ModuleClassLoader> moduleClassLoaders
Constructor Detail

ModuleFactory

public ModuleFactory()
Method Detail

loadModule

public static Module loadModule(java.io.File moduleFile)
                         throws ModuleException
Add a module (in the form of a jar file) to the list of openmrs modules Returns null if an error occurred and/or module was not successfully loaded

Parameters:
moduleFile -
Returns:
Module
Throws:
ModuleException

loadModule

public static Module loadModule(java.io.File moduleFile,
                                java.lang.Boolean replaceIfExists)
                         throws ModuleException
Add a module (in the form of a jar file) to the list of openmrs modules Returns null if an error occurred and/or module was not successfully loaded

Parameters:
moduleFile -
replaceIfExists - unload a module that has the same moduleId if one is loaded already
Returns:
Module
Throws:
ModuleException

loadModule

public static Module loadModule(Module module,
                                java.lang.Boolean replaceIfExists)
                         throws ModuleException
Add a module to the list of openmrs modules

Parameters:
module -
replaceIfExists - unload a module that has the same moduleId if one is loaded already
Returns:
module the module that was loaded or if the module exists already with the same version, the old module
Throws:
ModuleException

loadModules

public static void loadModules()
Load OpenMRS modules from OpenmrsUtil.getModuleRepository()


loadModules

public static void loadModules(java.util.List<java.io.File> modulesToLoad)
Attempt to load the given files as OpenMRS modules

Parameters:
modulesToLoad - the list of files to try and load

startModules

public static void startModules()
Try to start all of the loaded modules that have the global property moduleId.started is set to "true" or the property does not exist. Otherwise, leave it as only "loaded"

Modules that are already started will be skipped.


getLoadedModulesCoreFirst

public static java.util.List<Module> getLoadedModulesCoreFirst()
Returns all modules found/loaded into the system (started and not started), with the core modules at the start of that list

Returns:
List of the modules loaded into the system, with the core modules first.

getLoadedModules

public static java.util.Collection<Module> getLoadedModules()
Returns all modules found/loaded into the system (started and not started)

Returns:
Collection of the modules loaded into the system

getLoadedModulesMap

public static java.util.Map<java.lang.String,Module> getLoadedModulesMap()
Returns all modules found/loaded into the system (started and not started) in the form of a map

Returns:
map

getStartedModules

public static java.util.Collection<Module> getStartedModules()
Returns the modules that have been successfully started

Returns:
Collection of the started modules

getStartedModulesMap

public static java.util.Map<java.lang.String,Module> getStartedModulesMap()
Returns the modules that have been successfully started in the form of a map<ModuleId, Module>

Returns:
Map<ModuleId, Module>

getModuleById

public static Module getModuleById(java.lang.String moduleId)
Parameters:
moduleId -
Returns:
Module matching module id or null if none

getStartedModuleById

public static Module getStartedModuleById(java.lang.String moduleId)
Parameters:
moduleId -
Returns:
Module matching moduleId, if it is started or null otherwise

getModuleByPackage

public static Module getModuleByPackage(java.lang.String modulePackage)
Parameters:
modulePackage -
Returns:
Module matching module package or null if none

startModule

public static Module startModule(Module module)
                          throws ModuleException
Runs through extensionPoints and then calls BaseModuleActivator.willStart() on the Module's activator. This method is run in a new thread and is authenticated as the Daemon user

Parameters:
module - Module to start
Throws:
ModuleException - if the module throws any kind of error at startup or in an activator
See Also:
startModuleInternal(Module), Daemon.startModule(Module)

startModuleInternal

public static Module startModuleInternal(Module module)
                                  throws ModuleException
This method should not be called directly.

The startModule(Module) (and hence Daemon.startModule(Module)) calls this method in a new Thread and is authenticated as the Daemon user

Runs through extensionPoints and then calls BaseModuleActivator.willStart() on the Module's activator.

Parameters:
module - Module to start
Throws:
ModuleException

loadAdvice

public static void loadAdvice(Module module)
Loop over the given module's advice objects and load them into the Context This needs to be called for all started modules after every restart of the Spring Application Context

Parameters:
module -

stopModule

public static void stopModule(Module mod)
Runs through the advice and extension points and removes from api.
Also calls mod.Activator.shutdown()

Parameters:
mod - module to stop
See Also:
stopModule(Module, boolean, boolean)

stopModule

public static void stopModule(Module mod,
                              boolean isShuttingDown)
Runs through the advice and extension points and removes from api.
Also calls mod.Activator.shutdown()

Parameters:
mod - the module to stop
isShuttingDown - true if this is called during the process of shutting down openmrs
See Also:
stopModule(Module, boolean, boolean)

stopModule

public static java.util.List<Module> stopModule(Module mod,
                                                boolean skipOverStartedProperty,
                                                boolean isFailedStartup)
                                         throws ModuleMustStartException
Runs through the advice and extension points and removes from api.
skipOverStartedProperty should only be true when openmrs is stopping modules because it is shutting down. When normally stopping a module, use stopModule(Module) (or leave value as false). This property controls whether the globalproperty is set for startup/shutdown.
Also calls module's Activator.shutdown()

Parameters:
mod - module to stop
skipOverStartedProperty - true if we don't want to set <moduleid>.started to false
isFailedStartup - true if this is being called as a cleanup because of a failed module startup
Returns:
list of dependent modules that were stopped because this module was stopped. This will never be null.
Throws:
ModuleMustStartException

unloadModule

public static void unloadModule(Module mod)
Removes module from module repository

Parameters:
mod - module to unload

getExtensions

public static java.util.List<Extension> getExtensions(java.lang.String pointId)
Return all of the extensions associated with the given pointId Returns empty extension list if no modules extend this pointId

Parameters:
pointId -
Returns:
List of extensions

getExtensions

public static java.util.List<Extension> getExtensions(java.lang.String pointId,
                                                      Extension.MEDIA_TYPE type)
Return all of the extensions associated with the given pointId Returns getExtension(pointId) if no modules extend this pointId for given media type

Parameters:
pointId -
type - Extension.MEDIA_TYPE
Returns:
List of extensions

getPrivileges

public static java.util.List<Privilege> getPrivileges()
Get a list of required Privileges defined by the modules

Returns:
List of the required privileges

getGlobalProperties

public static java.util.List<GlobalProperty> getGlobalProperties()
Get a list of required GlobalProperties defined by the modules

Returns:
List object of the module's global properties

isModuleStarted

public static boolean isModuleStarted(Module mod)
Checks whether the given module is activated

Parameters:
mod - Module to check
Returns:
true if the module is started, false otherwise

getModuleClassLoader

public static ModuleClassLoader getModuleClassLoader(Module mod)
                                              throws ModuleException
Get a module's classloader

Parameters:
mod - Module to fetch the class loader for
Returns:
ModuleClassLoader pertaining to this module. Returns null if the module is not started
Throws:
ModuleException - if the module does not have a registered classloader

getModuleClassLoader

public static ModuleClassLoader getModuleClassLoader(java.lang.String moduleId)
                                              throws ModuleException
Get a module's classloader via the module id

Parameters:
moduleId - String id of the module
Returns:
ModuleClassLoader pertaining to this module. Returns null if the module is not started
Throws:
ModuleException - if this module isn't started or doesn't have a classloader
See Also:
getModuleClassLoader(Module)

getModuleClassLoaders

public static java.util.Collection<ModuleClassLoader> getModuleClassLoaders()
Returns all module classloaders This method will not return null

Returns:
Collection all known module classloaders or empty list.

getModuleClassLoaderMap

public static java.util.Map<Module,ModuleClassLoader> getModuleClassLoaderMap()
Return all current classloaders keyed on module object

Returns:
Map

getExtensionMap

public static java.util.Map<java.lang.String,java.util.List<Extension>> getExtensionMap()
Return the current extension map keyed on extension point id

Returns:
Map>

updateModule

public static Module updateModule(Module mod)
                           throws ModuleException
Update the module: 1) Download the new module 2) Unload the old module 3) Load/start the new module

Parameters:
mod -
Throws:
ModuleException

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change