|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Dictionary<K,V> java.util.Hashtable<Object,Object> java.util.Properties net.lucidviews.util.Properties
public class Properties
An extension to the java.util.Properties
class, which parses and
validates non-String
values.
A net.lucidviews.util.Properties
class can be instantiated in a
number of ways:
File
to load an initial set of property values from a
.properties
file. (See the file format described in the
java.util.Properties
JavaDoc.)
java.util.Properties
object. Effectively using the
net.lucidviews.util.Properties
class to wrapper the basic
properties table and provide more advanced access to the values therein.
net.lucidviews.util.Properties
class provides access methods
to set and get values of various types, including:
java.lang.Boolean
(and boolean
)java.lang.Class
java.awt.Color
java.lang.Double
(and double
)net.lucidviews.util.EnumValue
java.io.File
java.lang.Long
(and long
)
PropertyException
,
Properties
,
Serialized FormNested Class Summary | |
---|---|
private static class |
Properties.ClassParamMustExist
Helper class required for exported constant CLASS_PARAM_MUST_EXIST, which must be unique/different to avoid confusion with any other value a client may use. |
private static class |
Properties.EnumParamMustExist
Helper class required for exported constant ENUM_PARAM_MUST_EXIST, which must be unique/different to avoid confusion with any other value a client may use. |
Field Summary | |
---|---|
protected String |
_sourceDescription
A description of where the properties were defined. |
protected File |
_sourceFile
The file used to persist these property values. |
static Boolean |
BOOLEAN_MUST_BE_VALID
Special default value that ensures a valid Boolean value is parsed (i.e. |
static Boolean |
BOOLEAN_PARAM_MUST_EXIST
Special default value that ensures a property has been defined for a given Boolean value. |
static Class |
CLASS_MUST_BE_VALID
Special default value that ensures a valid Class is parsed (i.e. |
static Class |
CLASS_PARAM_MUST_EXIST
Special default value that ensures a property has been defined for a given class reference. |
static Color |
COLOR_MUST_BE_VALID
Special default value that ensures a valid Color is parsed (i.e. |
static Color |
COLOR_PARAM_MUST_EXIST
Special default value that ensures a property has been defined for a given colour value. |
static Double |
DOUBLE_MUST_BE_VALID
Special default value that ensures a valid floating-point value is parsed (i.e. |
static Double |
DOUBLE_PARAM_MUST_EXIST
Special default value that ensures a property has been defined for a given floating-point value. |
static File |
ENSURE_FILE_EXISTS
Special default value that ensures a valid File is parsed and references an existing file or a location where a new file can be created. |
static File |
ENSURE_FOLDER_EXISTS
Special default value that ensures a valid File is parsed and references an existing folder or a location where a new folder can be created. |
static File |
ENSURE_PARENT_FOLDER_EXISTS
Special default value that ensures a valid File is parsed and references a location within an existing folder or in a folder that can be created. |
static EnumValue |
ENUM_PARAM_MUST_EXIST
Special default value that ensures a property has been defined for a given enumeration value. |
static EnumValue |
ENUM_VALUE_MUST_BE_VALID
Special default value that ensures a valid Enumeration value is parsed (i.e. |
static File |
FILE_MUST_EXIST
Special default value that ensures a valid File is parsed and references a file that already exists on the file system. |
static File |
FILE_PARAM_MUST_EXIST
Special default value that ensures a property has been defined for a given file location. |
static File |
FOLDER_MUST_EXIST
Special default value that ensures a valid File is parsed and references a folder that already exists on the file system. |
static File |
FOLDER_PARAM_MUST_EXIST
Special default value that ensures a property has been defined for a given folder location. |
static Long |
LONG_MUST_BE_VALID
Special default value that ensures a valid integer value is parsed (i.e. |
static Long |
LONG_PARAM_MUST_EXIST
Special default value that ensures a property has been defined for a given integer value. |
static File |
PARENT_FOLDER_MUST_EXIST
Special default value that ensures a valid File is parsed and references a location within an existing folder on the file system. |
protected static long |
serialVersionUID
Version of class serialisation. |
protected static String |
UNDEFINED_SOURCE
A default source description. |
Fields inherited from class java.util.Properties |
---|
defaults |
Constructor Summary | |
---|---|
Properties()
Set-up an empty table of property values. |
|
Properties(File sourceFile)
Set-up a table of property values loaded from a given source file. |
|
Properties(Properties properties)
Set-up a table of property values copying values from another Properties table. |
|
Properties(Properties properties,
String sourceDescription)
Set-up a table of property values copying values from another Properties table, with a description of the
source of the property values. |
|
Properties(String sourceDescription)
Set-up an empty table of property values, with a description of the source of the property values. |
Method Summary | |
---|---|
Boolean |
getBooleanProperty(String key)
Parse a Boolean value from the property with given key. |
boolean |
getBooleanProperty(String key,
boolean defaultValue)
Parse a Boolean value from the property with given key, returning the default value if the property is missing or invalid. |
Boolean |
getBooleanProperty(String key,
Boolean defaultValue)
Parse a Boolean value from the property with given key, returning the default value if the property is missing or invalid. |
boolean |
getBooleanProperty(String key,
boolean defaultIfMissing,
boolean defaultIfInvalid)
Parse a Boolean value from the property with given key, returning one of the default values if the property is missing or invalid. |
Boolean |
getBooleanProperty(String key,
Boolean defaultIfMissing,
Boolean defaultIfInvalid)
Parse a Boolean value from the property with given key, returning one of the default values if the property is missing or invalid. |
Class |
getClassProperty(String key)
Parse a Java class from the property with given key. |
Class |
getClassProperty(String key,
Class defaultValue)
Parse a Java class from the property with given key, returning the default value if the property is missing or invalid. |
Class |
getClassProperty(String key,
Class defaultIfMissing,
Class defaultIfInvalid)
Parse a Java class from the property with given key, returning one of the default values if the property is missing or invalid. |
Class |
getClassProperty(String key,
String basePackage)
Parse a Java class from the property with given key. |
Class |
getClassProperty(String key,
String basePackage,
Class defaultValue)
Parse a Java class from the property with given key, returning the default value if the property is missing or invalid. |
Class |
getClassProperty(String key,
String basePackage,
Class defaultIfMissing,
Class defaultIfInvalid)
Parse a Java class from the property with given key, returning one of the default values if the property is missing or invalid. |
Color |
getColorProperty(String key)
Parse a Color from the property with given key. |
Color |
getColorProperty(String key,
Color defaultValue)
Parse a Color from the property with given key, returning
the default value if the property is missing or invalid. |
Color |
getColorProperty(String key,
Color defaultIfMissing,
Color defaultIfInvalid)
Parse a Color from the property with given key, returning
one of the default values if the property is missing or invalid. |
Double |
getDoubleProperty(String key)
Parse a numeric, floating-point value from the property with given key. |
double |
getDoubleProperty(String key,
double defaultValue)
Parse a numeric, floating-point value from the property with given key, returning the default value if the property is missing or invalid. |
Double |
getDoubleProperty(String key,
Double defaultValue)
Parse a numeric, floating-point value from the property with given key, returning the default value if the property is missing or invalid. |
double |
getDoubleProperty(String key,
double defaultIfMissing,
double defaultIfInvalid)
Parse a numeric, floating-point value from the property with given key, returning one of the default values if the property is missing or invalid. |
Double |
getDoubleProperty(String key,
Double defaultIfMissing,
Double defaultIfInvalid)
Parse a numeric, floating-point value from the property with given key, returning one of the default values if the property is missing or invalid. |
EnumValue |
getEnumProperty(String key,
Enumeration enumeration)
Parse an enumeration value from the property with given key. |
EnumValue |
getEnumProperty(String key,
Enumeration enumeration,
EnumValue defaultValue)
Parse an enumeration value from the property with given key, returning the default value if the property is missing or invalid. |
EnumValue |
getEnumProperty(String key,
Enumeration enumeration,
EnumValue defaultIfMissing,
EnumValue defaultIfInvalid)
Parse an enumeration value from the property with given key, returning one of the default values if the property is missing or invalid. |
File |
getFileProperty(File baseFolder,
String key)
Parse a file reference from the property with given key. |
File |
getFileProperty(File baseFolder,
String key,
File defaultValue)
Parse a file reference from the property with given key, returning the default value if the property is missing or invalid. |
File |
getFileProperty(File baseFolder,
String key,
File defaultIfMissing,
File defaultIfInvalid)
Parse a file reference from the property with given key, returning one of the default values if the property is missing or invalid. |
File |
getFileProperty(File baseFolder,
String key,
String defaultIfMissing,
File defaultIfInvalid)
Parse a file reference from the property with given key, returning one of the default values if the property is missing or invalid. |
File |
getFileProperty(String key)
Parse a file reference from the property with given key. |
File |
getFileProperty(String key,
File defaultValue)
Parse a file reference from the property with given key, returning the default value if the property is missing or invalid. |
File |
getFileProperty(String key,
File defaultIfMissing,
File defaultIfInvalid)
Parse a file reference from the property with given key, returning one of the default values if the property is missing or invalid. |
File |
getFileProperty(String key,
String defaultPath)
Parse a file reference from the property with given key, using the default file path if the property is missing or invalid. |
File |
getFileProperty(String key,
String defaultIfMissing,
File defaultIfInvalid)
Parse a file reference from the property with given key, returning one of the default values if the property is missing or invalid. |
File |
getFolderProperty(File baseFolder,
String key)
Parse a folder reference from the property with given key. |
File |
getFolderProperty(File baseFolder,
String key,
File defaultValue)
Parse a folder reference from the property with given key, returning the default value if the property is missing or invalid. |
File |
getFolderProperty(File baseFolder,
String key,
File defaultIfMissing,
File defaultIfInvalid)
Parse a folder reference from the property with given key, returning one of the default values if the property is missing or invalid. |
File |
getFolderProperty(File baseFolder,
String key,
String defaultIfMissing,
File defaultIfInvalid)
Parse a folder reference from the property with given key, returning one of the default values if the property is missing or invalid. |
File |
getFolderProperty(String key)
Parse a folder reference from the property with given key. |
File |
getFolderProperty(String key,
File defaultValue)
Parse a folder reference from the property with given key, returning the default value if the property is missing or invalid. |
File |
getFolderProperty(String key,
File defaultIfMissing,
File defaultIfInvalid)
Parse a folder reference from the property with given key, returning one of the default values if the property is missing or invalid. |
File |
getFolderProperty(String key,
String defaultIfMissing,
File defaultIfInvalid)
Parse a folder reference from the property with given key, returning one of the default values if the property is missing or invalid. |
Long |
getLongProperty(String key)
Parse a numeric, integer value from the property with given key. |
long |
getLongProperty(String key,
long defaultValue)
Parse a numeric, integer value from the property with given key, returning the default value if the property is missing or invalid. |
Long |
getLongProperty(String key,
Long defaultValue)
Parse a numeric, integer value from the property with given key, returning the default value if the property is missing or invalid. |
long |
getLongProperty(String key,
long defaultIfMissing,
long defaultIfInvalid)
Parse a numeric, integer value from the property with given key, returning one of the default values if the property is missing or invalid. |
Long |
getLongProperty(String key,
Long defaultIfMissing,
Long defaultIfInvalid)
Parse a numeric, integer value from the property with given key, returning one of the default values if the property is missing or invalid. |
String |
getStringProperty(String key)
Retrieve a String value from the property with given key. |
String |
getStringProperty(String key,
String defaultValue)
Retrieve a String value from the property with given key, returning the default value if the property is missing. |
void |
load()
Load property values from the source file. |
void |
load(File inFile)
Load property values from a specified file. |
void |
load(URL inUrl)
Load property values from a specified URL. |
void |
setBooleanProperty(String key,
boolean value)
Assign a Boolean value to a given property. |
void |
setBooleanProperty(String key,
Boolean value)
Assign a Boolean value to a given property. |
void |
setClassProperty(String key,
Class value)
Assign the name of a Java class to a given property. |
void |
setColorProperty(String key,
Color value)
Assign a color value to a given property. |
void |
setDoubleProperty(String key,
double value)
Assign a (floating-point) numeric value to a given property. |
void |
setDoubleProperty(String key,
Double value)
Assign a (floating-point) numeric value to a given property. |
void |
setEnumProperty(String key,
EnumValue value)
Assign an enumeration value to a given property. |
void |
setFileProperty(String key,
File value)
Assign a file path to a given property. |
void |
setFolderProperty(String key,
File value)
Assign a folder path to a given property. |
void |
setLongProperty(String key,
long value)
Assign an integer value to a given property. |
void |
setLongProperty(String key,
Long value)
Assign an integer value to a given property. |
void |
setSourceFile(File sourceFile)
Set the file that is used to persist these properties. |
void |
setStringProperty(String key,
String value)
Assign a text value to a given property. |
void |
store()
Store the property values into the source file. |
void |
store(File outFile,
String header)
Store the property values into a file at the given location. |
void |
store(String header)
Store the property values into the source file. |
Methods inherited from class java.util.Properties |
---|
getProperty, getProperty, list, list, load, loadFromXML, propertyNames, save, setProperty, store, storeToXML, storeToXML |
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 |
Field Detail |
---|
public static final Boolean BOOLEAN_PARAM_MUST_EXIST
getBooleanProperty(String,Boolean,Boolean)
public static final Long LONG_PARAM_MUST_EXIST
getLongProperty(String,Long,Long)
public static final Double DOUBLE_PARAM_MUST_EXIST
getDoubleProperty(String,Double,Double)
public static final File FILE_PARAM_MUST_EXIST
getFileProperty(String,File,File)
public static final File FOLDER_PARAM_MUST_EXIST
getFolderProperty(String,File,File)
public static final Class CLASS_PARAM_MUST_EXIST
getClassProperty(String,Class,Class)
public static final EnumValue ENUM_PARAM_MUST_EXIST
getEnumProperty(String,Enumeration,EnumValue)
public static final Color COLOR_PARAM_MUST_EXIST
getColorProperty(String,Color,Color)
public static final Boolean BOOLEAN_MUST_BE_VALID
getBooleanProperty(String,Boolean,Boolean)
public static final Long LONG_MUST_BE_VALID
getLongProperty(String,Long,Long)
public static final Double DOUBLE_MUST_BE_VALID
getDoubleProperty(String,Double,Double)
public static final File FILE_MUST_EXIST
getFileProperty(String,File,File)
public static final File ENSURE_FILE_EXISTS
getFileProperty(String,File,File)
public static final File FOLDER_MUST_EXIST
getFolderProperty(String,File,File)
public static final File ENSURE_FOLDER_EXISTS
getFolderProperty(String,File,File)
public static final File PARENT_FOLDER_MUST_EXIST
getFileProperty(String,File,File)
,
getFolderProperty(String,File,File)
public static final File ENSURE_PARENT_FOLDER_EXISTS
getFileProperty(String,File,File)
,
getFolderProperty(String,File,File)
public static final Class CLASS_MUST_BE_VALID
getClassProperty(String,Class,Class)
public static final EnumValue ENUM_VALUE_MUST_BE_VALID
getEnumProperty(String, Enumeration,EnumValue,EnumValue)
public static final Color COLOR_MUST_BE_VALID
getColorProperty(String,Color,Color)
protected static final String UNDEFINED_SOURCE
protected static final long serialVersionUID
protected String _sourceDescription
protected File _sourceFile
Constructor Detail |
---|
public Properties()
Properties( String )
constructor instead and specify a description of the properties table, so
that messages relating to property values can be put in context
public Properties(String sourceDescription)
sourceDescription
- a description of where the property values will
be loaded frompublic Properties(File sourceFile) throws IOException
store
or load
methods are
called it will be assumed the properties are to be stored/loaded from
this source file, unless a different file is stated.
sourceFile
- the file where the property values are to be loaded
from and stored to
IOException
- an error prevented the values being read from the
specified fileload()
,
store()
,
setSourceFile(java.io.File)
public Properties(Properties properties)
Properties
table.
Properties( Properties, String )
constructor instead and
specify a description of the properties table, so that messages relating
to property values can be put in context
properties
- initial values to be loaded into this properties tablepublic Properties(Properties properties, String sourceDescription)
Properties
table, with a description of the
source of the property values.
properties
- initial values to be loaded into this properties tablesourceDescription
- a description of where the property values will
be loaded fromMethod Detail |
---|
public void setSourceFile(File sourceFile)
store
or load
methods are
called it will be assumed the properties are to be stored/loaded from
this source file, unless a different file is stated.
sourceFile
- the file where the property values are to be loaded
and storedstore()
,
load()
public void load() throws FileNotFoundException, IOException
Properties
table (to remove values already loaded, use the
clear
method).
Properties( File )
constructor or by calling the
setSourceFile
method, then an exception will be thrown.
load
method of the java.util.Properties
class.
FileNotFoundException
- no source file has been defined for this
Properties
table or the
specified source file does not exist
IOException
- an error prevented the values being read from the
specified fileProperties.load(java.io.InputStream)
public void load(File inFile) throws FileNotFoundException, IOException
Properties
table (to remove values already loaded, use the
clear
method).
load
method of the java.util.Properties
class.
inFile
- the file where the property values are defined
FileNotFoundException
- the specified file does not exist
IOException
- an error prevented the values being read from the
specified fileProperties.load(java.io.InputStream)
public void load(URL inUrl) throws IOException
Properties
table (to remove values already loaded, use the
clear
method).
load
method of the java.util.Properties
class.
inUrl
- the location of the resource where the property values are
defined
IOException
- an error prevented the values being read from the
specified resourceProperties.load(java.io.InputStream)
public void store() throws IOException
IOException
- error writing the property values to the source filesetSourceFile(java.io.File)
public void store(String header) throws IOException
header
- a description of the property list
IOException
- error writing the property values to the source filesetSourceFile(java.io.File)
public void store(File outFile, String header) throws IOException
outFile
- the file where the property values are to be storedheader
- a description of the property list
IOException
- error writing the property values to the specified
filepublic String getStringProperty(String key) throws PropertyException
null
. Thus, the
following line of code will never cause a
NullPointerException
:
int strLen = myproperties.getStringProperty( key ).length();
PropertyException
if the property
does not exist.
key
- the name of the property to be read
PropertyException
- the property does not existpublic String getStringProperty(String key, String defaultValue)
null
provided the
defaultValue
is not null
. Thus, the following
line of code will never cause a NullPointerException
:
int strLen = myproperties.getStringProperty( key, default ).length();
key
- the name of the property to be readdefaultValue
- the value to be used if the property is missing
public void setStringProperty(String key, String value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic Boolean getBooleanProperty(String key) throws PropertyException
null
. Thus, the
following line of code will never cause a
NullPointerException
:
boolean value = myproperties.getBooleanProperty( key ).booleanValue();
PropertyException
if the property
value is invalid.
key
- the name of the property to be read
PropertyException
- the property does not exist or is invalidpublic Boolean getBooleanProperty(String key, Boolean defaultIfMissing, Boolean defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter is set to
Properties.BOOLEAN_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set to
Properties.BOOLEAN_MUST_BE_VALID
then an exception will
be thrown. Otherwise the defaultIfInvalid
value is returned.
null
provided neither of
the defaultValue
s are null
. Thus, the
following line of code will never cause a
NullPointerException
:
boolean value = myproperties.getBooleanProperty( key, default, default ).booleanValue();
PropertyException
if the property
value is invalid.
key
- the name of the property to be readdefaultIfMissing
- the Boolean value to use if the property is
missing (use
Properties.BOOLEAN_PARAM_MUST_EXIST
to cause an exception in such a situation)defaultIfInvalid
- the Boolean value to use if the property does not
specify a valid Boolean value (use
Properties.BOOLEAN_MUST_BE_VALID
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic Boolean getBooleanProperty(String key, Boolean defaultValue)
null
provided the
defaultValue
is not null
. Thus, the following
line of code will never cause a NullPointerException
:
boolean value = myproperties.getBooleanProperty( key, default ).booleanValue();
key
- the name of the property to be readdefaultValue
- the value to be used if the property is missing or
does not represent a Boolean value
public boolean getBooleanProperty(String key, boolean defaultValue)
key
- the name of the property to be readdefaultValue
- the value to be used if the property is missing or
does not represent a Boolean value
public boolean getBooleanProperty(String key, boolean defaultIfMissing, boolean defaultIfInvalid)
defaultIfMissing
value will be returned.
defaultIfInvalid
value is returned.
key
- the name of the property to be readdefaultIfMissing
- the value to be used if the property is missingdefaultIfInvalid
- the value to be used if the property does not
represent a Boolean value
public void setBooleanProperty(String key, Boolean value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic void setBooleanProperty(String key, boolean value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic Long getLongProperty(String key) throws PropertyException
null
. Thus, the
following lines of code will never cause a
NullPointerException
:
long value = myproperties.getLongProperty( key ).longValue();
int value = myproperties.getLongProperty( key ).intValue();
PropertyException
if the
property value is invalid.
key
- the name of the property to be read
PropertyException
- the property does not exist or is invalidpublic Long getLongProperty(String key, Long defaultIfMissing, Long defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter is set to
Properties.LONG_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is
set to Properties.LONG_MUST_BE_VALID
then an exception will
be thrown. Otherwise the defaultIfInvalid
value is returned.
null
provided neither of
the defaultValue
s are null
. Thus, the
following lines of code will never cause a
NullPointerException
:
long value = myproperties.getLongProperty( key, default, default ).longValue();
int value = myproperties.getLongProperty( key, default, default ).intValue();
PropertyException
if the property
value is invalid.
key
- the name of the property to be readdefaultIfMissing
- the number to use if the property is missing (use
Properties.LONG_PARAM_MUST_EXIST
to
cause an exception in such a situation)defaultIfInvalid
- the number to use if the property does not
specify a valid integer value (use
Properties.LONG_MUST_BE_VALID
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic Long getLongProperty(String key, Long defaultValue)
null
provided the
defaultValue
is not null
. Thus, the following
lines of code will never cause a NullPointerException
:
long value = myproperties.getLongProperty( key, default ).longValue();
int value = myproperties.getLongProperty( key, default ).intValue();
key
- the name of the property to be readdefaultValue
- the value to be used if the property is missing or
does not represent a numeric, integer value
public long getLongProperty(String key, long defaultValue)
key
- the name of the property to be readdefaultValue
- the value to be used if the property is missing or
does not represent a numeric, integer value
public long getLongProperty(String key, long defaultIfMissing, long defaultIfInvalid)
defaultIfMissing
value will be returned.
defaultIfInvalid
value is
returned.
key
- the name of the property to be readdefaultIfMissing
- the value to be used if the property is missingdefaultIfInvalid
- the value to be used if the property does not
represent a numeric, integer value
public void setLongProperty(String key, Long value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic void setLongProperty(String key, long value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic Double getDoubleProperty(String key) throws PropertyException
null
. Thus, the
following lines of code will never cause a
NullPointerException
:
double value = myproperties.getDoubleProperty( key ).doubleValue();
float value = myproperties.getDoubleProperty( key ).floatValue();
PropertyException
if the property
value is invalid.
key
- the name of the property to be read
PropertyException
- the property does not exist or is invalidpublic Double getDoubleProperty(String key, Double defaultIfMissing, Double defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter is set to
Properties.DOUBLE_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set to Properties.DOUBLE_MUST_BE_VALID
then an
exception will be thrown. Otherwise the defaultIfInvalid
value is returned.
null
provided neither of
the defaultValue
s are null
. Thus, the
following lines of code will never cause a
NullPointerException
:
double value = myproperties.getDoubleProperty( key, default, default ).doubleValue();
float value = myproperties.getDoubleProperty( key, default, default ).floatValue();
PropertyException
if the property
value is invalid.
key
- the name of the property to be readdefaultIfMissing
- the number to use if the property is missing (use
Properties.DOUBLE_PARAM_MUST_EXIST
to cause an exception in such a situation)defaultIfInvalid
- the number to use if the property does not
specify a valid floating-point value (use
Properties.DOUBLE_MUST_BE_VALID
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic Double getDoubleProperty(String key, Double defaultValue)
null
provided the
defaultValue
is not null
. Thus, the following
lines of code will never cause a NullPointerException
:
double value = myproperties.getDoubleProperty( key, default ).doubleValue();
float value = myproperties.getDoubleProperty( key, default ).floatValue();
key
- the name of the property to be readdefaultValue
- the value to be used if the property is missing or
does not represent a numeric, floating-point value
public double getDoubleProperty(String key, double defaultValue)
key
- the name of the property to be readdefaultValue
- the value to be used if the property is missing or
does not represent a numeric, floating-point value
public double getDoubleProperty(String key, double defaultIfMissing, double defaultIfInvalid)
defaultIfMissing
value will be returned.
defaultIfInvalid
value is returned.
key
- the name of the property to be readdefaultIfMissing
- the value to be used if the property is missingdefaultIfInvalid
- the value to be used if the property does not
represent a numeric, floating-point value
public void setDoubleProperty(String key, Double value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic void setDoubleProperty(String key, double value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic File getFileProperty(String key) throws PropertyException
null
.
key
- the name of the property to be read
PropertyException
- the property does not exist or is invalidpublic File getFileProperty(String key, File defaultIfMissing, File defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter is set to
Properties.FILE_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set to
Properties.FILE_MUST_EXIST
, an exception will be thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_FILE_EXISTS
, a new, empty file will be
created and a reference to that new file returned.
defaultIfInvalid
parameter is set to Properties.PARENT_FOLDER_MUST_EXIST
, an
exception will be thrown.
defaultIfInvalid
parameter is set to Properties.ENSURE_PARENT_FOLDER_EXISTS
,
the parent folder will be created and a reference to an inexistant file
(in a existant folder) will be returned.
null
provided neither of
the defaultValue
s are null
.
key
- the name of the property to be readdefaultIfMissing
- the file to use if the property is missing (use
Properties.FILE_PARAM_MUST_EXIST
to
cause an exception in such a situation)defaultIfInvalid
- the file to use if the property does not specify
a valid file (use
Properties.FILE_MUST_EXIST
to cause
an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic File getFileProperty(String key, String defaultIfMissing, File defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter will be used in place of the
property value.
defaultIfInvalid
parameter is set to
Properties.FILE_MUST_EXIST
, an exception will be thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_FILE_EXISTS
, a new, empty file will be
created and a reference to that new file returned.
defaultIfInvalid
parameter is set to
Properties.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder
will be created and a reference to an inexistant file (in an
existant folder) will be returned.
null
provided neither of
the defaultValue
s are null
. If
defaultIfInvalid
is set to
Properties.ENSURE_FILE_EXISTS
then the return value is
also guaranteed to reference a file that exists.
key
- the name of the property to be readdefaultIfMissing
- the path of the file to use if the property is
missingdefaultIfInvalid
- the file to use if the property does not
specify a valid file (use
Properties.FILE_MUST_EXIST
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic File getFileProperty(String key, File defaultValue)
null
provided the
defaultValue
is not null
.
key
- the name of the property to be readdefaultValue
- the file to use if the property is missing or invalid
public File getFileProperty(String key, String defaultPath)
null
provided the
defaultValue
is not null
.
key
- the name of the property to be readdefaultPath
- the file path to use if the property is missing or
invalid
public File getFileProperty(File baseFolder, String key) throws PropertyException
baseFolder
.
null
.
baseFolder
- the base/parent folder to use if the file path defined
by the string
is relative, rather than an
absolute pathkey
- the name of the property to be read
PropertyException
- the property does not exist or is invalidpublic File getFileProperty(File baseFolder, String key, File defaultIfMissing, File defaultIfInvalid) throws PropertyException
baseFolder
.
defaultIfMissing
parameter is set to
Properties.FILE_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set to
Properties.FILE_MUST_EXIST
, an exception will be thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_FILE_EXISTS
, a new, empty file will be
created and a reference to that new file returned.
defaultIfInvalid
parameter is set to Properties.PARENT_FOLDER_MUST_EXIST
, an
exception will be thrown.
defaultIfInvalid
parameter is set to Properties.ENSURE_PARENT_FOLDER_EXISTS
,
the parent folder will be created and a reference to an inexistant file
(in a existant folder) will be returned.
null
provided neither of
the defaultValue
s are null
.
baseFolder
- the base/parent folder to use if the file path defined
by the string
is relative, rather than an
absolute pathkey
- the name of the property to be readdefaultIfMissing
- the file to use if the property is missing (use
Properties.FILE_PARAM_MUST_EXIST
to
cause an exception in such a situation)defaultIfInvalid
- the file to use if the property does not specify
a valid file (use
Properties.FILE_MUST_EXIST
to cause
an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic File getFileProperty(File baseFolder, String key, String defaultIfMissing, File defaultIfInvalid) throws PropertyException
baseFolder
.
defaultIfMissing
parameter will be used in place of the
property value.
defaultIfInvalid
parameter is set to
Properties.FILE_MUST_EXIST
, an exception will be thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_FILE_EXISTS
, a new, empty file will be
created and a reference to that new file returned.
defaultIfInvalid
parameter is set to
Properties.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder
will be created and a reference to an inexistant file (in an
existant folder) will be returned.
null
provided neither of
the defaultValue
s are null
. If
defaultIfInvalid
is set to
Properties.ENSURE_FILE_EXISTS
then the return value is
also guaranteed to reference a file that exists.
baseFolder
- the base/parent folder to use if the file path defined
by the string
is relative, rather than an
absolute pathkey
- the name of the property to be readdefaultIfMissing
- the path of the file to use if the property is
missingdefaultIfInvalid
- the file to use if the property does not
specify a valid file (use
Properties.FILE_MUST_EXIST
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic File getFileProperty(File baseFolder, String key, File defaultValue)
baseFolder
.
null
provided the
defaultValue
is not null
.
baseFolder
- the base/parent folder to use if the file path defined
by the string
is relative, rather than an
absolute pathkey
- the name of the property to be readdefaultValue
- the file to use if the property is missing or invalid
public void setFileProperty(String key, File value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic File getFolderProperty(String key) throws PropertyException
null
. However, no
guarantee is made about the existance of the folder referenced by the
defaultValue
. Use
getFolderProperty( String key, String defaultIfMissing, File defaultIfInvalid )
and set defaultIfInvalid
to
Properties.ENSURE_FOLDER_EXISTS
to be sure the return value
references a folder that exists.
key
- the name of the property to be read
PropertyException
- the property does not exist or is invalidpublic File getFolderProperty(String key, File defaultIfMissing, File defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter is set to
Properties.FOLDER_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set to
Properties.FOLDER_MUST_EXIST
, an exception will be thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_FOLDER_EXISTS
, a new, empty folder will be
created and a reference to that new folder returned.
defaultIfInvalid
parameter is set to
Properties.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder
will be created and a reference to an inexistant sub-folder (of an
existant folder) will be returned.
null
provided neither of
the defaultValue
s are null
. However, no
guarantee is made about the existance of the folder referenced by the
defaultValue
. Use
getFolderProperty( String key, String defaultIfMissing, File defaultIfInvalid )
and set defaultIfInvalid
to
Properties.ENSURE_FOLDER_EXISTS
to be sure the return value
references a folder that exists.
key
- the name of the property to be readdefaultIfMissing
- the folder to use if the property is missing (use
Properties.FOLDER_PARAM_MUST_EXIST
to cause an exception in such a situation)defaultIfInvalid
- the folder to use if the property does not
specify a valid folder (use
Properties.FOLDER_MUST_EXIST
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic File getFolderProperty(String key, String defaultIfMissing, File defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter will be used in place of the
property value.
defaultIfInvalid
parameter is set to
Properties.FOLDER_MUST_EXIST
, an exception will be thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_FOLDER_EXISTS
, a new, empty folder will be
created and a reference to that new folder returned.
defaultIfInvalid
parameter is set to
Properties.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder
will be created and a reference to an inexistant sub-folder (of an
existant folder) will be returned.
null
provided neither of
the defaultValue
s are null
. If
defaultIfInvalid
is set to
Properties.ENSURE_FOLDER_EXISTS
then the return value is
also guaranteed to reference a folder that exists.
key
- the name of the property to be readdefaultIfMissing
- the path of the folder to use if the property is
missingdefaultIfInvalid
- the folder to use if the property does not
specify a valid folder (use
Properties.FOLDER_MUST_EXIST
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic File getFolderProperty(String key, File defaultValue)
null
provided the
defaultValue
is not null
. However, no guarantee
is made about the existance of the folder referenced by the
defaultValue
. Use
getFolderProperty( String key, String defaultIfMissing, File defaultIfInvalid )
and set defaultIfInvalid
to
Properties.ENSURE_FOLDER_EXISTS
to be sure the return value
references a folder that exists.
key
- the name of the property to be readdefaultValue
- the folder to use if the property is missing or
invalid
public File getFolderProperty(File baseFolder, String key) throws PropertyException
baseFolder
.
null
. However, no
guarantee is made about the existance of the folder referenced by the
defaultValue
. Use
getFolderProperty( File baseFolder, String key, String defaultIfMissing, File defaultIfInvalid )
and set defaultIfInvalid
to
Properties.ENSURE_FOLDER_EXISTS
to be sure the return value
references a folder that exists.
baseFolder
- the base/parent folder to use if the folder path
defined by the string
is relative, rather
than an absolute pathkey
- the name of the property to be read
PropertyException
- the property does not exist or is invalidpublic File getFolderProperty(File baseFolder, String key, File defaultIfMissing, File defaultIfInvalid) throws PropertyException
baseFolder
.
defaultIfMissing
parameter is set to
Properties.FOLDER_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set to
Properties.FOLDER_MUST_EXIST
, an exception will be thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_FOLDER_EXISTS
, a new, empty folder will be
created and a reference to that new folder returned.
defaultIfInvalid
parameter is set to
Properties.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder
will be created and a reference to an inexistant sub-folder (of an
existant folder) will be returned.
null
provided neither of
the defaultValue
s are null
. However, no
guarantee is made about the existance of the folder referenced by the
defaultValue
. Use
getFolderProperty( File baseFolder, String key, String defaultIfMissing, File defaultIfInvalid )
and set defaultIfInvalid
to
Properties.ENSURE_FOLDER_EXISTS
to be sure the return value
references a folder that exists.
baseFolder
- the base/parent folder to use if the folder path
defined by the string
is relative, rather
than an absolute pathkey
- the name of the property to be readdefaultIfMissing
- the folder to use if the property is missing (use
Properties.FOLDER_PARAM_MUST_EXIST
to cause an exception in such a situation)defaultIfInvalid
- the folder to use if the property does not
specify a valid folder (use
Properties.FOLDER_MUST_EXIST
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic File getFolderProperty(File baseFolder, String key, String defaultIfMissing, File defaultIfInvalid) throws PropertyException
baseFolder
.
defaultIfMissing
parameter will be used in place of the
property value.
defaultIfInvalid
parameter is set to
Properties.FOLDER_MUST_EXIST
, an exception will be thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_FOLDER_EXISTS
, a new, empty folder will be
created and a reference to that new folder returned.
defaultIfInvalid
parameter is set to
Properties.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultIfInvalid
parameter is set to
Properties.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder
will be created and a reference to an inexistant sub-folder (of an
existant folder) will be returned.
null
provided neither of
the defaultValue
s are null
. If
defaultIfInvalid
is set to
Properties.ENSURE_FOLDER_EXISTS
then the return value is
also guaranteed to reference a folder that exists.
baseFolder
- the base/parent folder to use if the folder path
defined by the string
is relative, rather
than an absolute pathkey
- the name of the property to be readdefaultIfMissing
- the path of the folder to use if the property is
missingdefaultIfInvalid
- the folder to use if the property does not
specify a valid folder (use
Properties.FOLDER_MUST_EXIST
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic File getFolderProperty(File baseFolder, String key, File defaultValue)
baseFolder
.
null
provided the
defaultValue
is not null
. However, no guarantee
is made about the existance of the folder referenced by the
defaultValue
. Use
getFolderProperty( File baseFolder, String key, String defaultIfMissing, File defaultIfInvalid )
and set defaultIfInvalid
to
Properties.ENSURE_FOLDER_EXISTS
to be sure the return value
references a folder that exists.
baseFolder
- the base/parent folder to use if the folder path
defined by the string
is relative, rather
than an absolute pathkey
- the name of the property to be readdefaultValue
- the folder to use if the property is missing or
invalid
public void setFolderProperty(String key, File value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic Class getClassProperty(String key) throws PropertyException
null
.
key
- the name of the property to be read
PropertyException
- the property does not exist or is invalidpublic Class getClassProperty(String key, Class defaultIfMissing, Class defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter is set to
Properties.CLASS_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set to
Properties.CLASS_MUST_EXIST
, an exception will be thrown.
null
provided neither of
the defaultValue
s are null
.
key
- the name of the property to be readdefaultIfMissing
- the class to use if the property is missing (use
Properties.CLASS_PARAM_MUST_EXIST
to cause an exception in such a situation)defaultIfInvalid
- the class to use if the property does not
specify a valid Java class (use
Properties.CLASS_MUST_BE_VALID
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic Class getClassProperty(String key, Class defaultValue)
null
provided the
defaultValue
is not null
.
key
- the name of the property to be readdefaultValue
- the class to use if the property is missing or
invalid
public Class getClassProperty(String key, String basePackage) throws PropertyException
basePackage
.
null
.
key
- the name of the property to be readbasePackage
- the base package path to use if the class name defined
by the parameter is not an absolute path
PropertyException
- the property does not exist or is invalidpublic Class getClassProperty(String key, String basePackage, Class defaultIfMissing, Class defaultIfInvalid) throws PropertyException
basePackage
.
defaultIfMissing
parameter is set to
Properties.CLASS_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set to
Properties.CLASS_MUST_EXIST
, an exception will be thrown.
null
provided neither of
the defaultValue
s are null
.
key
- the name of the property to be readbasePackage
- the base package path to use if the class name defined
by the parameter is not an absolute pathdefaultIfMissing
- the class to use if the property is missing (use
Properties.CLASS_PARAM_MUST_EXIST
to cause an exception in such a situation)defaultIfInvalid
- the class to use if the property does not
specify a valid Java class (use
Properties.CLASS_MUST_BE_VALID
to
cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic Class getClassProperty(String key, String basePackage, Class defaultValue)
basePackage
.
null
provided the
defaultValue
is not null
.
key
- the name of the property to be readbasePackage
- the base package path to use if the class name defined
by the parameter is not an absolute pathdefaultValue
- the folder to use if the property is missing or
invalid
public void setClassProperty(String key, Class value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic EnumValue getEnumProperty(String key, Enumeration enumeration) throws PropertyException
enumeration
then an exception will be
thrown.
null
.
key
- the name of the property to be readenumeration
- the enumeration type
PropertyException
- the property does not exist or is invalidpublic EnumValue getEnumProperty(String key, Enumeration enumeration, EnumValue defaultIfMissing, EnumValue defaultIfInvalid) throws PropertyException
defaultIfMissing
parameter is set to
Properties.ENUM_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
enumeration
and the
defaultIfInvalid
parameter is set to
Properties.ENUM_VALUE_MUST_BE_VALID
, an exception will be
thrown.
null
provided neither of
the defaultValue
s are null
.
key
- the name of the property to be readenumeration
- the enumeration typedefaultIfMissing
- the enumeration value to use if the property is
missing (use
Properties.ENUM_PARAM_MUST_EXIST
to cause an exception in such a situation)defaultIfInvalid
- the enumeration value to use if the property does
not equate to one of the enumeration values (use
Properties.ENUM_VALUE_MUST_BE_VALID
to cause an exception in such a situation)
PropertyException
- the property does not exist or is invalidpublic EnumValue getEnumProperty(String key, Enumeration enumeration, EnumValue defaultValue)
enumeration
then the default value will
be returned.
null
provided the
defaultValue
is not null
.
key
- the name of the property to be readenumeration
- the enumeration typedefaultValue
- the enumeration value to use if the property is
missing or invalid
public void setEnumProperty(String key, EnumValue value)
key
- the name of the property to be storedvalue
- the new value of the propertypublic Color getColorProperty(String key) throws PropertyException
Color
from the property with given key.
"[AAA] RRR GGG BBB"
where
AAA
, RRR
, GGG
and BBB
are 16-bit decimal values (0-255) for the alpha, red, green and blue
components of the colour (alpha optional) each separated by one or more
whitespace characters
"#[AA]RRGGBB"
where
AA
, RR
, GG
and BB
are
16-bit hex values for the alpha, red, green and blue components of the
colour (alpha optional)
"#[AA]RRGGBB"
format
defaultIfMissing
parameter is set to
Properties.COLOR_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set
to Properties.COLOR_VALUE_MUST_BE_VALID
, an exception will
be thrown.
enumeration
then an exception will be
thrown.
null
.
key
- the name of the property to be read
Color
object for the color specified by the
property value
PropertyException
- the property does not exist or is invalidpublic Color getColorProperty(String key, Color defaultIfMissing, Color defaultIfInvalid) throws PropertyException
Color
from the property with given key, returning
one of the default values if the property is missing or invalid.
"[AAA] RRR GGG BBB"
where
AAA
, RRR
, GGG
and BBB
are 16-bit decimal values (0-255) for the alpha, red, green and blue
components of the colour (alpha optional) each separated by one or more
whitespace characters
"#[AA]RRGGBB"
where
AA
, RR
, GG
and BB
are
16-bit hex values for the alpha, red, green and blue components of the
colour (alpha optional)
"#[AA]RRGGBB"
format
defaultIfMissing
parameter is set to
Properties.COLOR_PARAM_MUST_EXIST
then an exception will
be thrown. Otherwise the defaultIfMissing
value is returned.
defaultIfInvalid
parameter is set
to Properties.COLOR_VALUE_MUST_BE_VALID
, an exception will
be thrown.
null
provided neither of
the defaultValue
s are null
.
key
- the name of the property to be readdefaultIfMissing
- the value to use if the property is missing (use
Properties.ENUM_PARAM_MUST_EXIST
to cause an exception in such a situation)defaultIfInvalid
- the value to use if the property does not equate
to one of the enumeration values (use
Properties.ENUM_VALUE_MUST_BE_VALID
to cause an exception in such a situation)
Color
object for the color specified by the
property value, or the default value if the property value is
invalid
PropertyException
- the property does not exist or is invalidpublic Color getColorProperty(String key, Color defaultValue)
Color
from the property with given key, returning
the default value if the property is missing or invalid.
"[AAA] RRR GGG BBB"
where
AAA
, RRR
, GGG
and BBB
are 16-bit decimal values (0-255) for the alpha, red, green and blue
components of the colour (alpha optional) each separated by one or more
whitespace characters
"#[AA]RRGGBB"
where
AA
, RR
, GG
and BB
are
16-bit hex values for the alpha, red, green and blue components of the
colour (alpha optional)
"#[AA]RRGGBB"
format
null
provided the
defaultValue
is not null
.
key
- the name of the property to be readdefaultValue
- the value to use if the property is missing or
invalid
Color
object for the color specified by the
property value, or the default value if the property value is
invalidpublic void setColorProperty(String key, Color value)
key
- the name of the property to be storedvalue
- the new value of the property
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |