net.sf.jnati.config
Class Configuration

java.lang.Object
  extended by net.sf.jnati.config.Configuration

public class Configuration
extends Object

Implements a multi-layered configuration. There are three layers of configuration - in order of increasing precedence: defaults, configuration and runtime. Defaults and configured properties can be loaded (from a .properties file) or set (from a Map), while runtime properties are retrieved from System.getProperties().

Author:
Sam Adams

Constructor Summary
Configuration()
          Construct a new configuration with no parameters.
Configuration(Configuration parentConfig, Map<String,String> params, Properties configuration)
          Construct a new configuration with the specified parent configuration, and parameters.
Configuration(Map<String,String> params)
          Construct a new configuration with the specified parameters.
 
Method Summary
 String getProperty(String key)
          Gets the property's value.
 void loadConfiguration(InputStream in)
          Load the configured properties.
 void loadDefaults(InputStream in)
          Load the default property values.
 void setConfiguration(Map<String,String> config)
          Sets the configured properties.
 void setDefaults(Map<String,String> defaults)
          Sets the default property values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Configuration

public Configuration()
Construct a new configuration with no parameters.


Configuration

public Configuration(Map<String,String> params)
Construct a new configuration with the specified parameters.

Parameters:
params -

Configuration

public Configuration(Configuration parentConfig,
                     Map<String,String> params,
                     Properties configuration)
Construct a new configuration with the specified parent configuration, and parameters.

Parameters:
parentConfig -
params -
Method Detail

loadDefaults

public void loadDefaults(InputStream in)
                  throws IOException
Load the default property values. Existing defaults with the same name will be overridden. Invokes java.util.Properties.load().

Parameters:
in -
Throws:
IOException

setDefaults

public void setDefaults(Map<String,String> defaults)
Sets the default property values. Existing defaults with the same name will be overridden.

Parameters:
defaults -

loadConfiguration

public void loadConfiguration(InputStream in)
                       throws IOException
Load the configured properties. Invokes java.util.Properties.load().

Parameters:
in -
Throws:
IOException

setConfiguration

public void setConfiguration(Map<String,String> config)
Sets the configured properties.

Parameters:
config -

getProperty

public String getProperty(String key)
Gets the property's value.

Parameters:
key -
Returns:
The value for the specified key, or null if no property of that name exists.


Copyright © 2007-2011 Sam Adams. All Rights Reserved.