|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.foray.common.Configuration
public abstract class Configuration
Abstract superclass for configuration options. All options are stored in key / value pairs. Protected Convenience methods are available to handle Boolean, Int, String, and List values.
Most accessor methods are protected. The purpose is to force clients to use the subclass accessor methods instead, where more intelligence can be applied with regard to handling null values, etc. Applications that wish to make these available should simply override them with public methods in the subclass.
Field Summary | |
---|---|
static byte |
PRECEDENCE_COMMAND_LINE
Constant indicating the highest-level precedence, that of an item set on the command-line. |
static byte |
PRECEDENCE_CONFIG_FILE
Constant indicating the middle-level precedence, that of an item in the configuration file. |
static byte |
PRECEDENCE_DEFAULT
Constant indicating the lowest precedence, that of the default values. |
Constructor Summary | |
---|---|
protected |
Configuration()
Constructor. |
Method Summary | |
---|---|
protected void |
addUnvalidatedOption(String key,
Object value,
int precedenceValue)
Adds an item to the configuration without giving the subclass an opportunity to validate it. |
String |
dumpConfiguration()
Returns the contents of this Configuration as a String, suitable for logging. |
protected Boolean |
getBooleanValue(String key)
Convenience method to access boolean values in the configuration. |
protected int |
getIntValue(String key)
Convenience methods to access int values in the configuration. |
protected List<?> |
getListValue(String key)
Convenience method to access list values in the configuration. |
protected abstract String |
getName()
Supplies a name for this configuration. |
protected String |
getStringValue(String key)
Convenience method to access strings values in the configuration. |
protected Object |
getValue(String key)
Accessor method for a generic property. |
protected Boolean |
parseBoolean(String key,
String value)
Converts a given configuration item to a Boolean value. |
abstract boolean |
parseOption(String key,
String value,
int precedenceValue)
Attempt to add the configuration option. |
protected String[] |
parseSpaceDelimitedList(String key,
String value)
Converts a given space-delimited configuration item to an ArrayList. |
protected URL |
parseURL(String key,
String urlString)
Converts a given configuration item to a URL. |
protected URL |
parseURLDirectory(String key,
String directory)
Converts a given configuration item to a URL directory, logging a warning if the resulting URL points to a file instead of a directory. |
protected URL |
parseURLFile(String key,
String fileName)
Converts a given configuration item to a URL, logging a warning if the resulting URL points to a directory instead of a file. |
protected void |
put(String key,
Object value,
int precedenceValue)
Adds or updates a configuration option. |
protected abstract void |
setDefaults()
Sets any default configuration values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte PRECEDENCE_DEFAULT
public static final byte PRECEDENCE_CONFIG_FILE
public static final byte PRECEDENCE_COMMAND_LINE
Constructor Detail |
---|
protected Configuration()
Method Detail |
---|
protected abstract void setDefaults()
protected abstract String getName()
protected Object getValue(String key)
key
- a string containing the key value for the configuration value
protected String getStringValue(String key)
key
- a string containing the key value for the configuration value
protected int getIntValue(String key)
key
- a string containing the key value for the configuration value
protected Boolean getBooleanValue(String key)
key
- a string containing the key value for the configuration value
protected List<?> getListValue(String key)
key
- a string containing the key value for the configuration value
protected void put(String key, Object value, int precedenceValue)
key
- A string containing the key value for the configuration value.value
- The object containing the configuration value.precedenceValue
- The precedence with which this option should be
treated.
Entries with a higher precedence value override entries with a lower
value.public abstract boolean parseOption(String key, String value, int precedenceValue) throws ConfigurationException
key
- A string containing the key value for the configuration value.value
- The string containing the configuration value.precedenceValue
- The precedence with which this option should be
treated.
Entries with a higher precedence value override entries with a lower
value.
ConfigurationException
- For an invalid value for the given key.protected void addUnvalidatedOption(String key, Object value, int precedenceValue)
key
- A string containing the key value for the configuration value.value
- The object containing the configuration value.precedenceValue
- The precedence with which this option should be
treated.
Entries with a higher precedence value override entries with a lower
value.protected Boolean parseBoolean(String key, String value) throws ConfigurationException
key
- A string containing the key value for the configuration value.value
- The unparsed boolean value.
ConfigurationException
- If value
is neither "true" nor "false".protected URL parseURLDirectory(String key, String directory) throws ConfigurationException
key
- A string containing the key value for the configuration value.directory
- The unparsed URL directory value.
ConfigurationException
- If directory
is malformed, or if it is not a directory.protected URL parseURLFile(String key, String fileName) throws ConfigurationException
key
- A string containing the key value for the configuration value.fileName
- The unparsed URL name.
ConfigurationException
- If fileName
is malformed, or if it is not a file.protected URL parseURL(String key, String urlString) throws ConfigurationException
key
- A string containing the key value for the configuration value.urlString
- The unparsed URL name.
ConfigurationException
- If urlString
is malformed.protected String[] parseSpaceDelimitedList(String key, String value)
key
- A string containing the key value for the configuration value.value
- The space-delimited input.
public String dumpConfiguration()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |