public class PropertyAccessor
extends java.lang.Object
It also allows a Properties to be created from a pathname.
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected java.util.Properties properties
protected java.lang.String configFile
public PropertyAccessor(java.lang.String fileName)
fileName
- The pathname to a properties file.public PropertyAccessor(java.util.Properties p)
p
- The properties object to wrap around.public java.lang.String getConfigFile()
public java.util.Properties getProperties()
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.
public java.util.Properties getProperties(java.lang.String startingWith)
For example, if the file contains
name = bob bob.age = 49 bob.weight = 165Then a call to getProperties ("bob.") will return a Properties object containing only age and weight (and their respective values).
startingWith
- Grab all key/value pairs where the
key starts with this string.public void initialize(java.lang.String fileName)
fileName
- The pathname of a standard config file.public boolean isDefined(java.lang.String key)
public java.lang.String getString(java.lang.String key)
java.util.NoSuchElementException
- If there is no property by the given name.public java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
public int getInt(java.lang.String key)
java.util.NoSuchElementException
- If there is no property by the given name.public boolean getBoolean(java.lang.String key)
java.util.NoSuchElementException
- If there is no property by the given name.public double getDouble(java.lang.String key)
java.util.NoSuchElementException
- If there is no property by the given name.Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.