gov.sns.tools.apputils
Class PropertyManager

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--gov.sns.tools.apputils.PropertyManager
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class PropertyManager
extends java.util.Properties

PropertyManager is a Properties subclass which loads properties from default properties files for the specified root class. For starters, properties can be supplied to the constructor. Then if a default.properties resource is found relative to the root class, its properties are read and update the properties. If a config file is found in the user's Library/config/ folder and it has the root's fully qualified name along with the "properties" suffix (e.g. gov.sns.xyz.X.properties), then it is read and its properties update the manager's properties. Finally, any command line properties update the manager's properties. This should provide sufficient flexibility to supply defaults for various components.

See Also:
Serialized Form

Field Summary
protected  java.io.File CONFIG_FILE
           
protected static java.io.File CONFIG_FOLDER
           
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
PropertyManager(java.lang.Class root)
          Constructor to build a properties table for the specified class.
PropertyManager(java.lang.Class root, java.util.Properties defaults)
          Constructor to build a properties table for the specified class.
PropertyManager(java.lang.Object root)
          Constructor to build a properties table for the class of the specified object.
 
Method Summary
protected static java.util.Properties fetchDefaults(java.lang.Class root, java.util.Properties defaults)
          Fetch default properties from the root's default.properties resource starting with properties initialized defaults.
 java.io.File getUserConfigFile()
          Get the user's config file.
protected  void loadUserConfig()
          Load properties from the user's configuration file if it exists.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CONFIG_FOLDER

protected static final java.io.File CONFIG_FOLDER

CONFIG_FILE

protected final java.io.File CONFIG_FILE
Constructor Detail

PropertyManager

public PropertyManager(java.lang.Class root,
                       java.util.Properties defaults)
Constructor to build a properties table for the specified class. Load default properties from both the class's default properties file and the user's config properties file for the class. Properties are loaded in the following order: - properties specified programmatically in the constructor - properties loaded from the default.properties file if it exists - properties loaded from the user's config file if it exists - properties specified as command line arguments

Parameters:
root - The class for which to load default properties.
defaults - Default properties with which to start.

PropertyManager

public PropertyManager(java.lang.Class root)
Constructor to build a properties table for the specified class. Properties are loaded in the following order: - properties loaded from the default.properties file if it exists - properties loaded from the user's config file if it exists - properties specified as command line arguments

Parameters:
root - The class for which to load default properties.

PropertyManager

public PropertyManager(java.lang.Object root)
Constructor to build a properties table for the class of the specified object.

Parameters:
root - The object whose class identifies the properties to load.
Method Detail

loadUserConfig

protected void loadUserConfig()
Load properties from the user's configuration file if it exists.


fetchDefaults

protected static java.util.Properties fetchDefaults(java.lang.Class root,
                                                    java.util.Properties defaults)
Fetch default properties from the root's default.properties resource starting with properties initialized defaults.

Parameters:
root - The class whose default.properties resource is used to fetch properties
defaults - The properties used for initialization.
Returns:
The default properties.

getUserConfigFile

public java.io.File getUserConfigFile()
Get the user's config file.

Returns:
the user's config file.