|
Préférences
Moteurs de recherche
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.5.0
java.util.prefs
|
Field Summary | |
---|---|
protected Object |
lock
An object whose monitor is used to lock this node. |
protected boolean |
newNode
This field should be true if this node did not exist in the backing store prior to the creation of this object. |
Fields inherited from class java.util.prefs.Preferences |
---|
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH |
Constructor Summary | |
---|---|
protected |
AbstractPreferences(AbstractPreferences parent,
String name)
Creates a preference node with the specified parent and the specified name relative to its parent. |
Method Summary | |
---|---|
String |
absolutePath()
Implements the absolutePath method as per the specification in Preferences.absolutePath() . |
void |
addNodeChangeListener(NodeChangeListener ncl)
Registers the specified listener to receive node change events for this node. |
void |
addPreferenceChangeListener(PreferenceChangeListener pcl)
Registers the specified listener to receive preference change events for this preference node. |
protected AbstractPreferences[] |
cachedChildren()
Returns all known unremoved children of this node. |
String[] |
childrenNames()
Implements the children method as per the specification in Preferences.childrenNames() . |
protected abstract String[] |
childrenNamesSpi()
Returns the names of the children of this preference node. |
protected abstract AbstractPreferences |
childSpi(String name)
Returns the named child of this preference node, creating it if it does not already exist. |
void |
clear()
Implements the clear method as per the specification in Preferences.clear() . |
void |
exportNode(OutputStream os)
Implements the exportNode method as per the specification in Preferences.exportNode(OutputStream) . |
void |
exportSubtree(OutputStream os)
Implements the exportSubtree method as per the specification in Preferences.exportSubtree(OutputStream) . |
void |
flush()
Implements the flush method as per the specification in Preferences.flush() . |
protected abstract void |
flushSpi()
This method is invoked with this node locked. |
String |
get(String key,
String def)
Implements the get method as per the specification in Preferences.get(String,String) . |
boolean |
getBoolean(String key,
boolean def)
Implements the getBoolean method as per the specification in Preferences.getBoolean(String,boolean) . |
byte[] |
getByteArray(String key,
byte[] def)
Implements the getByteArray method as per the specification in Preferences.getByteArray(String,byte[]) . |
protected AbstractPreferences |
getChild(String nodeName)
Returns the named child if it exists, or null if it does not. |
double |
getDouble(String key,
double def)
Implements the getDouble method as per the specification in Preferences.getDouble(String,double) . |
float |
getFloat(String key,
float def)
Implements the getFloat method as per the specification in Preferences.getFloat(String,float) . |
int |
getInt(String key,
int def)
Implements the getInt method as per the specification in Preferences.getInt(String,int) . |
long |
getLong(String key,
long def)
Implements the getLong method as per the specification in Preferences.getLong(String,long) . |
protected abstract 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. |
protected boolean |
isRemoved()
Returns true iff this node (or an ancestor) has been removed with the removeNode() method. |
boolean |
isUserNode()
Implements the isUserNode method as per the specification in Preferences.isUserNode() . |
String[] |
keys()
Implements the keys method as per the specification in Preferences.keys() . |
protected abstract String[] |
keysSpi()
Returns all of the keys that have an associated value in this preference node. |
String |
name()
Implements the name method as per the specification in Preferences.name() . |
Preferences |
node(String path)
Implements the node method as per the specification in Preferences.node(String) . |
boolean |
nodeExists(String path)
Implements the nodeExists method as per the specification in Preferences.nodeExists(String) . |
Preferences |
parent()
Implements the parent method as per the specification in Preferences.parent() . |
void |
put(String key,
String value)
Implements the put method as per the specification in Preferences.put(String,String) . |
void |
putBoolean(String key,
boolean value)
Implements the putBoolean method as per the specification in Preferences.putBoolean(String,boolean) . |
void |
putByteArray(String key,
byte[] value)
Implements the putByteArray method as per the specification in Preferences.putByteArray(String,byte[]) . |
void |
putDouble(String key,
double value)
Implements the putDouble method as per the specification in Preferences.putDouble(String,double) . |
void |
putFloat(String key,
float value)
Implements the putFloat method as per the specification in Preferences.putFloat(String,float) . |
void |
putInt(String key,
int value)
Implements the putInt method as per the specification in Preferences.putInt(String,int) . |
void |
putLong(String key,
long value)
Implements the putLong method as per the specification in Preferences.putLong(String,long) . |
protected abstract void |
putSpi(String key,
String value)
Put the given key-value association into this preference node. |
void |
remove(String key)
Implements the remove(String) method as per the specification in Preferences.remove(String) . |
void |
removeNode()
Implements the removeNode() method as per the specification in Preferences.removeNode() . |
void |
removeNodeChangeListener(NodeChangeListener ncl)
Removes the specified NodeChangeListener, so it no longer receives change events. |
protected abstract void |
removeNodeSpi()
Removes this preference node, invalidating it and any preferences that it contains. |
void |
removePreferenceChangeListener(PreferenceChangeListener pcl)
Removes the specified preference change listener, so it no longer receives preference change events. |
protected abstract 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 abstract void |
syncSpi()
This method is invoked with this node locked. |
String |
toString()
Returns the absolute path name of this preferences node. |
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 |
---|
protected boolean newNode
protected final Object lock
Constructor Detail |
---|
protected AbstractPreferences(AbstractPreferences parent, String name)
parent
- the parent of this preference node, or null if this
is the root.name
- the name of this preference node, relative to its parent,
or "" if this is the root.
IllegalArgumentException
- if name contains a slash
('/'), or parent is null and
name isn't "".Method Detail |
---|
public void put(String key, String value)
Preferences.put(String,String)
.
This implementation checks that the key and value are legal,
obtains this preference node's lock, checks that the node
has not been removed, invokes putSpi(String,String)
, and if
there are any preference change listeners, enqueues a notification
event for processing by the event dispatch thread.
put
in class Preferences
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
NullPointerException
- if key or value is null.
IllegalArgumentException
- if key.length() exceeds
MAX_KEY_LENGTH or if value.length exceeds
MAX_VALUE_LENGTH.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.public String get(String key, String def)
Preferences.get(String,String)
.
This implementation first checks to see if key is
null throwing a NullPointerException if this is
the case. Then it obtains this preference node's lock,
checks that the node has not been removed, invokes getSpi(String)
, and returns the result, unless the getSpi
invocation returns null or throws an exception, in which case
this invocation returns def.
get
in class Preferences
key
- key whose associated value is to be returned.def
- the value to be returned in the event that this
preference node has no value associated with key.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.
NullPointerException
- if key is null. (A
null default is permitted.)public void remove(String key)
Preferences.remove(String)
.
This implementation obtains this preference node's lock,
checks that the node has not been removed, invokes
removeSpi(String)
and if there are any preference
change listeners, enqueues a notification event for processing by the
event dispatch thread.
remove
in class Preferences
key
- key whose mapping is to be removed from the preference node.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.public void clear() throws BackingStoreException
Preferences.clear()
.
This implementation obtains this preference node's lock,
invokes keys()
to obtain an array of keys, and
iterates over the array invoking remove(String)
on each key.
clear
in class Preferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.Preferences.removeNode()
public void putInt(String key, int value)
Preferences.putInt(String,int)
.
This implementation translates value to a string with
Integer.toString(int)
and invokes put(String,String)
on the result.
putInt
in class Preferences
key
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.
NullPointerException
- if key is null.
IllegalArgumentException
- if key.length() exceeds
MAX_KEY_LENGTH.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.Preferences.getInt(String,int)
public int getInt(String key, int def)
Preferences.getInt(String,int)
.
This implementation invokes get(key,
null)
. If the return value is non-null, the implementation
attempts to translate it to an int with
Integer.parseInt(String)
. If the attempt succeeds, the return
value is returned by this method. Otherwise, def is returned.
getInt
in class Preferences
key
- key whose associated value is to be returned as an int.def
- the value to be returned in the event that this
preference node has no value associated with key
or the associated value cannot be interpreted as an int.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.
NullPointerException
- if key is null.Preferences.putInt(String,int)
,
Preferences.get(String,String)
public void putLong(String key, long value)
Preferences.putLong(String,long)
.
This implementation translates value to a string with
Long.toString(long)
and invokes put(String,String)
on the result.
putLong
in class Preferences
key
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.
NullPointerException
- if key is null.
IllegalArgumentException
- if key.length() exceeds
MAX_KEY_LENGTH.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.Preferences.getLong(String,long)
public long getLong(String key, long def)
Preferences.getLong(String,long)
.
This implementation invokes get(key,
null)
. If the return value is non-null, the implementation
attempts to translate it to a long with
Long.parseLong(String)
. If the attempt succeeds, the return
value is returned by this method. Otherwise, def is returned.
getLong
in class Preferences
key
- key whose associated value is to be returned as a long.def
- the value to be returned in the event that this
preference node has no value associated with key
or the associated value cannot be interpreted as a long.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.
NullPointerException
- if key is null.Preferences.putLong(String,long)
,
Preferences.get(String,String)
public void putBoolean(String key, boolean value)
Preferences.putBoolean(String,boolean)
.
This implementation translates value to a string with
String.valueOf(boolean)
and invokes put(String,String)
on the result.
putBoolean
in class Preferences
key
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.
NullPointerException
- if key is null.
IllegalArgumentException
- if key.length() exceeds
MAX_KEY_LENGTH.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.Preferences.getBoolean(String,boolean)
,
Preferences.get(String,String)
public boolean getBoolean(String key, boolean def)
Preferences.getBoolean(String,boolean)
.
This implementation invokes get(key,
null)
. If the return value is non-null, it is compared with
"true" using String.equalsIgnoreCase(String)
. If the
comparison returns true, this invocation returns
true. Otherwise, the original return value is compared with
"false", again using String.equalsIgnoreCase(String)
.
If the comparison returns true, this invocation returns
false. Otherwise, this invocation returns def.
getBoolean
in class Preferences
key
- key whose associated value is to be returned as a boolean.def
- the value to be returned in the event that this
preference node has no value associated with key
or the associated value cannot be interpreted as a boolean.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.
NullPointerException
- if key is null.Preferences.get(String,String)
,
Preferences.putBoolean(String,boolean)
public void putFloat(String key, float value)
Preferences.putFloat(String,float)
.
This implementation translates value to a string with
Float.toString(float)
and invokes put(String,String)
on the result.
putFloat
in class Preferences
key
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.
NullPointerException
- if key is null.
IllegalArgumentException
- if key.length() exceeds
MAX_KEY_LENGTH.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.Preferences.getFloat(String,float)
public float getFloat(String key, float def)
Preferences.getFloat(String,float)
.
This implementation invokes get(key,
null)
. If the return value is non-null, the implementation
attempts to translate it to an float with
Float.parseFloat(String)
. If the attempt succeeds, the return
value is returned by this method. Otherwise, def is returned.
getFloat
in class Preferences
key
- key whose associated value is to be returned as a float.def
- the value to be returned in the event that this
preference node has no value associated with key
or the associated value cannot be interpreted as a float.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.
NullPointerException
- if key is null.Preferences.putFloat(String,float)
,
Preferences.get(String,String)
public void putDouble(String key, double value)
Preferences.putDouble(String,double)
.
This implementation translates value to a string with
Double.toString(double)
and invokes put(String,String)
on the result.
putDouble
in class Preferences
key
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.
NullPointerException
- if key is null.
IllegalArgumentException
- if key.length() exceeds
MAX_KEY_LENGTH.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.Preferences.getDouble(String,double)
public double getDouble(String key, double def)
Preferences.getDouble(String,double)
.
This implementation invokes get(key,
null)
. If the return value is non-null, the implementation
attempts to translate it to an double with
Double.parseDouble(String)
. If the attempt succeeds, the return
value is returned by this method. Otherwise, def is returned.
getDouble
in class Preferences
key
- key whose associated value is to be returned as a double.def
- the value to be returned in the event that this
preference node has no value associated with key
or the associated value cannot be interpreted as a double.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.
NullPointerException
- if key is null.Preferences.putDouble(String,double)
,
Preferences.get(String,String)
public void putByteArray(String key, byte[] value)
Preferences.putByteArray(String,byte[])
.
putByteArray
in class Preferences
key
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.
NullPointerException
- if key or value is null.
IllegalArgumentException
- if key.length() exceeds MAX_KEY_LENGTH
or if value.length exceeds MAX_VALUE_LENGTH*3/4.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.Preferences.getByteArray(String,byte[])
,
Preferences.get(String,String)
public byte[] getByteArray(String key, byte[] def)
Preferences.getByteArray(String,byte[])
.
getByteArray
in class Preferences
key
- key whose associated value is to be returned as a byte array.def
- the value to be returned in the event that this
preference node has no value associated with key
or the associated value cannot be interpreted as a byte array.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.
NullPointerException
- if key is null. (A
null value for def is permitted.)Preferences.get(String,String)
,
Preferences.putByteArray(String,byte[])
public String[] keys() throws BackingStoreException
Preferences.keys()
.
This implementation obtains this preference node's lock, checks that
the node has not been removed and invokes keysSpi()
.
keys
in class Preferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.public String[] childrenNames() throws BackingStoreException
Preferences.childrenNames()
.
This implementation obtains this preference node's lock, checks that
the node has not been removed, constructs a TreeSet initialized
to the names of children already cached (the children in this node's
"child-cache"), invokes childrenNamesSpi()
, and adds all of the
returned child-names into the set. The elements of the tree set are
dumped into a String array using the toArray method,
and this array is returned.
childrenNames
in class Preferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.cachedChildren()
protected final AbstractPreferences[] cachedChildren()
public Preferences parent()
Preferences.parent()
.
This implementation obtains this preference node's lock, checks that the node has not been removed and returns the parent value that was passed to this node's constructor.
parent
in class Preferences
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.public Preferences node(String path)
Preferences.node(String)
.
This implementation obtains this preference node's lock and checks
that the node has not been removed. If path is "",
this node is returned; if path is "/", this node's
root is returned. If the first character in path is
not '/', the implementation breaks path into
tokens and recursively traverses the path from this node to the
named node, "consuming" a name and a slash from path at
each step of the traversal. At each step, the current node is locked
and the node's child-cache is checked for the named node. If it is
not found, the name is checked to make sure its length does not
exceed MAX_NAME_LENGTH. Then the childSpi(String)
method is invoked, and the result stored in this node's child-cache.
If the newly created Preferences object's newNode
field is true and there are any node change listeners,
a notification event is enqueued for processing by the event dispatch
thread.
When there are no more tokens, the last value found in the child-cache or returned by childSpi is returned by this method. If during the traversal, two "/" tokens occur consecutively, or the final token is "/" (rather than a name), an appropriate IllegalArgumentException is thrown.
If the first character of path is '/'
(indicating an absolute path name name) this preference node's
lock is dropped prior to breaking path into tokens, and
this method recursively traverses the path starting from the root
(rather than starting from this node). The traversal is otherwise
identical to the one described for relative path names. Dropping
the lock on this node prior to commencing the traversal at the root
node is essential to avoid the possibility of deadlock, as per the
locking invariant
.
node
in class Preferences
path
- the path name of the preference node to return.
IllegalArgumentException
- if the path name is invalid (i.e.,
it contains multiple consecutive slash characters, or ends
with a slash character and is more than one character long).
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.Preferences.flush()
public boolean nodeExists(String path) throws BackingStoreException
Preferences.nodeExists(String)
.
This implementation is very similar to node(String)
,
except that getChild(String)
is used instead of childSpi(String)
.
nodeExists
in class Preferences
path
- the path name of the node whose existence is to be checked.
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.
IllegalArgumentException
- if the path name is invalid (i.e.,
it contains multiple consecutive slash characters, or ends
with a slash character and is more than one character long).
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method and
pathname is not the empty string ("").public void removeNode() throws BackingStoreException
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 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 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 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 Preferences
IllegalStateException
- if this node (or an ancestor) has already
been removed with the removeNode()
method.
UnsupportedOperationException
- if this method is invoked on
the root node.
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.Preferences.flush()
public String name()
Preferences.name()
.
This implementation merely returns the name that was passed to this node's constructor.
name
in class Preferences
public String absolutePath()
Preferences.absolutePath()
.
This implementation merely returns the absolute path name that was computed at the time that this node was constructed (based on the name that was passed to this node's constructor, and the names that were passed to this node's ancestors' constructors).
absolutePath
in class Preferences
public boolean isUserNode()
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 Preferences
public void addPreferenceChangeListener(PreferenceChangeListener pcl)
Preferences
Preferences.removeNode()
method, which generates a node change event.
Preference change events are generated by the clear
method.)
Events are only guaranteed for changes made within the same JVM as the registered listener, though some implementations may generate events for changes made outside this JVM. Events may be generated before the changes have been made persistent. Events are not generated when preferences are modified in descendants of this node; a caller desiring such events must register with each descendant.
addPreferenceChangeListener
in class Preferences
pcl
- The preference change listener to add.Preferences.removePreferenceChangeListener(PreferenceChangeListener)
,
Preferences.addNodeChangeListener(NodeChangeListener)
public void removePreferenceChangeListener(PreferenceChangeListener pcl)
Preferences
removePreferenceChangeListener
in class Preferences
pcl
- The preference change listener to remove.Preferences.addPreferenceChangeListener(PreferenceChangeListener)
public void addNodeChangeListener(NodeChangeListener ncl)
Preferences
Preferences.removeNode()
invocation results in multiple node change events, one for every
node in the subtree rooted at the removed node.)
Events are only guaranteed for changes made within the same JVM as the registered listener, though some implementations may generate events for changes made outside this JVM. Events may be generated before the changes have become permanent. Events are not generated when indirect descendants of this node are added or removed; a caller desiring such events must register with each descendant.
Few guarantees can be made regarding node creation. Because nodes are created implicitly upon access, it may not be feasible for an implementation to determine whether a child node existed in the backing store prior to access (for example, because the backing store is unreachable or cached information is out of date). Under these circumstances, implementations are neither required to generate node change events nor prohibited from doing so.
addNodeChangeListener
in class Preferences
ncl
- The NodeChangeListener to add.Preferences.removeNodeChangeListener(NodeChangeListener)
,
Preferences.addPreferenceChangeListener(PreferenceChangeListener)
public void removeNodeChangeListener(NodeChangeListener ncl)
Preferences
removeNodeChangeListener
in class Preferences
ncl
- The NodeChangeListener to remove.Preferences.addNodeChangeListener(NodeChangeListener)
protected abstract void putSpi(String key, String value)
This method is invoked with the lock on this node held.
protected abstract String getSpi(String key)
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.
protected abstract void removeSpi(String key)
This method is invoked with the lock on this node held.
protected abstract void removeNodeSpi() throws BackingStoreException
Preferences.removeNode()
method
invokes this method repeatedly in a bottom-up fashion, removing each of
a node's descendants before removing the node itself).
This method is invoked with the lock held on this node and its
parent (and all ancestors that are being removed as a
result of a single invocation to Preferences.removeNode()
).
The removal of a node needn't become persistent until the flush method is invoked on this node (or an ancestor).
If this node throws a BackingStoreException, the exception
will propagate out beyond the enclosing removeNode()
invocation.
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.protected abstract String[] keysSpi() throws BackingStoreException
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 keys()
invocation.
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.protected abstract String[] childrenNamesSpi() throws BackingStoreException
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 childrenNames()
invocation.
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.protected AbstractPreferences getChild(String nodeName) throws BackingStoreException
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 if he chooses to override this method.)
Finally, it is guaranteed that the named node has not been returned
by a previous invocation of this method or childSpi(java.lang.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. (The implementor
needn't maintain his own cache of previously returned children if he
chooses to override this method.)
This implementation obtains this preference node's lock, invokes
childrenNames()
to get an array of the names of this node's
children, and iterates over the array comparing the name of each child
with the specified node name. If a child node has the correct name,
the childSpi(String)
method is invoked and the resulting
node is returned. If the iteration completes without finding the
specified name, null is returned.
nodeName
- name of the child to be searched for.
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.protected abstract AbstractPreferences childSpi(String name)
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 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.
name
- The name of the child node to return, relative to
this preference node.
public String toString()
toString
in class Preferences
public void sync() throws BackingStoreException
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 Preferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.
IllegalStateException
- if this node (or an ancestor) has been
removed with the removeNode()
method.flush()
protected abstract void syncSpi() throws BackingStoreException
If this node throws a BackingStoreException, the exception
will propagate out beyond the enclosing sync()
invocation.
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
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 removeNode()
method, flushSpi() is invoked on this node,
but not on others.
flush
in class Preferences
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.flush()
protected abstract void flushSpi() throws BackingStoreException
If this node throws a BackingStoreException, the exception
will propagate out beyond the enclosing flush()
invocation.
BackingStoreException
- if this operation cannot be completed
due to a failure in the backing store, or inability to
communicate with it.protected boolean isRemoved()
removeNode()
method. This method
locks this node prior to returning the contents of the private
field used to track this state.
removeNode()
method.public void exportNode(OutputStream os) throws IOException, BackingStoreException
Preferences.exportNode(OutputStream)
.
exportNode
in class Preferences
os
- the output stream on which to emit the XML document.
IOException
- if writing to the specified output stream
results in an IOException.
BackingStoreException
- if preference data cannot be read from
backing store.Preferences.importPreferences(InputStream)
public void exportSubtree(OutputStream os) throws IOException, BackingStoreException
Preferences.exportSubtree(OutputStream)
.
exportSubtree
in class Preferences
os
- the output stream on which to emit the XML document.
IOException
- if writing to the specified output stream
results in an IOException.
BackingStoreException
- if preference data cannot be read from
backing store.Preferences.importPreferences(InputStream)
,
Preferences.exportNode(OutputStream)