com.claritysys.util
Class PropertyAccessor

java.lang.Object
  extended by com.claritysys.util.PropertyAccessor

public class PropertyAccessor
extends java.lang.Object

PropertyAccessor extends java.util.Properties with strongly typed methods for reading int, boolean, etc out of a Properties object.

It also allows a Properties to be created from a pathname.


Field Summary
protected  java.lang.String configFile
          The file name we were created from.
protected  java.util.Properties properties
          The underlying properties as read directly from the config file.
 
Constructor Summary
PropertyAccessor(java.util.Properties p)
          Create a new accessor for the given properties.
PropertyAccessor(java.lang.String fileName)
          Create a new PropertyAccessor from the properties in the named file.
 
Method Summary
 boolean getBoolean(java.lang.String key)
          Return the named property as a boolean.
 java.lang.String getConfigFile()
          Return the name of the config file from which this object was created.
 double getDouble(java.lang.String key)
          Return the named property as a double.
 int getInt(java.lang.String key)
          Return the named property as an int.
 java.util.Properties getProperties()
          Return the underlying Properties.
 java.util.Properties getProperties(java.lang.String startingWith)
          Return the properties from the underlying Properties object which start with the given string.
 java.lang.String getString(java.lang.String key)
          Return the named property as a String.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Return the named property as a String.
 void initialize(java.lang.String fileName)
          Initialize from the given named property file.
 boolean isDefined(java.lang.String key)
          Return true if the named property is defined.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected java.util.Properties properties
The underlying properties as read directly from the config file.


configFile

protected java.lang.String configFile
The file name we were created from.

Constructor Detail

PropertyAccessor

public PropertyAccessor(java.lang.String fileName)
Create a new PropertyAccessor from the properties in the named file.

Parameters:
fileName - The pathname to a properties file.

PropertyAccessor

public PropertyAccessor(java.util.Properties p)
Create a new accessor for the given properties.

Parameters:
p - The properties object to wrap around.
Method Detail

getConfigFile

public java.lang.String getConfigFile()
Return the name of the config file from which this object was created.

Returns:
The config file name.

getProperties

public java.util.Properties getProperties()
Return the underlying Properties.

Note that this returns the actual object, not a clone.Making changes to the returned object may have undesirable impact and may not be forward compatible.

Returns:
The actual Properties object as read from the config file.

getProperties

public java.util.Properties getProperties(java.lang.String startingWith)
Return the properties from the underlying Properties object which start with the given string.

For example, if the file contains

 name = bob
 bob.age = 49
 bob.weight = 165
 
Then a call to getProperties ("bob.") will return a Properties object containing only age and weight (and their respective values).

Parameters:
startingWith - Grab all key/value pairs where the key starts with this string.
Returns:
A new Properties containing just the desired key/value pairs.

initialize

public void initialize(java.lang.String fileName)
Initialize from the given named property file.

Parameters:
fileName - The pathname of a standard config file.

isDefined

public boolean isDefined(java.lang.String key)
Return true if the named property is defined.


getString

public java.lang.String getString(java.lang.String key)
Return the named property as a String.

Throws:
java.util.NoSuchElementException - If there is no property by the given name.

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Return the named property as a String. If not defined, returned the supplied default.


getInt

public int getInt(java.lang.String key)
Return the named property as an int.

Throws:
java.util.NoSuchElementException - If there is no property by the given name.

getBoolean

public boolean getBoolean(java.lang.String key)
Return the named property as a boolean.

Throws:
java.util.NoSuchElementException - If there is no property by the given name.

getDouble

public double getDouble(java.lang.String key)
Return the named property as a double.

Throws:
java.util.NoSuchElementException - If there is no property by the given name.


Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.