public abstract class AbstractPreferences extends Preferences
Preferences provider's
implementation. This class defines nine abstract SPI methods, which must be
implemented by a preference provider.Preferences| Modifier and Type | Field and Description |
|---|---|
protected Object |
lock
The object used to lock this node.
|
protected boolean |
newNode
This field is true if this node is created while it doesn't exist in the
backing store.
|
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH| Modifier | Constructor and Description |
|---|---|
protected |
AbstractPreferences(AbstractPreferences parent,
String name)
Constructs a new
AbstractPreferences instance using the given
parent node and node name. |
| Modifier and Type | Method and Description |
|---|---|
String |
absolutePath()
Gets the absolute path string of this preference node.
|
void |
addNodeChangeListener(NodeChangeListener ncl)
Registers a
NodeChangeListener instance for this node, which will
handle NodeChangeEvents. |
void |
addPreferenceChangeListener(PreferenceChangeListener pcl)
Registers a
PreferenceChangeListener instance for this node,
which will handle PreferenceChangeEvents. |
protected AbstractPreferences[] |
cachedChildren()
Returns an array of all cached child nodes.
|
String[] |
childrenNames()
Returns the names of all children of this node or an empty array if this
node has no children.
|
protected abstract String[] |
childrenNamesSpi()
Returns the names of all of the child nodes of this node or an empty
array if this node has no children.
|
protected abstract AbstractPreferences |
childSpi(String name)
Returns the child preference node with the given name, creating it
if it does not exist.
|
void |
clear()
Removes all preferences of this node.
|
void |
exportNode(OutputStream ostream)
Exports all of the preferences of this node to a XML document using the
given output stream.
|
void |
exportSubtree(OutputStream ostream)
Exports all of the preferences of this node and all its descendants to a
XML document using the given output stream.
|
void |
flush()
Forces all pending updates to this node and its descendants to be
persisted in the backing store.
|
protected abstract void |
flushSpi()
Flushes changes of this node to the backing store.
|
String |
get(String key,
String deflt)
Gets the
String value mapped to the given key or its default
value if no value is mapped or no backing store is available. |
boolean |
getBoolean(String key,
boolean deflt)
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. |
byte[] |
getByteArray(String key,
byte[] deflt)
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. |
protected AbstractPreferences |
getChild(String name)
Returns the child node with the specified name or
null if it
doesn't exist. |
double |
getDouble(String key,
double deflt)
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. |
float |
getFloat(String key,
float deflt)
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. |
int |
getInt(String key,
int deflt)
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. |
long |
getLong(String key,
long deflt)
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. |
protected abstract String |
getSpi(String key)
Gets the preference value mapped to the given key.
|
protected boolean |
isRemoved()
Returns whether this node has been removed by invoking the method
removeNode(). |
boolean |
isUserNode()
Returns whether this is a user preference node.
|
String[] |
keys()
Returns all preference keys stored in this node or an empty array if no
key was found.
|
protected abstract String[] |
keysSpi()
Returns an array of all preference keys of this node or an empty array if
no preferences have been found.
|
String |
name()
Returns the name of this node.
|
Preferences |
node(String name)
Returns the preference node with the given path name.
|
boolean |
nodeExists(String name)
Returns whether the preference node with the given path name exists.
|
Preferences |
parent()
Returns the parent preference node of this node or
null if this
node is the root node. |
void |
put(String key,
String value)
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.
|
void |
putBoolean(String key,
boolean value)
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. |
void |
putByteArray(String key,
byte[] value)
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.
|
void |
putDouble(String key,
double value)
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. |
void |
putFloat(String key,
float value)
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. |
void |
putInt(String key,
int value)
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. |
void |
putLong(String key,
long value)
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. |
protected abstract void |
putSpi(String name,
String value)
Puts the given key-value pair into this node.
|
void |
remove(String key)
Removes the preference mapped to the given key from this node.
|
void |
removeNode()
Removes this preference node with all its descendants.
|
void |
removeNodeChangeListener(NodeChangeListener ncl)
Removes the given
NodeChangeListener instance from this node. |
protected abstract void |
removeNodeSpi()
Removes this node from the preference hierarchy tree.
|
void |
removePreferenceChangeListener(PreferenceChangeListener pcl)
Removes the given
PreferenceChangeListener instance from this
node. |
protected abstract void |
removeSpi(String key)
Removes the preference with the specified key.
|
void |
sync()
Synchronizes the data of this preference node and its descendants with
the back-end preference store.
|
protected abstract void |
syncSpi()
Synchronizes this node with the backing store.
|
String |
toString()
Returns a string representation of this node.
|
importPreferences, setPreferencesFactory, systemNodeForPackage, systemRoot, userNodeForPackage, userRootprotected final Object lock
protected boolean newNode
protected AbstractPreferences(AbstractPreferences parent, String name)
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.protected final AbstractPreferences[] cachedChildren()
protected AbstractPreferences getChild(String name) throws BackingStoreException
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.protected boolean isRemoved()
removeNode().true, if this node has been removed, false
otherwise.protected abstract void flushSpi()
throws BackingStoreException
flush().BackingStoreException - if the backing store is unavailable or causes an operation
failure.protected abstract String[] childrenNamesSpi() throws BackingStoreException
BackingStoreException - if the backing store is unavailable or causes an operation
failure.protected abstract AbstractPreferences childSpi(String name)
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.protected abstract void putSpi(String name, String value)
name - the given preference key.value - the given preference value.protected abstract String getSpi(String key)
null return value.key - the given key to be searched for.protected abstract String[] keysSpi() throws BackingStoreException
BackingStoreException - if the backing store is unavailable or causes an operation
failure.protected abstract void removeNodeSpi()
throws BackingStoreException
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.protected abstract void removeSpi(String key)
key - the key of the preference that is to be removed.protected abstract void syncSpi()
throws BackingStoreException
sync().BackingStoreException - if the backing store is unavailable or causes an operation
failure.public String absolutePath()
PreferencesabsolutePath in class Preferencespublic String[] childrenNames() throws BackingStoreException
PreferenceschildrenNames in class PreferencesBackingStoreException - if backing store is unavailable or causes an operation
failure.public void clear()
throws BackingStoreException
Preferencesclear in class PreferencesBackingStoreException - if backing store is unavailable or causes an operation
failure.public void exportNode(OutputStream ostream) throws IOException, BackingStoreException
PreferencesThis 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.
exportNode in class Preferencesostream - the output stream to write the XML-formatted data to.IOException - if an error occurs while exporting.BackingStoreException - if the backing store is unavailable or causes an operation
failure.public void exportSubtree(OutputStream ostream) throws IOException, BackingStoreException
PreferencesThis 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.
exportSubtree in class Preferencesostream - the output stream to write the XML-formatted data to.IOException - if an error occurs while exporting.BackingStoreException - if the backing store is unavailable or causes an operation
failure.public void flush()
throws BackingStoreException
PreferencesIf this node has been removed, the invocation of this method only flushes this node, not its descendants.
flush in class PreferencesBackingStoreException - if the backing store is unavailable or causes an operation
failure.public String get(String key, String deflt)
PreferencesString 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.
get in class Preferenceskey - 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.public boolean getBoolean(String key, boolean deflt)
Preferencesboolean 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.
getBoolean in class Preferenceskey - 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.public byte[] getByteArray(String key, byte[] deflt)
Preferencesbyte 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.
getByteArray in class Preferenceskey - 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.public double getDouble(String key, double deflt)
Preferencesdouble 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.
getDouble in class Preferenceskey - 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.public float getFloat(String key, float deflt)
Preferencesfloat 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.
getFloat in class Preferenceskey - 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.public int getInt(String key, int deflt)
Preferencesint 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.
getInt in class Preferenceskey - 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.public long getLong(String key, long deflt)
Preferenceslong 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.
getLong in class Preferenceskey - 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.public boolean isUserNode()
PreferencesisUserNode in class Preferencestrue, if this is a user preference node, false if
this is a system preference node.public String[] keys() throws BackingStoreException
Preferenceskeys in class PreferencesBackingStoreException - if the backing store is unavailable or causes an operation
failure.public String name()
Preferencesname in class Preferencespublic Preferences node(String name)
PreferencesThe 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.
node in class Preferencesname - the path name of the requested preference node.public boolean nodeExists(String name) throws BackingStoreException
Preferences
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.
nodeExists in class Preferencesname - the path name of the preference node to query.true, if the queried preference node exists, false
otherwise.BackingStoreException - if the backing store is unavailable or causes an operation
failure.public Preferences parent()
Preferencesnull if this
node is the root node.parent in class Preferencespublic void put(String key, String value)
Preferencesput in class Preferenceskey - the preference key to be added or updated.value - the preference value for the given key.public void putBoolean(String key, boolean value)
Preferencesboolean value to this node using the
given key and value or updates the value if a preference with the given
key already exists.putBoolean in class Preferenceskey - the preference key to be added or updated.value - the preference boolean value for the given key.public void putByteArray(String key, byte[] value)
PreferencesThe 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.
putByteArray in class Preferenceskey - the preference key to be added or updated.value - the preference value for the given key.public void putDouble(String key, double value)
Preferencesdouble
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).
putDouble in class Preferenceskey - the preference key to be added or updated.value - the preference value for the given key.public void putFloat(String key, float value)
Preferencesfloat
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).
putFloat in class Preferenceskey - the preference key to be added or updated.value - the preference value for the given key.public void putInt(String key, int value)
Preferencesint
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).
putInt in class Preferenceskey - the preference key to be added or updated.value - the preference value for the given key.public void putLong(String key, long value)
Preferenceslong
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).
putLong in class Preferenceskey - the preference key to be added or updated.value - the preference value for the given key.public void remove(String key)
Preferencesremove in class Preferenceskey - the key of the preference to be removed.public void removeNode()
throws BackingStoreException
Preferencesflush() is invoked.removeNode in class PreferencesBackingStoreException - if the backing store is unavailable or causes an operation
failure.public void addNodeChangeListener(NodeChangeListener ncl)
PreferencesNodeChangeListener instance for this node, which will
handle NodeChangeEvents. NodeChangeEvents will be fired
when a child node has been added to or removed from this node.addNodeChangeListener in class Preferencesncl - the listener to be registered.public void addPreferenceChangeListener(PreferenceChangeListener pcl)
PreferencesPreferenceChangeListener instance for this node,
which will handle PreferenceChangeEvents. PreferenceChangeEvents will be fired when a preference has been added
to, removed from, or updated for this node.addPreferenceChangeListener in class Preferencespcl - the listener to be registered.public void removeNodeChangeListener(NodeChangeListener ncl)
PreferencesNodeChangeListener instance from this node.removeNodeChangeListener in class Preferencesncl - the listener to be removed.public void removePreferenceChangeListener(PreferenceChangeListener pcl)
PreferencesPreferenceChangeListener instance from this
node.removePreferenceChangeListener in class Preferencespcl - the listener to be removed.public void sync()
throws BackingStoreException
Preferencessync in class PreferencesBackingStoreException - if the backing store is unavailable or causes an operation
failure.public String toString()
PreferencestoString in class Preferences