net.sourceforge.argval.utils.impl
Class PropertiesLoaderImpl

java.lang.Object
  extended by net.sourceforge.argval.utils.impl.PropertiesLoaderImpl
All Implemented Interfaces:
PropertiesLoader

public class PropertiesLoaderImpl
extends Object
implements PropertiesLoader

This PropertiesLoader provides a standard way for loading (test) configuration(s). It provides a static method to load the configuration as a Properties object.

The configuration is loaded as follows:

An example of using the PropertiesLoader:

Author:
T. Verhagen

Constructor Summary
PropertiesLoaderImpl(String propKeyConfigurationFile, String configDirName, String defaultFileName)
          Creates a PropertiesLoader specific for an application / utility.
 
Method Summary
 File getPropertiesFile()
          Returns the location of the properties file.
 String getPropertiesFileMessage()
          Returns a message about the location from which the message was loaded.
 Properties loadConfiguration()
          Returns the loaded configuration Properties, including the System.getProperties().
 Properties loadConfiguration(Boolean includeSystemProperties)
          Load the configuration properties from file and add the System properties (environment variable).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesLoaderImpl

public PropertiesLoaderImpl(String propKeyConfigurationFile,
                            String configDirName,
                            String defaultFileName)
Creates a PropertiesLoader specific for an application / utility.

Specify the propKeyConfigurationFile as a property key. This key can be used to specify the location of the configuration file, as system property / environment variable. As in:

java  -Dmy-application-name.configuration.path=
   org.organisation.application.Start
The folderName is optional, use it when the application has a default configuration folder in the users home directory. Like ${user.home/.my-application-config/. The defaultFileName required, used to find load the default configuration file, from the configuration application configuration directory (${user.home}/.my-application-config/defaultFileName). Or the current working directory (${user.dir}/defaultFileName).

Parameters:
propKeyConfigurationFile - - the system property key, for locating the configuration file (not null)
configDirName - - the applications configuration directory (when it has one) (can be null)
defaultFileName - - the default configuration file name (not null).
Method Detail

loadConfiguration

public Properties loadConfiguration()
                             throws IOException
Description copied from interface: PropertiesLoader
Returns the loaded configuration Properties, including the System.getProperties().

Specified by:
loadConfiguration in interface PropertiesLoader
Returns:
The loaded Properties.
Throws:
FileNotFoundException - When no configuration file is found.
IOException - When loading of properties file is not successful.

loadConfiguration

public Properties loadConfiguration(Boolean includeSystemProperties)
                             throws IOException
Description copied from interface: PropertiesLoader
Load the configuration properties from file and add the System properties (environment variable). Or explicitly instruct not to add the system properties.

Specified by:
loadConfiguration in interface PropertiesLoader
Parameters:
includeSystemProperties - - If true the system properties will be included (over ruling the loaded properties from file), else (when false) the system properties will not added. (Default is true)
Returns:
The loaded Properties.
Throws:
FileNotFoundException - When no configuration file is found.
IOException - When loading of properties file is not successful.

getPropertiesFile

public File getPropertiesFile()
                       throws FileNotFoundException
Description copied from interface: PropertiesLoader
Returns the location of the properties file.

Specified by:
getPropertiesFile in interface PropertiesLoader
Returns:
The location of the properties file.
Throws:
FileNotFoundException - When no configuration file is found.

getPropertiesFileMessage

public String getPropertiesFileMessage()
Description copied from interface: PropertiesLoader
Returns a message about the location from which the message was loaded.

Specified by:
getPropertiesFileMessage in interface PropertiesLoader
Returns:
A message about the location from which the message was loaded.


Copyright © 2013 Verhagen Software. All Rights Reserved.