|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.Dictionary
java.util.Hashtable
java.util.Properties
org.nees.util.XProperties
java.util.Properties object may be used.
An extended properties class. The specific problems it solves are as follows.
- methods for saving/getting specific types (see below) This saves having a lot of little snippets to make
things like dates and numbers over and over
- methods for adding (vs. simply replacing) values from another property file
- methods for loading from other sources
- a few more convenient constructors.
There is a main method to test this. It takes a single argument which is a file name which will be created (thereby allowing a test of writing a file and reading it.)
Int as an entry means there are two methods named setInt and getInt)
or the explicit names of these are given. The last column gives a bit more description.
| Property Summary | ||
| Type | Set/Get | Description |
java.util.Date |
Date |
A standard Java date. This is actually stored as a long. |
integer |
Int |
An integer. |
long |
Long |
A long |
String |
String |
A string. Note that the values are escaped in the resulting properties file. |
boolean |
Boolean |
A boolean value. This automatically parses values of yes, enable(d), ok, true, yup, yeah and 1 to be logical true and false,
no, disable(d), nope, off, nay or 0 to be logical false. These are case insensitive. If the value is not recognized an exception is thrown. |
bytes array |
Bytes |
This will store or retrieve an arbitrary array of bytes |
serializable java object |
Serializable |
Works if the object implements the java.io.Serializable interface. |
serializable list |
SerializableList |
An array of java objects each of which implements the java.io.Serializable interface. |
file |
getFile(key), getFile(key, parent), setFileName |
This will store a file name in the properties. There are two getters, so that if the users needs to resolve the file against a specific parent (vs. the java default of the invocation directory) it may be done. |
| Field Summary | |
static java.lang.String |
DEFAULT_LIST_SEPARATOR
|
static java.lang.String[] |
LOGICAL_FALSES
Strings this will treat as equivalent to logical false. |
static java.lang.String[] |
LOGICAL_TRUES
Strings that this will treat as equivalent to logical true. |
| Fields inherited from class java.util.Properties |
defaults |
| Constructor Summary | |
XProperties()
Creates a new instance of XProperty |
|
XProperties(java.io.File file)
|
|
XProperties(java.util.Properties p)
Same as the constructor in the superclass, this gives this object all the same properties as the argument. |
|
XProperties(java.util.Properties[] sources,
boolean overwrite)
This will allow for an array of Properties objects. |
|
XProperties(java.util.Properties[] sources,
boolean[] overwrite)
This will instantiate the properties taking the value ssupplied. |
|
XProperties(java.lang.String fileName)
Convenience method. |
|
| Method Summary | |
void |
add(java.util.Properties[] sources,
boolean overwrite)
|
void |
add(java.util.Properties[] sources,
boolean[] overwrite)
Adds each property set with a flag for the set indicating overwrite permission. |
void |
add(java.util.Properties source,
boolean overwrite)
|
java.lang.Object |
clone()
|
boolean |
equals(java.lang.Object obj)
|
boolean |
getBoolean(java.lang.String key)
Retrieves the boolean value. |
byte[] |
getBytes(java.lang.String key)
|
XProperties |
getClone()
|
java.util.Date |
getDate(java.lang.String key)
|
double |
getDouble(java.lang.String key)
|
java.io.File |
getFile(java.lang.String key)
Retrieve the file stored by this key, resolving it against the given invocation directory. |
java.io.File |
getFile(java.lang.String key,
java.io.File parent)
Retrieve the file stored by this key, resolving it against the given file. |
int |
getInt(java.lang.String key)
|
java.lang.String[] |
getList(java.lang.String key)
|
java.lang.String[] |
getList(java.lang.String key,
java.lang.String separator)
This will take a comma separated list and return a vector of strings. |
java.lang.String |
getListSeparator()
|
long |
getLong(java.lang.String key)
|
java.lang.Object |
getSerializable(java.lang.String key)
Stores a single serializable java object. |
java.lang.Object[] |
getSerializableList(java.lang.String key)
Retrieves a list of serializable objects from the property. |
java.lang.String |
getString(java.lang.String key)
|
java.net.URI |
getURI(java.lang.String key)
|
boolean |
isEmpty()
This will return true if the current properties has no entries and false
otherwise. |
protected boolean |
keySubset(XProperties b)
Checks that the keys of b are a subset of the keys in this. |
void |
load(java.io.File f)
The parent class really needs one of these... |
static void |
main(java.lang.String[] args)
This exists simply for testing this object. |
void |
setBoolean(java.lang.String key,
boolean value)
Sets the given boolean value. |
void |
setBytes(java.lang.String key,
byte[] ba)
|
void |
setDate(java.lang.String key,
java.util.Date d)
|
void |
setDouble(java.lang.String key,
double value)
|
void |
setFile(java.lang.String key,
java.io.File f)
Puts the file name into the properties, (not) the contents! This will not be portable between platforms, since this is the full path, properly escaped. |
void |
setInt(java.lang.String key,
int value)
|
void |
setList(java.lang.String key,
java.lang.String list)
This sets a list directly, so the list itself is not touched. |
void |
setList(java.lang.String key,
java.lang.String[] list)
|
void |
setList(java.lang.String key,
java.lang.String[] list,
java.lang.String separator)
|
void |
setListSeparator(java.lang.String listSeparator)
|
void |
setLong(java.lang.String key,
long value)
|
java.lang.Object |
setProperty(java.lang.String key,
java.lang.String value)
A bug fix for Properties... |
void |
setSerializable(java.lang.String key,
java.io.Serializable object)
Retrieves a single serializable java object.Don't for get that you need to have any classes for this available to the current virtual machine to correctly deserialize the result. |
void |
setSerializableList(java.lang.String key,
java.lang.Object[] oList)
Stores a list of serializable java objects in the properties. |
void |
setString(java.lang.String key,
java.lang.String value)
|
void |
setURI(java.lang.String key,
java.lang.String uriString)
A convenience. |
void |
setURI(java.lang.String key,
java.net.URI uri)
|
| Methods inherited from class java.util.Properties |
getProperty, getProperty, list, list, load, propertyNames, save, store |
| Methods inherited from class java.util.Hashtable |
clear, contains, containsKey, containsValue, elements, entrySet, get, hashCode, 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 java.lang.String DEFAULT_LIST_SEPARATOR
public static java.lang.String[] LOGICAL_TRUES
public static java.lang.String[] LOGICAL_FALSES
| Constructor Detail |
public XProperties()
public XProperties(java.lang.String fileName)
throws java.lang.Exception
fileName -
java.lang.Exception
public XProperties(java.io.File file)
throws java.lang.Exception
public XProperties(java.util.Properties p)
Grrrrr this is busted in the super class (!!). This works here...
public XProperties(java.util.Properties[] sources,
boolean overwrite)
sources - overwrite -
public XProperties(java.util.Properties[] sources,
boolean[] overwrite)
throws java.lang.Exception
sources - overwrite -
java.lang.Exception - thrown if the list of properties and flags is not the same length.| Method Detail |
public java.lang.String getListSeparator()
public void setListSeparator(java.lang.String listSeparator)
public boolean getBoolean(java.lang.String key)
throws java.lang.Exception
true, ok, yes, 1 are equivalent to
logical true. Any of false, no, 0 are equivalent to logical false. All
comparisons are done case-insensitive
key -
java.lang.Exception - if no recognized logical value is supplied.
public void setBoolean(java.lang.String key,
boolean value)
key - value -
public int getInt(java.lang.String key)
throws java.lang.Exception
key -
java.lang.Exception
public void setInt(java.lang.String key,
int value)
key - value -
public long getLong(java.lang.String key)
throws java.lang.Exception
key -
java.lang.Exception
public void setLong(java.lang.String key,
long value)
key - value -
public java.io.File getFile(java.lang.String key)
throws java.lang.Exception
key -
java.lang.Exception
public java.io.File getFile(java.lang.String key,
java.io.File parent)
throws java.lang.Exception
key - parent -
java.lang.Exception
public void setFile(java.lang.String key,
java.io.File f)
throws java.lang.Exception
key - f -
java.lang.Exceptionpublic java.lang.String getString(java.lang.String key)
key -
public void setString(java.lang.String key,
java.lang.String value)
key - value - public java.lang.Object getSerializable(java.lang.String key)
key -
public void setSerializable(java.lang.String key,
java.io.Serializable object)
key - object -
public void setSerializableList(java.lang.String key,
java.lang.Object[] oList)
throws java.lang.Exception
key - oList -
java.lang.Exception
public java.lang.Object[] getSerializableList(java.lang.String key)
throws java.lang.Exception
key -
java.lang.Exception
public byte[] getBytes(java.lang.String key)
throws java.lang.Exception
key -
java.lang.Exception
public void setBytes(java.lang.String key,
byte[] ba)
throws java.lang.Exception
key - ba -
java.lang.Exception
public void setDouble(java.lang.String key,
double value)
throws java.lang.Exception
key - value -
java.lang.Exception
public double getDouble(java.lang.String key)
throws java.lang.Exception
key -
java.lang.Exception
public void load(java.io.File f)
throws java.lang.Exception
f - the file
java.lang.Exception
public java.lang.Object setProperty(java.lang.String key,
java.lang.String value)
NullPointerException. This is intercepted here.
public void add(java.util.Properties source,
boolean overwrite)
public void add(java.util.Properties[] sources,
boolean overwrite)
sources - overwrite -
public void add(java.util.Properties[] sources,
boolean[] overwrite)
throws java.lang.Exception
sources - overwrite -
java.lang.Exception - thrown if the arguments are not the same length.
public void setDate(java.lang.String key,
java.util.Date d)
throws java.lang.Exception
key - d -
java.lang.Exception
public java.net.URI getURI(java.lang.String key)
throws java.lang.Exception
java.lang.Exception
public void setURI(java.lang.String key,
java.net.URI uri)
throws java.lang.Exception
java.lang.Exception
public void setURI(java.lang.String key,
java.lang.String uriString)
throws java.lang.Exception
java.lang.Exception
public java.util.Date getDate(java.lang.String key)
throws java.lang.Exception
key -
java.lang.Exception
public java.lang.String[] getList(java.lang.String key,
java.lang.String separator)
throws java.lang.Exception
java.lang.Exception
public java.lang.String[] getList(java.lang.String key)
throws java.lang.Exception
java.lang.Exception
public void setList(java.lang.String key,
java.lang.String list)
throws java.lang.Exception
setString(key,list) and is simply provided as a convenience.
java.lang.Exception
public void setList(java.lang.String key,
java.lang.String[] list)
throws java.lang.Exception
java.lang.Exception
public void setList(java.lang.String key,
java.lang.String[] list,
java.lang.String separator)
throws java.lang.Exception
java.lang.Exceptionpublic boolean isEmpty()
true if the current properties has no entries and false
otherwise.
public java.lang.Object clone()
public XProperties getClone()
public boolean equals(java.lang.Object obj)
protected boolean keySubset(XProperties b)
public static void main(java.lang.String[] args)
args -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||