org.unitils.core
Class ModulesLoader

java.lang.Object
  extended by org.unitils.core.ModulesLoader

public class ModulesLoader
extends Object

A class for loading unitils modules.

The core names set by the PROPKEY_MODULES property which modules will be loaded. These names can then be used to construct properties that define the classnames and optionally the dependencies of these modules. E.g.


 unitils.modules= a, b, c, d
 unitils.module.a.className= org.unitils.A
 unitils.module.a.runAfter= b, c
 unitils.module.b.className= org.unitils.B
 unitils.module.b.runAfter= c
 unitils.module.c.className= org.unitils.C
 unitils.module.d.enabled= false
 
The above configuration will load 3 core classes A, B and C and will always perform processing in order C, B, A.

If a circular dependency is found in the runAfter configuration, a runtime exception will be thrown.

Author:
Filip Neven, Tim Ducheyne

Field Summary
static String PROPKEY_MODULE_PREFIX
          First part of all core specific properties.
static String PROPKEY_MODULE_SUFFIX_CLASS_NAME
          Last part of the core specific property that specifies the classname of the core.
static String PROPKEY_MODULE_SUFFIX_ENABLED
          Last part of the core specific property that specifies whether the core should be loaded.
static String PROPKEY_MODULE_SUFFIX_RUN_AFTER
          Last part of the core specific property that specifies the names of the modules that should be run before this core.
static String PROPKEY_MODULES
          Property that contains the names of the modules that are to be loaded.
 
Constructor Summary
ModulesLoader()
           
 
Method Summary
protected  boolean classFileExistsInClasspath(String className)
           
protected  List<Module> createAndInitializeModules(List<String> moduleNames, Properties configuration)
          Creates the modules with the given class names and calls initializes them with the given configuration.
 List<Module> loadModules(Properties configuration)
          Loads all unitils modules as described in the class javadoc.
protected  void removeDisabledModules(Set<String> moduleNames, Properties configuration)
          Removes all modules that have a value false for the enabled property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPKEY_MODULES

public static final String PROPKEY_MODULES
Property that contains the names of the modules that are to be loaded.

See Also:
Constant Field Values

PROPKEY_MODULE_PREFIX

public static final String PROPKEY_MODULE_PREFIX
First part of all core specific properties.

See Also:
Constant Field Values

PROPKEY_MODULE_SUFFIX_ENABLED

public static final String PROPKEY_MODULE_SUFFIX_ENABLED
Last part of the core specific property that specifies whether the core should be loaded.

See Also:
Constant Field Values

PROPKEY_MODULE_SUFFIX_CLASS_NAME

public static final String PROPKEY_MODULE_SUFFIX_CLASS_NAME
Last part of the core specific property that specifies the classname of the core.

See Also:
Constant Field Values

PROPKEY_MODULE_SUFFIX_RUN_AFTER

public static final String PROPKEY_MODULE_SUFFIX_RUN_AFTER
Last part of the core specific property that specifies the names of the modules that should be run before this core.

See Also:
Constant Field Values
Constructor Detail

ModulesLoader

public ModulesLoader()
Method Detail

loadModules

public List<Module> loadModules(Properties configuration)
Loads all unitils modules as described in the class javadoc.

Parameters:
configuration - the configuration, not null
Returns:
the modules, not null

createAndInitializeModules

protected List<Module> createAndInitializeModules(List<String> moduleNames,
                                                  Properties configuration)
Creates the modules with the given class names and calls initializes them with the given configuration.

Parameters:
moduleNames - the module class names, not null
configuration - the configuration, not null
Returns:
the modules, not null

removeDisabledModules

protected void removeDisabledModules(Set<String> moduleNames,
                                     Properties configuration)
Removes all modules that have a value false for the enabled property.

Parameters:
moduleNames - the module names, not null
configuration - the configuration, not null

classFileExistsInClasspath

protected boolean classFileExistsInClasspath(String className)
Parameters:
className - The name of the class to check, not null
Returns:
True if the classfile exists in the classpath


Copyright © 2011. All Rights Reserved.