| java.lang.Object net.sourceforge.groboutils.util.io.v1.PropertyDatabase
PropertyDatabase | public class PropertyDatabase (Code) | | A database of property files. Internally, it uses a
ResourceBundle, so that locale specific properties can be used.
The format is for the application defined property files to be defined
as "read-only", and for a user defined property file to be the
readable/writeable properties (i.e. modifications or additions or
removals of the default properties). User settings override the
read-only settings. The user property file is not localized, and is
stored at $home/.app-name/user.properties (or the filename
may be specified).
By default, the properties are loaded from the Resource streams,
although this can be changed.
Before using this class, you must initialize the user property file
by either
PropertyDatabase.setApplicationName(String) or
PropertyDatabase.setUserPropertyFile(String) .
The stored data is only of type String, and multiple identical key
entries are not possible - only the first one is allowed.
author: Matt Albrecht groboclown@users.sourceforge.net since: January 7, 2001 version: $Date: 2003/02/10 22:52:45 $ |
Method Summary | |
public void | addResourceBundle(String resourceName) Adds a resource bundle of the given name to the database, from the
specified locale. | protected void | autoSave() | public File | getApplicationDirectory() Returns the directory where the user properties are stored for the
current application, or null if there is no application set. | public boolean | getBooleanValue(String key) Convenience function to convert a property to a boolean value. | public byte | getByteValue(String key) Convenience function to convert a property to a byte value. | public char | getCharValue(String key) Convenience function to convert a property to a char value. | public double | getDoubleValue(String key) Convenience function to convert a property to a double value. | public float | getFloatValue(String key) Convenience function to convert a property to a float value. | public int | getIntValue(String key) Convenience function to convert a property to an int value. | public long | getLongValue(String key) Convenience function to convert a property to a long value. | public short | getShortValue(String key) Convenience function to convert a property to a short value. | public String | getValue(String key) Retrieves the value associated with the given key. | public boolean | isAutosaveOn() Retrieves the auto-save setting. | protected void | loadUserProperties() | public String | removeValue(String key) Removes a value from the properties. | public void | saveUserProperties() Saves the current user properties. | public void | setApplicationName(String name) Set the application name and thus the corresponding directory that will
store the user properties. | public void | setAutosaveOn(boolean yes) Sets the current autosave setting. | public void | setBooleanValue(String key, boolean value) Convenience function to convert a boolean value to a String property. | public void | setByteValue(String key, byte value) Convenience function to convert a byte value to a String property. | public void | setCharValue(String key, char value) Convenience function to convert a char value to a String property. | public void | setDoubleValue(String key, double value) Convenience function to convert a byte value to a String property. | public void | setFloatValue(String key, float value) Convenience function to convert a float value to a String property. | public void | setIntValue(String key, int value) Convenience function to convert an int value to a String property. | public void | setLongValue(String key, long value) Convenience function to convert a long value to a String property. | public void | setShortValue(String key, short value) Convenience function to convert a short value to a String property. | public void | setTrace(PrintWriter tracer) Sets the trace stream. | public void | setUserPropertyFile(String name) Set the user property file name exactly. | public void | setValue(String key, String value) Sets the given value to the user properties. | public String | setValueToDefault(String key) Resets the user property to the resource bundle's default value.
Parameters: key - the key to be reset. |
PropertyDatabase | public PropertyDatabase()(Code) | | Default Constructor
|
PropertyDatabase | public PropertyDatabase(Locale l)(Code) | | Specify the Locale to load the properties from.
|
addResourceBundle | public void addResourceBundle(String resourceName)(Code) | | Adds a resource bundle of the given name to the database, from the
specified locale. Note that
if a user property already exists with a given key, then the
user property overrides the resource property.
|
autoSave | protected void autoSave()(Code) | | |
getApplicationDirectory | public File getApplicationDirectory()(Code) | | Returns the directory where the user properties are stored for the
current application, or null if there is no application set.
|
getBooleanValue | public boolean getBooleanValue(String key)(Code) | | Convenience function to convert a property to a boolean value.
the given key converted to a boolean, or falseif there was a parse error. |
getByteValue | public byte getByteValue(String key)(Code) | | Convenience function to convert a property to a byte value.
the given key converted to a byte, or Byte.MIN_VALUEif there was a parse error. |
getCharValue | public char getCharValue(String key)(Code) | | Convenience function to convert a property to a char value.
the given key converted to a char, or Character.MIN_VALUEif there was a parse error. |
getDoubleValue | public double getDoubleValue(String key)(Code) | | Convenience function to convert a property to a double value.
the given key converted to a double, or Double.MIN_VALUEif there was a parse error. |
getFloatValue | public float getFloatValue(String key)(Code) | | Convenience function to convert a property to a float value.
the given key converted to a float, or Float.MIN_VALUEif there was a parse error. |
getIntValue | public int getIntValue(String key)(Code) | | Convenience function to convert a property to an int value.
the given key converted to an integer, or Integer.MIN_VALUEif there was a parse error. |
getLongValue | public long getLongValue(String key)(Code) | | Convenience function to convert a property to a long value.
the given key converted to a long, or Long.MIN_VALUEif there was a parse error. |
getShortValue | public short getShortValue(String key)(Code) | | Convenience function to convert a property to a short value.
the given key converted to a short, or Short.MIN_VALUEif there was a parse error. |
getValue | public String getValue(String key)(Code) | | Retrieves the value associated with the given key.
Parameters: key - the key to pull the value out of |
isAutosaveOn | public boolean isAutosaveOn()(Code) | | Retrieves the auto-save setting.
|
removeValue | public String removeValue(String key)(Code) | | Removes a value from the properties. If the property is defined
by a resource, then the user list must specify that it is
removed.
Parameters: key - the key to remove the value the key was assigned to, or null if nothingwas removed. |
saveUserProperties | public void saveUserProperties() throws IOException(Code) | | Saves the current user properties.
|
setApplicationName | public void setApplicationName(String name) throws IOException(Code) | | Set the application name and thus the corresponding directory that will
store the user properties. The user properties are located
at $home/.app-name/user.properties. If the user property
file is already set, then an IllegalStateException is thrown.
Parameters: name - name of the application. |
setAutosaveOn | public void setAutosaveOn(boolean yes)(Code) | | Sets the current autosave setting.
|
setBooleanValue | public void setBooleanValue(String key, boolean value)(Code) | | Convenience function to convert a boolean value to a String property.
|
setByteValue | public void setByteValue(String key, byte value)(Code) | | Convenience function to convert a byte value to a String property.
|
setCharValue | public void setCharValue(String key, char value)(Code) | | Convenience function to convert a char value to a String property.
|
setDoubleValue | public void setDoubleValue(String key, double value)(Code) | | Convenience function to convert a byte value to a String property.
|
setFloatValue | public void setFloatValue(String key, float value)(Code) | | Convenience function to convert a float value to a String property.
|
setIntValue | public void setIntValue(String key, int value)(Code) | | Convenience function to convert an int value to a String property.
|
setLongValue | public void setLongValue(String key, long value)(Code) | | Convenience function to convert a long value to a String property.
|
setShortValue | public void setShortValue(String key, short value)(Code) | | Convenience function to convert a short value to a String property.
|
setTrace | public void setTrace(PrintWriter tracer)(Code) | | Sets the trace stream. If you set this to non-null, then warnings,
such as ResourceBundles containing duplicate keys, will be reported
to the stream. Errors will still be thrown as exceptions. Autosave
will send any exceptions to this trace.
|
setUserPropertyFile | public void setUserPropertyFile(String name) throws IOException(Code) | | Set the user property file name exactly. If the user property file
is already set, then an IllegalStateException is thrown.
|
setValue | public void setValue(String key, String value)(Code) | | Sets the given value to the user properties.
Parameters: key - the key to assign the value to Parameters: value - the value to be assigned to the key |
setValueToDefault | public String setValueToDefault(String key)(Code) | | Resets the user property to the resource bundle's default value.
Parameters: key - the key to be reset. the default value for the key. |
|
|