org.elkoserver.foundation.boot
Class BootProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by org.elkoserver.foundation.boot.BootProperties
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class BootProperties
extends Properties

Enhanced version of the Java Properties class that knows how to pull properties settings out of the command line and also provides a friendlier interface to the values of the properties settings themselves.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
BootProperties()
          Creates an empty property collection with no default values.
BootProperties(Properties defaults)
          Creates an empty property collection with the specified defaults.
 
Method Summary
 boolean boolProperty(String property, boolean defaultValue)
          Get the value of a property as a boolean.
 double doubleProperty(String property, double defaultValue)
          Get the value of a property as a double.
 int intProperty(String property, int defaultValue)
          Get the value of a property as an integer.
 String[] scanArgs(String[] inArgs)
          Read properties files and parse property settings from the command line.
 boolean testProperty(String property)
          Test the setting of a boolean property.
 boolean testProperty(String property, String possibleValue)
          Test if the value of a property is a particular string.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
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
 

Constructor Detail

BootProperties

public BootProperties()
Creates an empty property collection with no default values.


BootProperties

public BootProperties(Properties defaults)
Creates an empty property collection with the specified defaults.

Parameters:
defaults - A set of properties to use as a default initializer.
Method Detail

boolProperty

public boolean boolProperty(String property,
                            boolean defaultValue)
Get the value of a property as a boolean.

Parameters:
property - The name of the property to test.
defaultValue - The default value in the event of absence or error.
Returns:
the value of the property interpreted as a boolean.
Throws:
IllegalArgumentException - if the property has a value that is neither of the strings "true" nor "false".

doubleProperty

public double doubleProperty(String property,
                             double defaultValue)
Get the value of a property as a double.

Parameters:
property - The name of the property of interest.
defaultValue - The default value in the event of absence or error.
Returns:
the value of the property interpreted as a double.

intProperty

public int intProperty(String property,
                       int defaultValue)
Get the value of a property as an integer.

Parameters:
property - The name of the property of interest.
defaultValue - The default value in the event of absence or error.
Returns:
the value of the property interpreted as an int.

scanArgs

public String[] scanArgs(String[] inArgs)
                  throws IOException
Read properties files and parse property settings from the command line. Unless otherwise directed, a default properties file is read for property definitions. The command line is parsed for additional property assignments according to the following rules:

key=val

The property named key is given the value val.
-nodefaults
Suppress reading ~/.propsrc for further property definitions.
-properties filename
File filename is read for further property definitions.
anythingelse
The argument is added to the returned arguments array.

Parameters:
inArgs - The raw, unprocessed command line arguments array.
Returns:
an array of the arguments remaining after all the property-specifying ones are stripped out.
Throws:
IOException - when a file from which it is supposed to read further properties does not exist or cannot be read. However, if any of the default properties files do not exist, their non-existence is silently ignored rather than causing an exception. On the other hand, if they do exist but simply aren't readable, an exception is thrown as for any other properties file.

testProperty

public boolean testProperty(String property)
Test the setting of a boolean property. A boolean property is true if its string value is "true", and false if its string value is "false" or if the property is not set at all.

Parameters:
property - The name of the property to test.
Returns:
the value of the property interpreted as a boolean.
Throws:
IllegalArgumentException - if the property has a value that is neither of the strings "true" nor "false".

testProperty

public boolean testProperty(String property,
                            String possibleValue)
Test if the value of a property is a particular string.

Parameters:
property - The name of the property to test.
possibleValue - String value to test if it is equal to.
Returns:
true if the property has a value equal to possibleValue.