java.lang.Object | ||
↳ | java.util.prefs.Preferences | |
↳ | java.util.prefs.AbstractPreferences |
This abstract class is a partial implementation of the abstract class
Preferences, which can be used to simplify Preferences
provider's
implementation. This class defines nine abstract SPI methods, which must be
implemented by a preference provider.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.prefs.Preferences
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
lock | The object used to lock this node. | ||||||||||
newNode | This field is true if this node is created while it doesn't exist in the backing store. |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
AbstractPreferences instance using the given
parent node and node name. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the absolute path string of this preference node.
| |||||||||||
Registers a
NodeChangeListener instance for this node, which will
handle NodeChangeEvent s. | |||||||||||
Registers a
PreferenceChangeListener instance for this node,
which will handle PreferenceChangeEvent s. | |||||||||||
Returns the names of all children of this node or an empty array if this
node has no children.
| |||||||||||
Removes all preferences of this node.
| |||||||||||
Exports all of the preferences of this node to a XML document using the
given output stream.
| |||||||||||
Exports all of the preferences of this node and all its descendants to a
XML document using the given output stream.
| |||||||||||
Forces all pending updates to this node and its descendants to be
persisted in the backing store.
| |||||||||||
Gets the
String value mapped to the given key or its default
value if no value is mapped or no backing store is available. | |||||||||||
Gets the
boolean value mapped to the given key or its default
value if no value is mapped, if the backing store is unavailable, or if
the value is invalid. | |||||||||||
Gets the
byte array value mapped to the given key or its default
value if no value is mapped, if the backing store is unavailable, or if
the value is an invalid string. | |||||||||||
Gets the
double value mapped to the given key or its default
value if no value is mapped, if the backing store is unavailable, or if
the value is an invalid string. | |||||||||||
Gets the
float value mapped to the given key or its default value
if no value is mapped, if the backing store is unavailable, or if the
value is an invalid string. | |||||||||||
Gets the
int value mapped to the given key or its default value
if no value is mapped, if the backing store is unavailable, or if the
value is an invalid string. | |||||||||||
Gets the
long value mapped to the given key or its default value
if no value is mapped, if the backing store is unavailable, or if the
value is an invalid string. | |||||||||||
Returns whether this is a user preference node.
| |||||||||||
Returns all preference keys stored in this node or an empty array if no
key was found.
| |||||||||||
Returns the name of this node.
| |||||||||||
Returns the preference node with the given path name.
| |||||||||||
Returns whether the preference node with the given path name exists.
| |||||||||||
Returns the parent preference node of this node or
null if this
node is the root node. | |||||||||||
Adds a new preference to this node using the given key and value or
updates the value if a preference with the given key already exists.
| |||||||||||
Adds a new preference with a
boolean value to this node using the
given key and value or updates the value if a preference with the given
key already exists. | |||||||||||
Adds a new preference to this node using the given key and the string
form of the given value or updates the value if a preference with the
given key already exists.
| |||||||||||
Adds a new preference to this node using the given key and
double
value or updates the value if a preference with the
given key already exists. | |||||||||||
Adds a new preference to this node using the given key and
float
value or updates the value if a preference with the
given key already exists. | |||||||||||
Adds a new preference to this node using the given key and
int
value or updates the value if a preference with the
given key already exists. | |||||||||||
Adds a new preference to this node using the given key and
long
value or updates the value if a preference with the
given key already exists. | |||||||||||
Removes the preference mapped to the given key from this node.
| |||||||||||
Removes this preference node with all its descendants.
| |||||||||||
Removes the given
NodeChangeListener instance from this node. | |||||||||||
Removes the given
PreferenceChangeListener instance from this
node. | |||||||||||
Synchronizes the data of this preference node and its descendants with
the back-end preference store.
| |||||||||||
Returns a string representation of this node.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns an array of all cached child nodes.
| |||||||||||
Returns the child preference node with the given name, creating it
if it does not exist.
| |||||||||||
Returns the names of all of the child nodes of this node or an empty
array if this node has no children.
| |||||||||||
Flushes changes of this node to the backing store.
| |||||||||||
Returns the child node with the specified name or
null if it
doesn't exist. | |||||||||||
Gets the preference value mapped to the given key.
| |||||||||||
Returns whether this node has been removed by invoking the method
removeNode() . | |||||||||||
Returns an array of all preference keys of this node or an empty array if
no preferences have been found.
| |||||||||||
Puts the given key-value pair into this node.
| |||||||||||
Removes this node from the preference hierarchy tree.
| |||||||||||
Removes the preference with the specified key.
| |||||||||||
Synchronizes this node with the backing store.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.prefs.Preferences
| |||||||||||
From class
java.lang.Object
|
This field is true if this node is created while it doesn't exist in the backing store. This field's default value is false, and it is checked when the node creation is completed, and if it is true, the node change event will be fired for this node's parent.
Constructs a new AbstractPreferences
instance using the given
parent node and node name.
parent | the parent node of the new node or null to indicate
that the new node is a root node. |
---|---|
name | the name of the new node or an empty string to indicate that this node is called "root". |
IllegalArgumentException | if the name contains a slash character or is empty if parent is not null .
|
---|
Gets the absolute path string of this preference node.
Registers a NodeChangeListener
instance for this node, which will
handle NodeChangeEvent
s. NodeChangeEvent
s will be fired
when a child node has been added to or removed from this node.
ncl | the listener to be registered. |
---|
Registers a PreferenceChangeListener
instance for this node,
which will handle PreferenceChangeEvent
s. PreferenceChangeEvent
s will be fired when a preference has been added
to, removed from, or updated for this node.
pcl | the listener to be registered. |
---|
Returns the names of all children of this node or an empty array if this node has no children.
BackingStoreException |
---|
Removes all preferences of this node.
BackingStoreException |
---|
Exports all of the preferences of this node to a XML document using the given output stream.
This XML document uses the UTF-8 encoding and is written according to the DTD in its DOCTYPE declaration, which is the following:
<!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">Please note that (unlike the methods of this class that don't concern serialization), this call is not thread-safe.
ostream | the output stream to write the XML-formatted data to. |
---|
IOException | |
---|---|
BackingStoreException |
Exports all of the preferences of this node and all its descendants to a XML document using the given output stream.
This XML document uses the UTF-8 encoding and is written according to the DTD in its DOCTYPE declaration, which is the following:
<!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">Please note that (unlike the methods of this class that don't concern serialization), this call is not thread-safe.
ostream | the output stream to write the XML-formatted data to. |
---|
IOException | |
---|---|
BackingStoreException |
Forces all pending updates to this node and its descendants to be persisted in the backing store.
If this node has been removed, the invocation of this method only flushes this node, not its descendants.
BackingStoreException |
---|
Gets the String
value mapped to the given key or its default
value if no value is mapped or no backing store is available.
Some implementations may store default values in backing stores. In this case, if there is no value mapped to the given key, the stored default value is returned.
key | the preference key. |
---|---|
deflt | the default value, which will be returned if no value is mapped to the given key or no backing store is available. |
Gets the boolean
value mapped to the given key or its default
value if no value is mapped, if the backing store is unavailable, or if
the value is invalid.
The only valid values are the String
"true", which represents
true
and "false", which represents false
, ignoring case.
Some implementations may store default values in backing stores. In this case, if there is no value mapped to the given key, the stored default value is returned.
key | the preference key. |
---|---|
deflt | the default value, which will be returned if no value is mapped to the given key, if the backing store is unavailable, or if the value is invalid. |
Gets the byte
array value mapped to the given key or its default
value if no value is mapped, if the backing store is unavailable, or if
the value is an invalid string.
To be valid, the value string must be Base64-encoded binary data. The Base64 encoding is as defined in RFC 2045, section 6.8.
Some implementations may store default values in backing stores. In this case, if there is no value mapped to the given key, the stored default value is returned.
key | the preference key. |
---|---|
deflt | the default value, which will be returned if no value is mapped to the given key, if the backing store is unavailable, or if the value is invalid. |
Gets the double
value mapped to the given key or its default
value if no value is mapped, if the backing store is unavailable, or if
the value is an invalid string.
To be valid, the value string must be a string that can be converted to a
double
by Double.parseDouble(String)
.
Some implementations may store default values in backing stores. In this case, if there is no value mapped to the given key, the stored default value is returned.
key | the preference key. |
---|---|
deflt | the default value, which will be returned if no value is mapped to the given key, if the backing store is unavailable, or if the value is invalid. |
Gets the float
value mapped to the given key or its default value
if no value is mapped, if the backing store is unavailable, or if the
value is an invalid string.
To be valid, the value string must be a string that can be converted to a
float
by Float.parseFloat(String)
.
Some implementations may store default values in backing stores. In this case, if there is no value mapped to the given key, the stored default value is returned.
key | the preference key. |
---|---|
deflt | the default value, which will be returned if no value is mapped to the given key, if the backing store is unavailable, or if the value is invalid. |
Gets the int
value mapped to the given key or its default value
if no value is mapped, if the backing store is unavailable, or if the
value is an invalid string.
To be valid, the value string must be a string that can be converted to
an int
by Integer.parseInt(String)
.
Some implementations may store default values in backing stores. In this case, if there is no value mapped to the given key, the stored default value is returned.
key | the preference key. |
---|---|
deflt | the default value, which will be returned if no value is mapped to the given key, if the backing store is unavailable, or if the value is invalid. |
Gets the long
value mapped to the given key or its default value
if no value is mapped, if the backing store is unavailable, or if the
value is an invalid string.
To be valid, the value string must be a string that can be converted to a
long
by Long.parseLong(String)
.
Some implementations may store default values in backing stores. In this case, if there is no value mapped to the given key, the stored default value is returned.
key | the preference key. |
---|---|
deflt | the default value, which will be returned if no value is mapped to the given key, if the backing store is unavailable, or if the value is invalid. |
Returns whether this is a user preference node.
true
, if this is a user preference node, false
if
this is a system preference node.
Returns all preference keys stored in this node or an empty array if no key was found.
BackingStoreException |
---|
Returns the name of this node.
Returns the preference node with the given path name. The path name can be relative or absolute. The requested node and its ancestors will be created if they do not exist.
The path is treated as relative to this node if it doesn't start with a slash, otherwise it will be treated as an absolute path.
name | the path name of the requested preference node. |
---|
Returns whether the preference node with the given path name exists. The path is treated as relative to this node if it doesn't start with a slash, otherwise it is treated as an absolute path.
Please note that if this node has been removed, an invocation of this
node will throw an IllegalStateException
unless the given path is
an empty string, which will return false
.
name | the path name of the preference node to query. |
---|
true
, if the queried preference node exists, false
otherwise.BackingStoreException |
---|
Returns the parent preference node of this node or null
if this
node is the root node.
Adds a new preference to this node using the given key and value or updates the value if a preference with the given key already exists.
key | the preference key to be added or updated. |
---|---|
value | the preference value for the given key. |
Adds a new preference with a boolean
value to this node using the
given key and value or updates the value if a preference with the given
key already exists.
key | the preference key to be added or updated. |
---|---|
value | the preference boolean value for the given key. |
Adds a new preference to this node using the given key and the string form of the given value or updates the value if a preference with the given key already exists.
The string form of the value is the Base64-encoded binary data of the given byte array. The Base64 encoding is as defined in RFC 2045, section 6.8.
key | the preference key to be added or updated. |
---|---|
value | the preference value for the given key. |
Adds a new preference to this node using the given key and double
value or updates the value if a preference with the
given key already exists.
The value is stored in its string form, which is the result of invoking
Double.toString(double)
.
key | the preference key to be added or updated. |
---|---|
value | the preference value for the given key. |
Adds a new preference to this node using the given key and float
value or updates the value if a preference with the
given key already exists.
The value is stored in its string form, which is the result of invoking
Float.toString(float)
.
key | the preference key to be added or updated. |
---|---|
value | the preference value for the given key. |
Adds a new preference to this node using the given key and int
value or updates the value if a preference with the
given key already exists.
The value is stored in its string form, which is the result of invoking
Integer.toString(int)
.
key | the preference key to be added or updated. |
---|---|
value | the preference value for the given key. |
Adds a new preference to this node using the given key and long
value or updates the value if a preference with the
given key already exists.
The value is stored in its string form, which is the result of invoking
Long.toString(long)
.
key | the preference key to be added or updated. |
---|---|
value | the preference value for the given key. |
Removes the preference mapped to the given key from this node.
key | the key of the preference to be removed. |
---|
Removes this preference node with all its descendants. The removal won't
necessarily be persisted until the method flush()
is invoked.
BackingStoreException |
---|
Removes the given NodeChangeListener
instance from this node.
ncl | the listener to be removed. |
---|
Removes the given PreferenceChangeListener
instance from this
node.
pcl | the listener to be removed. |
---|
Synchronizes the data of this preference node and its descendants with the back-end preference store. Any changes found in the back-end data should be reflected in this node and its descendants, and at the same time any local changes to this node and descendants should be persisted.
BackingStoreException |
---|
Returns a string representation of this node. The format is "User/System Preference Node: " followed by this node's absolute path.
Returns an array of all cached child nodes.
Returns the child preference node with the given name, creating it if it does not exist. The caller of this method should ensure that the given name is valid and that this node has not been removed or cached. If the named node has just been removed, the implementation of this method must create a new one instead of reactivating the removed one.
The new creation is not required to be persisted immediately until the flush method will be invoked.
name | the name of the child preference to be returned. |
---|
Returns the names of all of the child nodes of this node or an empty array if this node has no children. The names of cached children are not required to be returned.
BackingStoreException | if the backing store is unavailable or causes an operation failure. |
---|
Flushes changes of this node to the backing store. This method should
only flush this node and should not include the descendant nodes. Any
implementation that wants to provide functionality to flush all nodes
at once should override the method flush()
.
BackingStoreException | if the backing store is unavailable or causes an operation failure. |
---|
Returns the child node with the specified name or null
if it
doesn't exist. Implementers can assume that the name supplied to this
method will be a valid node name string (conforming to the node naming
format) and will not correspond to a node that has been cached or
removed.
name | the name of the desired child node. |
---|
null
if it doesn't
exist.BackingStoreException | if the backing store is unavailable or causes an operation failure. |
---|
Gets the preference value mapped to the given key. The caller of this
method should ensure that the given key is valid and that this node has
not been removed. This method should not throw any exceptions but if it
does, the caller will ignore the exception, regarding it as a null
return value.
key | the given key to be searched for. |
---|
Returns whether this node has been removed by invoking the method removeNode()
.
true
, if this node has been removed, false
otherwise.
Returns an array of all preference keys of this node or an empty array if no preferences have been found. The caller of this method should ensure that this node has not been removed.
BackingStoreException | if the backing store is unavailable or causes an operation failure. |
---|
Puts the given key-value pair into this node. Caller of this method should ensure that both of the given values are valid and that this node has not been removed.
name | the given preference key. |
---|---|
value | the given preference value. |
Removes this node from the preference hierarchy tree. The caller of this
method should ensure that this node has no child nodes, which means the
method Preferences.removeNode()
should
invoke this method multiple-times in bottom-up pattern. The removal is
not required to be persisted until after it is flushed.
BackingStoreException | if the backing store is unavailable or causes an operation failure. |
---|
Removes the preference with the specified key. The caller of this method should ensure that the given key is valid and that this node has not been removed.
key | the key of the preference that is to be removed. |
---|
Synchronizes this node with the backing store. This method should only
synchronize this node and should not include the descendant nodes. An
implementation that wants to provide functionality to synchronize all
nodes at once should override the method sync()
.
BackingStoreException | if the backing store is unavailable or causes an operation failure. |
---|