org.unitils.core
Class ConfigurationLoader

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

public class ConfigurationLoader
extends Object

Utility that loads the configuration of unitils.

Unitils settings can be defined in 3 files and in the system properties:

The name of the custom settings file (unitils.properties) is defined by the PROPKEY_CUSTOM_CONFIGURATION property in the default settings. The name of the local settings file (unitils-local.propeties) is defined by the PROPKEY_LOCAL_CONFIGURATION in the custom or default settings. If these properties are set to null or empty, the corresponding property file will not be loaded.

A runtime exception is thrown when the default properties cannot be loaded. A warning is logged when the custom propreties cannot be loaded. A debug message is logged when the local properties cannot be loaded.

Ant-like property place holders, e.g. ${holder} will be expanded if needed all property place holders to actual values. For example suppose you have a property defined as follows: root.dir=/usr/home Expanding following ${root.dir}/somesubdir will then give following result: /usr/home/somesubdir

Author:
Tim Ducheyne, Filip Neven, Fabian Krueger

Field Summary
static String DEFAULT_PROPERTIES_FILE_NAME
          Name of the fixed configuration file that contains all defaults
static String PROPKEY_CUSTOM_CONFIGURATION
          Property in the defaults configuration file that contains the name of the custom configuration file
static String PROPKEY_LOCAL_CONFIGURATION
          Property in the defaults and/or custom configuration file that contains the name of the user local configuration file
 
Constructor Summary
ConfigurationLoader()
           
 
Method Summary
protected  void expandPropertyValues(Properties properties)
          Expands all property place holders to actual values.
protected  String getConfigurationFileName(String propertyName, Properties properties)
          Gets the configuration file name from the system properties or if not defined, from the given loaded properties.
 Properties loadConfiguration()
          Creates and loads all configuration settings.
protected  void loadCustomConfiguration(Properties properties)
          Load the custom project level configuration file (unitils.properties)
protected  void loadDefaultConfiguration(Properties properties)
          Load the default properties file that is distributed with unitils (unitils-default.properties)
protected  void loadLocalConfiguration(Properties properties)
          Load the local configuration file from the user home, or from the classpath
protected  void loadSystemProperties(Properties properties)
          Load the environment properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROPERTIES_FILE_NAME

public static final String DEFAULT_PROPERTIES_FILE_NAME
Name of the fixed configuration file that contains all defaults

See Also:
Constant Field Values

PROPKEY_CUSTOM_CONFIGURATION

public static final String PROPKEY_CUSTOM_CONFIGURATION
Property in the defaults configuration file that contains the name of the custom configuration file

See Also:
Constant Field Values

PROPKEY_LOCAL_CONFIGURATION

public static final String PROPKEY_LOCAL_CONFIGURATION
Property in the defaults and/or custom configuration file that contains the name of the user local configuration file

See Also:
Constant Field Values
Constructor Detail

ConfigurationLoader

public ConfigurationLoader()
Method Detail

loadConfiguration

public Properties loadConfiguration()
Creates and loads all configuration settings.

Returns:
the settings, not null

loadDefaultConfiguration

protected void loadDefaultConfiguration(Properties properties)
Load the default properties file that is distributed with unitils (unitils-default.properties)

Parameters:
properties - The instance to add to loaded properties to, not null

loadCustomConfiguration

protected void loadCustomConfiguration(Properties properties)
Load the custom project level configuration file (unitils.properties)

Parameters:
properties - The instance to add to loaded properties to, not null

loadLocalConfiguration

protected void loadLocalConfiguration(Properties properties)
Load the local configuration file from the user home, or from the classpath

Parameters:
properties - The instance to add to loaded properties to, not null

loadSystemProperties

protected void loadSystemProperties(Properties properties)
Load the environment properties.

Parameters:
properties - The instance to add to loaded properties to, not null

expandPropertyValues

protected void expandPropertyValues(Properties properties)
Expands all property place holders to actual values. For example suppose you have a property defined as follows: root.dir=/usr/home Expanding following ${root.dir}/somesubdir will then give following result: /usr/home/somesubdir

Parameters:
properties - The properties, not null

getConfigurationFileName

protected String getConfigurationFileName(String propertyName,
                                          Properties properties)
Gets the configuration file name from the system properties or if not defined, from the given loaded properties. An exception is raised if no value is defined.

Parameters:
propertyName - The name of the property that defines the local/custom file name, not null
properties - The propertis that were already loaded, not null
Returns:
The property value, not null


Copyright © 2011. All Rights Reserved.