public class GrinderProperties
extends java.util.Properties
Properties
to add type safe accessors.
Has an optional associated file.Grinder.ScriptContext.getProperties()
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
GrinderProperties.PersistenceException
Exception indicating a problem in persisting properties.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONSOLE_HOST
Key to use for the console host property.
|
static java.lang.String |
CONSOLE_PORT
Key to use for the console host property.
|
static java.io.File |
DEFAULT_PROPERTIES
Default file name for properties.
|
static java.io.File |
DEFAULT_SCRIPT
Default script file name.
|
static java.lang.String |
LOG_DIRECTORY
Key to use for the log directory property.
|
static java.lang.String |
SCRIPT
Key to use for the script property.
|
Constructor and Description |
---|
GrinderProperties()
Construct an empty GrinderProperties with no associated file.
|
GrinderProperties(java.io.File file)
Construct a GrinderProperties, reading initial values from the
specified file.
|
Modifier and Type | Method and Description |
---|---|
java.io.File |
getAssociatedFile()
Get the associated file.
|
boolean |
getBoolean(java.lang.String propertyName,
boolean defaultValue)
Get the value of the property with the given name, return the
value as a
boolean . |
double |
getDouble(java.lang.String propertyName,
double defaultValue)
Get the value of the property with the given name, return the
value as a
double . |
java.io.File |
getFile(java.lang.String propertyName,
java.io.File defaultValue)
Get the value of the property with the given name, return the value as a
File . |
int |
getInt(java.lang.String propertyName,
int defaultValue)
Get the value of the property with the given name, return the
value as an
int . |
long |
getLong(java.lang.String propertyName,
long defaultValue)
Get the value of the property with the given name, return the
value as a
long . |
GrinderProperties |
getPropertySubset(java.lang.String prefix)
Return a new GrinderProperties that contains the subset of our
Properties which begin with the specified prefix.
|
short |
getShort(java.lang.String propertyName,
short defaultValue)
Get the value of the property with the given name, return the
value as a
short . |
java.io.File |
resolveRelativeFile(java.io.File file)
Returns a
File representing the combined path of our associated
property file directory and the passed file . |
void |
save()
Save our properties to our file.
|
void |
saveSingleProperty(java.lang.String name)
Save a single property to our file.
|
void |
setAssociatedFile(java.io.File file)
Set the associated file.
|
void |
setBoolean(java.lang.String propertyName,
boolean value)
Set the property with the given name to a
boolean
value. |
void |
setDouble(java.lang.String propertyName,
double value)
Set the property with the given name to a
double
value. |
void |
setErrorWriter(java.io.PrintWriter writer)
Set a writer to report warnings to.
|
void |
setFile(java.lang.String propertyName,
java.io.File value)
Set the property with the given name to a
File
value. |
void |
setInt(java.lang.String propertyName,
int value)
Set the property with the given name to an
int
value. |
void |
setLong(java.lang.String propertyName,
long value)
Set the property with the given name to a
long
value. |
void |
setShort(java.lang.String propertyName,
short value)
Set the property with the given name to a
short
value. |
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
public static final java.lang.String SCRIPT
public static final java.lang.String LOG_DIRECTORY
public static final java.lang.String CONSOLE_HOST
public static final java.lang.String CONSOLE_PORT
public static final java.io.File DEFAULT_PROPERTIES
public static final java.io.File DEFAULT_SCRIPT
public GrinderProperties()
public GrinderProperties(java.io.File file) throws GrinderProperties.PersistenceException
grinder.
"are also added to allow values to be
overridden on the command line.file
- The file to read the properties from.GrinderProperties.PersistenceException
- If an error occurs reading from
the file.DEFAULT_PROPERTIES
public final java.io.File getAssociatedFile()
null
if none.public final void setAssociatedFile(java.io.File file)
file
- The associated file, or null
if none.public final void save() throws GrinderProperties.PersistenceException
GrinderProperties.PersistenceException
- If there is no file associated
with this GrinderProperties
or an I/O exception occurs..public final void saveSingleProperty(java.lang.String name) throws GrinderProperties.PersistenceException
name
- Property name.GrinderProperties.PersistenceException
- If there is no file associated with this
GrinderProperties
or an I/O exception occurs.public final void setErrorWriter(java.io.PrintWriter writer)
writer
- The writer.public final GrinderProperties getPropertySubset(java.lang.String prefix)
prefix
- The prefix.public final int getInt(java.lang.String propertyName, int defaultValue)
int
.propertyName
- The property name.defaultValue
- The value to return if a property with the
given name does not exist or is not an integer.public final void setInt(java.lang.String propertyName, int value)
int
value.propertyName
- The property name.value
- The value to set.public final long getLong(java.lang.String propertyName, long defaultValue)
long
.propertyName
- The property name.defaultValue
- The value to return if a property with the
given name does not exist or is not a long.public final void setLong(java.lang.String propertyName, long value)
long
value.propertyName
- The property name.value
- The value to set.public final short getShort(java.lang.String propertyName, short defaultValue)
short
.propertyName
- The property name.defaultValue
- The value to return if a property with the
given name does not exist or is not a short.public final void setShort(java.lang.String propertyName, short value)
short
value.propertyName
- The property name.value
- The value to set.public final double getDouble(java.lang.String propertyName, double defaultValue)
double
.propertyName
- The property name.defaultValue
- The value to return if a property with the
given name does not exist or is not a double.public final void setDouble(java.lang.String propertyName, double value)
double
value.propertyName
- The property name.value
- The value to set.public final boolean getBoolean(java.lang.String propertyName, boolean defaultValue)
boolean
.propertyName
- The property name.defaultValue
- The value to return if a property with the
given name does not exist.public final void setBoolean(java.lang.String propertyName, boolean value)
boolean
value.propertyName
- The property name.value
- The value to set.public final java.io.File getFile(java.lang.String propertyName, java.io.File defaultValue)
File
.propertyName
- The property name.defaultValue
- The value to return if a property with the given name does not
exist.public final java.io.File resolveRelativeFile(java.io.File file)
File
representing the combined path of our associated
property file directory and the passed file
.
If file
is absolute, or this GrinderProperties
has no associated property file, return file
.
file
- The file.file
resolved relative to the directory
of our associated properties file, or file
.public final void setFile(java.lang.String propertyName, java.io.File value)
File
value.propertyName
- The property name.value
- The value to set.