public class FileSystemPreferences extends AbstractPreferences
Preferences
lock, newNode
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH
Constructor and Description |
---|
FileSystemPreferences(String path,
File lockFile,
boolean isUserNode) |
Modifier and Type | Method and Description |
---|---|
protected String[] |
childrenNamesSpi()
Returns the names of the children of this preference node.
|
protected AbstractPreferences |
childSpi(String name)
Returns the named child of this preference node, creating it if it does
not already exist.
|
void |
flush()
Implements the flush method as per the specification in
Preferences.flush() . |
protected void |
flushSpi()
This method is invoked with this node locked.
|
protected String |
getSpi(String key)
Return the value associated with the specified key at this preference
node, or null if there is no association for this key, or the
association cannot be determined at this time.
|
boolean |
isUserNode()
Implements the isUserNode method as per the specification in
Preferences.isUserNode() . |
protected String[] |
keysSpi()
Returns all of the keys that have an associated value in this
preference node.
|
protected void |
putSpi(String key,
String value)
Put the given key-value association into this preference node.
|
void |
removeNode()
Implements the removeNode() method as per the specification in
Preferences.removeNode() . |
protected void |
removeNodeSpi()
Called with file lock held (in addition to node locks).
|
protected void |
removeSpi(String key)
Remove the association (if any) for the specified key at this
preference node.
|
void |
sync()
Implements the sync method as per the specification in
Preferences.sync() . |
protected void |
syncSpi()
This method is invoked with this node locked.
|
absolutePath, addNodeChangeListener, addPreferenceChangeListener, cachedChildren, childrenNames, clear, exportNode, exportSubtree, get, getBoolean, getByteArray, getChild, getDouble, getFloat, getInt, getLong, isRemoved, keys, name, node, nodeExists, parent, put, putBoolean, putByteArray, putDouble, putFloat, putInt, putLong, remove, removeNodeChangeListener, removePreferenceChangeListener, toString
importPreferences, setPreferencesFactory, systemNodeForPackage, systemRoot, userNodeForPackage, userRoot
public boolean isUserNode()
AbstractPreferences
Preferences.isUserNode()
.
This implementation compares this node's root node (which is stored
in a private field) with the value returned by
Preferences.userRoot()
. If the two object references are
identical, this method returns true.
isUserNode
in class AbstractPreferences
protected void putSpi(String key, String value)
AbstractPreferences
This method is invoked with the lock on this node held.
putSpi
in class AbstractPreferences
protected String getSpi(String key)
AbstractPreferences
Generally speaking, this method should not throw an exception under any circumstances. If, however, if it does throw an exception, the exception will be intercepted and treated as a null return value.
This method is invoked with the lock on this node held.
getSpi
in class AbstractPreferences
protected void removeSpi(String key)
AbstractPreferences
This method is invoked with the lock on this node held.
removeSpi
in class AbstractPreferences
protected String[] keysSpi()
AbstractPreferences
This method is invoked with the lock on this node held.
If this node throws a BackingStoreException, the exception
will propagate out beyond the enclosing AbstractPreferences.keys()
invocation.
keysSpi
in class AbstractPreferences
protected String[] childrenNamesSpi()
AbstractPreferences
This method is invoked with the lock on this node held.
If this node throws a BackingStoreException, the exception
will propagate out beyond the enclosing AbstractPreferences.childrenNames()
invocation.
childrenNamesSpi
in class AbstractPreferences
protected AbstractPreferences childSpi(String name)
AbstractPreferences
Preferences.MAX_NAME_LENGTH
characters. Also, it is guaranteed that
this node has not been removed. (The implementor needn't check for any
of these things.)
Finally, it is guaranteed that the named node has not been returned
by a previous invocation of this method or AbstractPreferences.getChild(String)
after the last time that it was removed. In other words, a cached
value will always be used in preference to invoking this method.
Subclasses need not maintain their own cache of previously returned
children.
The implementer must ensure that the returned node has not been removed. If a like-named child of this node was previously removed, the implementer must return a newly constructed AbstractPreferences node; once removed, an AbstractPreferences node cannot be "resuscitated."
If this method causes a node to be created, this node is not guaranteed to be persistent until the flush method is invoked on this node or one of its ancestors (or descendants).
This method is invoked with the lock on this node held.
childSpi
in class AbstractPreferences
name
- The name of the child node to return, relative to
this preference node.public void removeNode() throws BackingStoreException
AbstractPreferences
Preferences.removeNode()
.
This implementation checks to see that this node is the root; if so,
it throws an appropriate exception. Then, it locks this node's parent,
and calls a recursive helper method that traverses the subtree rooted at
this node. The recursive method locks the node on which it was called,
checks that it has not already been removed, and then ensures that all
of its children are cached: The AbstractPreferences.childrenNamesSpi()
method is
invoked and each returned child name is checked for containment in the
child-cache. If a child is not already cached, the AbstractPreferences.childSpi(String)
method is invoked to create a Preferences
instance for it, and this instance is put into the child-cache. Then
the helper method calls itself recursively on each node contained in its
child-cache. Next, it invokes AbstractPreferences.removeNodeSpi()
, marks itself
as removed, and removes itself from its parent's child-cache. Finally,
if there are any node change listeners, it enqueues a notification
event for processing by the event dispatch thread.
Note that the helper method is always invoked with all ancestors up to the "closest non-removed ancestor" locked.
removeNode
in class AbstractPreferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.Preferences.flush()
protected void removeNodeSpi() throws BackingStoreException
removeNodeSpi
in class AbstractPreferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.public void sync() throws BackingStoreException
AbstractPreferences
Preferences.sync()
.
This implementation calls a recursive helper method that locks this node, invokes syncSpi() on it, unlocks this node, and recursively invokes this method on each "cached child." A cached child is a child of this node that has been created in this VM and not subsequently removed. In effect, this method does a depth first traversal of the "cached subtree" rooted at this node, calling syncSpi() on each node in the subTree while only that node is locked. Note that syncSpi() is invoked top-down.
sync
in class AbstractPreferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.AbstractPreferences.flush()
protected void syncSpi() throws BackingStoreException
AbstractPreferences
If this node throws a BackingStoreException, the exception
will propagate out beyond the enclosing AbstractPreferences.sync()
invocation.
syncSpi
in class AbstractPreferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.public void flush() throws BackingStoreException
AbstractPreferences
Preferences.flush()
.
This implementation calls a recursive helper method that locks this node, invokes flushSpi() on it, unlocks this node, and recursively invokes this method on each "cached child." A cached child is a child of this node that has been created in this VM and not subsequently removed. In effect, this method does a depth first traversal of the "cached subtree" rooted at this node, calling flushSpi() on each node in the subTree while only that node is locked. Note that flushSpi() is invoked top-down.
If this method is invoked on a node that has been removed with
the AbstractPreferences.removeNode()
method, flushSpi() is invoked on this node,
but not on others.
flush
in class AbstractPreferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.AbstractPreferences.flush()
protected void flushSpi() throws BackingStoreException
AbstractPreferences
If this node throws a BackingStoreException, the exception
will propagate out beyond the enclosing AbstractPreferences.flush()
invocation.
flushSpi
in class AbstractPreferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.