|
|||||||||
| Home >> All >> gnu >> java >> util >> [ prefs overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
gnu.java.util.prefs
Class FileBasedPreferences

java.lang.Objectjava.util.prefs.Preferences
java.util.prefs.AbstractPreferences
gnu.java.util.prefs.FileBasedPreferences
- public class FileBasedPreferences
- extends java.util.prefs.AbstractPreferences
This is a simple file-based preference implementation which writes the preferences as properties files. A node is represented as a directory beneath the user's home directory. The preferences for the node are stored in a single properties file in that directory. Sub-nodes are stored in subdirectories. This implementation uses file locking to mediate access to the properties files.
| Field Summary | |
private static java.lang.String |
DATA_FILE
Name of the property file storing the data in a given directory. |
private java.io.File |
dataFile
The file holding the data for this node. |
private java.io.File |
directory
The directory corresponding to this preference node. |
private java.util.Properties |
properties
The data in this node. |
| Fields inherited from class java.util.prefs.AbstractPreferences |
lock, newNode |
| Fields inherited from class java.util.prefs.Preferences |
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH |
| Constructor Summary | |
(package private) |
FileBasedPreferences()
Create the root node for the file-based preferences. |
(package private) |
FileBasedPreferences(FileBasedPreferences parent,
java.lang.String name)
Create a new file-based preference object with the given parent and the given name. |
| Method Summary | |
protected java.lang.String[] |
childrenNamesSpi()
Returns the names of the sub nodes of this preference node. |
protected java.util.prefs.AbstractPreferences |
childSpi(java.lang.String name)
Returns a child note with the given name. |
protected void |
flushSpi()
Writes all entries of this preferences node that have not yet been written to the backing store and possibly creates this node in the backing store, if it does not yet exist. |
protected java.lang.String |
getSpi(java.lang.String key)
Returns the value associated with the key in this preferences node or null when the key does not exist in this preferences node. |
boolean |
isUserNode()
Returns true if this node comes from the user preferences tree, false if it comes from the system preferences tree. |
protected java.lang.String[] |
keysSpi()
Returns an (possibly empty) array with all the keys of the preference entries of this node. |
private void |
load()
|
protected void |
putSpi(java.lang.String key,
java.lang.String value)
Sets the value of the given preferences entry for this node. |
protected void |
removeNodeSpi()
Clears this node from this VM and removes it from the backing store. |
protected void |
removeSpi(java.lang.String key)
Removes the given key entry from this preferences node. |
protected void |
syncSpi()
Writes all entries of this preferences node that have not yet been written to the backing store and reads any entries that have changed in the backing store but that are not yet visible in this VM. |
| Methods inherited from class java.util.prefs.AbstractPreferences |
absolutePath, addNodeChangeListener, addPreferenceChangeListener, cachedChildren, childrenNames, clear, exportNode, exportSubtree, flush, get, getBoolean, getByteArray, getChild, getDouble, getFloat, getInt, getLong, isRemoved, keys, name, node, nodeExists, parent, put, putBoolean, putByteArray, putDouble, putFloat, putInt, putLong, remove, removeNode, removeNodeChangeListener, removePreferenceChangeListener, sync, toString |
| Methods inherited from class java.util.prefs.Preferences |
importPreferences, systemNodeForPackage, systemRoot, userNodeForPackage, userRoot |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
DATA_FILE
private static final java.lang.String DATA_FILE
- Name of the property file storing the data in a given directory.
- See Also:
- Constant Field Values
directory
private java.io.File directory
- The directory corresponding to this preference node.
dataFile
private java.io.File dataFile
- The file holding the data for this node.
properties
private java.util.Properties properties
- The data in this node.
| Constructor Detail |
FileBasedPreferences
FileBasedPreferences()
- Create the root node for the file-based preferences.
FileBasedPreferences
FileBasedPreferences(FileBasedPreferences parent, java.lang.String name)
- Create a new file-based preference object with the given parent
and the given name.
| Method Detail |
load
private void load()
isUserNode
public boolean isUserNode()
- Description copied from class:
java.util.prefs.AbstractPreferences - Returns true if this node comes from the user preferences tree, false
if it comes from the system preferences tree.
childrenNamesSpi
protected java.lang.String[] childrenNamesSpi() throws java.util.prefs.BackingStoreException
- Description copied from class:
java.util.prefs.AbstractPreferences - Returns the names of the sub nodes of this preference node.
This method only has to return any not yet cached child names,
but may return all names if that is easier. It must not return
null when there are no children, it has to return an empty array
in that case. Since this method must consult the backing store to
get all the sub node names it may throw a BackingStoreException.
Called by
childrenNames()with this node locked.
childSpi
protected java.util.prefs.AbstractPreferences childSpi(java.lang.String name)
- Description copied from class:
java.util.prefs.AbstractPreferences - Returns a child note with the given name.
This method is called by the
node()method (indirectly through thegetNode()helper method) with this node locked if a sub node with this name does not already exist in the child cache. If the child node did not aleady exist in the backing store the boolean fieldnewNodeof the returned node should be set.Note that this method should even return a non-null child node if the backing store is not available since it may not throw a
BackingStoreException.
keysSpi
protected java.lang.String[] keysSpi() throws java.util.prefs.BackingStoreException
- Description copied from class:
java.util.prefs.AbstractPreferences - Returns an (possibly empty) array with all the keys of the preference
entries of this node.
Called by
keys()with this node locked if this node has not been removed. May throw an exception when the backing store cannot be accessed.
getSpi
protected java.lang.String getSpi(java.lang.String key)
- Description copied from class:
java.util.prefs.AbstractPreferences - Returns the value associated with the key in this preferences node or
null when the key does not exist in this preferences node.
Called by
key()with this node locked after checking that key is valid, not null and that the node has not been removed.key()will catch any exceptions that this method throws.
putSpi
protected void putSpi(java.lang.String key, java.lang.String value)
- Description copied from class:
java.util.prefs.AbstractPreferences - Sets the value of the given preferences entry for this node.
The implementation is not required to propagate the change to the
backing store immediately. It may not throw an exception when it tries
to write to the backing store and that operation fails, the failure
should be registered so a later invocation of
flush()orsync()can signal the failure.Called by
put()with this node locked after checking that key and value are valid and non-null.
removeSpi
protected void removeSpi(java.lang.String key)
- Description copied from class:
java.util.prefs.AbstractPreferences - Removes the given key entry from this preferences node.
The implementation is not required to propagate the change to the
backing store immediately. It may not throw an exception when it tries
to write to the backing store and that operation fails, the failure
should be registered so a later invocation of
flush()orsync()can signal the failure.Called by
remove()with this node locked after checking that the key is valid and non-null.
flushSpi
protected void flushSpi()
throws java.util.prefs.BackingStoreException
- Description copied from class:
java.util.prefs.AbstractPreferences - Writes all entries of this preferences node that have not yet been
written to the backing store and possibly creates this node in the
backing store, if it does not yet exist. Should only write changes to
this node and not write changes to any subnodes.
Note that the node can be already removed in this VM. To check if
that is the case the implementation can call
isRemoved().Called (indirectly) by
flush()with this node locked.
syncSpi
protected void syncSpi()
throws java.util.prefs.BackingStoreException
- Description copied from class:
java.util.prefs.AbstractPreferences - Writes all entries of this preferences node that have not yet been
written to the backing store and reads any entries that have changed
in the backing store but that are not yet visible in this VM.
Should only sync this node and not change any of the subnodes.
Note that the node can be already removed in this VM. To check if
that is the case the implementation can call
isRemoved().Called (indirectly) by
sync()with this node locked.
removeNodeSpi
protected void removeNodeSpi()
throws java.util.prefs.BackingStoreException
- Description copied from class:
java.util.prefs.AbstractPreferences - Clears this node from this VM and removes it from the backing store.
After this method has been called the node is marked as removed.
Called (indirectly) by
removeNode()with this node locked after all the sub nodes of this node have already been removed.
|
|||||||||
| Home >> All >> gnu >> java >> util >> [ prefs overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC