fc.util
Class PropertyMgr

java.lang.Object
  extended by fc.util.PropertyMgr
Direct Known Subclasses:
FilePropertyMgr, ServletPropertyMgr

public abstract class PropertyMgr
extends Object

Implementations help load and manage properties from various sources including java property files, databases, custom file formats etc. Regardless of where the properties are loaded from, each property consists of a pair of name and value strings.

Version:
1.0 12/30/2001

Constructor Summary
PropertyMgr()
          Constructs a new PropertyMgr.
 
Method Summary
abstract  String get(String name)
          Returns the property associated with the specified key or null if the property was not found.
 String get(String name, String backup)
          Returns the property associated with the specified key.
 boolean getBoolean(String name, boolean backup)
          Returns the property associated with the specified key as a boolean value.
 int getInt(String name, int backup)
          Returns the property associated with the specified key as a integer value.
 String getRequired(String name)
          Returns the value corresponding to the specified key.
 boolean getRequiredBoolean(String name)
           
 int getRequiredInt(String name)
           
abstract  void save()
          Saves any properties that were set previously.
abstract  String set(String name, String backup)
          Sets the property associated with the specified key.
 void setUsage(String str)
          Specify program usage information to be output when an error occurs.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyMgr

public PropertyMgr()
Constructs a new PropertyMgr.

Method Detail

get

public abstract String get(String name)
Returns the property associated with the specified key or null if the property was not found.

Parameters:
name - the property key

get

public String get(String name,
                  String backup)
Returns the property associated with the specified key.

Parameters:
name - the property key
backup - value to return if the property for the specified key is not found
Returns:
value of specified key or backup string

getBoolean

public boolean getBoolean(String name,
                          boolean backup)
Returns the property associated with the specified key as a boolean value. If the property is present, then the corresponding boolean value is true if the property value is any of the following (case-insensitive):
yes, 1, true
else false is returned.

Parameters:
name - the property key
backup - value to return if the property for the specified property is not present
Returns:
value of specified key or backup string

getInt

public int getInt(String name,
                  int backup)
Returns the property associated with the specified key as a integer value. If the property is present but cannot be converted into an integer (via a Integer.parseInt(String) call), the backup value will be returned.

Parameters:
name - the property key
backup - value to return if the property for the specified property is not present
Returns:
value of specified key or backup string

getRequired

public String getRequired(String name)
Returns the value corresponding to the specified key. If the property value is not found, the handleError(java.lang.String) method is called, which by default prints a stack trace and exits the application.

If the handleError method is overriden to not exit the application, then this method will return null if the specified key is not found.

Parameters:
name - the property key

getRequiredBoolean

public boolean getRequiredBoolean(String name)

getRequiredInt

public int getRequiredInt(String name)

set

public abstract String set(String name,
                           String backup)
Sets the property associated with the specified key.

Parameters:
name - the property key
backup - the property value
Returns:
the previous value of the specified key or null if it did not have one.

save

public abstract void save()
                   throws IOException
Saves any properties that were set previously. This method does not need to be called if properties were only read, however if any property was modified or added, it is essential to call this method to save any such changes.

Throws:
IOException

setUsage

public void setUsage(String str)
Specify program usage information to be output when an error occurs. This information should contain a short description of required keys and any other information that the application expects.

Parameters:
str - Usage information