This interface allows applications to store and retrieve user and system preference data. This data is stored persistently in an implementation-dependent backing store. Typical implementations include flat files, OS-specific registries, directory servers and SQL databases.
For each bundle, there is a separate tree of nodes for each user, and one for system preferences. The precise description of "user" and "system" will vary from one bundle to another. Typical information stored in the user preference tree might include font choice, and color choice for a bundle which interacts with the user via a servlet. Typical information stored in the system preference tree might include installation data, or things like high score information for a game program.
Nodes in a preference tree are named in a similar fashion to directories in a hierarchical file system. Every node in a preference tree has a node name (which is not necessarily unique), a unique absolute path name , and a path name relative to each ancestor including itself.
The root node has a node name of the empty String object (""). Every
other node has an arbitrary node name, specified at the time it is created.
The only restrictions on this name are that it cannot be the empty string,
and it cannot contain the slash character ('/').
The root node has an absolute path name of "/". Children of the root
node have absolute path names of "/" + <node name> .
All other nodes have absolute path names of <parent's absolute path
name> + "/" + <node name> . Note that all
absolute path names begin with the slash character.
A node n 's path name relative to its ancestor a is simply the string that must be appended to a 's absolute path name in order to form n 's absolute path name, with the initial slash character (if present) removed. Note that:
Note finally that:
Each Preference node has zero or more properties associated with it,
where a property consists of a name and a value. The bundle writer is free to
choose any appropriate names for properties. Their values can be of type
String,long,int,boolean, byte[],
float, or double but they can always be accessed as if they
were String objects.
All node name and property name comparisons are case-sensitive.
All of the methods that modify preference data are permitted to operate
asynchronously; they may return immediately, and changes will eventually
propagate to the persistent backing store, with an implementation-dependent
delay. The flush method may be used to synchronously force updates to
the backing store.
Implementations must automatically attempt to flush to the backing store any pending updates for a bundle's preferences when the bundle is stopped or otherwise ungets the Preferences Service.
The methods in this class may be invoked concurrently by multiple threads in a single Java Virtual Machine (JVM) without the need for external synchronization, and the results will be equivalent to some serial execution. If this class is used concurrently by multiple JVMs that store their preference data in the same backing store, the data store will not be corrupted, but no other guarantees are made concerning the consistency of the preference data.
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public String[] | Returns: the names of the children of this node.Returns the names of the children of this node. |
| public void | |
| public void | |
| public String | Returns: the value associated withkey, or def if no value
is associated with key.key whose associated value is to be returned. key, String the value to be returned in the event that this node has no
value associated with def)key or the backing store is
inaccessible.Returns the value associated with the specified |
| public boolean | Returns: theboolean value represented by the String
object associated with key in this node, or null
if the associated value does not exist or cannot be interpreted
as a boolean.key whose associated value is to be returned as a
boolean.the value to be returned in the event that this node has no
value associated with def)key or the associated value cannot
be interpreted as a boolean or the backing store is
inaccessible.Returns the |
| public byte[] | Returns: thebyte[] value represented by the String object
associated with key in this node, or def if the
associated value does not exist or cannot be interpreted as a
byte[].key whose associated value is to be returned as a
byte[] object.the value to be returned in the event that this node has no
value associated with def)key or the associated value cannot
be interpreted as a byte[] type, or the backing store is
inaccessible.Returns the |
| public double | Returns: thedouble value represented by the String object
associated with key in this node, or def if the
associated value does not exist or cannot be interpreted as a
double type.key whose associated value is to be returned as a
double value.the value to be returned in the event that this node has no
value associated with def)key or the associated value cannot
be interpreted as a double type or the backing store is
inaccessible.Returns the |
| public float | Returns: thefloat value represented by the string associated with
key in this node, or def if the associated value
does not exist or cannot be interpreted as a float type.key whose associated value is to be returned as a
float value.the value to be returned in the event that this node has no
value associated with def)key or the associated value cannot
be interpreted as a float type or the backing store is
inaccessible.Returns the float |
| public int | Returns: theint value represented by the String object
associated with key in this node, or def if the
associated value does not exist or cannot be interpreted as an
int type.key whose associated value is to be returned as an key, int int
.the value to be returned in the event that this node has no
value associated with def)key or the associated value cannot
be interpreted as an int or the backing store is
inaccessible.Returns the |
| public long | Returns: thelong value represented by the String object
associated with key in this node, or def if the
associated value does not exist or cannot be interpreted as a
long type.key whose associated value is to be returned as a
long value.the value to be returned in the event that this node has no
value associated with def)key or the associated value cannot
be interpreted as a long type or the backing store is
inaccessible.Returns the |
| public String[] | Returns: an array of the keys that have an associated value in this node.Returns all of the keys that have an associated value in this node. |
| public String | Returns: this node's name, relative to its parent.Returns this node's name, relative to its parent. |
| public Preferences | |
| public boolean | Returns: true if the specified node exists.the path name of the node whose existence is to be
checked. pathName)Returns true if the named node exists. |
| public Preferences | Returns: the parent of this node.Returns the parent of this node, or |
| public void | |
| public void | putBoolean(String
key with which the string form of value is to be
associated.value whose string form is to be associated with value)key
.Associates a |
| public void | putByteArray(String
key with which the string form of value is to
be associated.value whose string form is to be associated with
key.Associates a |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | removeNode()
Removes this node and all of its descendants, invalidating any properties contained in the removed nodes. |
| public void | sync()
Ensures that future reads from this node and its descendants reflect any
changes that were committed to the persistent store (from any VM) prior
to the |
| absolutePath | back to summary |
|---|---|
| public String absolutePath() Returns this node's absolute path name. Note that:
| |
| childrenNames | back to summary |
|---|---|
| public String[] childrenNames() throws BackingStoreException Returns the names of the children of this node. (The returned array will
be of size zero if this node has no children and not
| |
| clear | back to summary |
|---|---|
| public void clear() throws BackingStoreException Removes all of the properties (key-value associations) in this node. This call has no effect on any descendants of this node.
| |
| flush | back to summary |
|---|---|
| public void flush() throws BackingStoreException Forces any changes in the contents of this node and its descendants to the persistent store. Once this method returns successfully, it is safe to assume that all changes made in the subtree rooted at this node prior to the method invocation have become permanent. Implementations are free to flush changes into the persistent store at any time. They do not need to wait for this method to be called. When a flush occurs on a newly created node, it is made persistent, as are any ancestors (and descendants) that have yet to be made persistent. Note however that any properties value changes in ancestors are not guaranteed to be made persistent.
| |
| get | back to summary |
|---|---|
| public String get(String key, String def) Returns the value associated with the specified
| |
| getBoolean | back to summary |
|---|---|
| public boolean getBoolean(String key, boolean def) Returns the
Returns the specified default if there is no value associated with the
| |
| getByteArray | back to summary |
|---|---|
| public byte[] getByteArray(String key, byte[] def) Returns the
Returns the specified default if there is no value associated with the
| |
| getDouble | back to summary |
|---|---|
| public double getDouble(String key, double def) Returns the
| |
| getFloat | back to summary |
|---|---|
| public float getFloat(String key, float def) Returns the float
| |
| getInt | back to summary |
|---|---|
| public int getInt(String key, int def) Returns the
| |
| getLong | back to summary |
|---|---|
| public long getLong(String key, long def) Returns the
| |
| keys | back to summary |
|---|---|
| public String[] keys() throws BackingStoreException Returns all of the keys that have an associated value in this node. (The
returned array will be of size zero if this node has no preferences and
not
| |
| name | back to summary |
|---|---|
| public String name() Returns this node's name, relative to its parent.
| |
| node | back to summary |
|---|---|
| public Preferences node(String pathName) Returns a named
If the returned node did not exist prior to this call, this node and any
ancestors that were created by this call are not guaranteed to become
persistent until the
| |
| nodeExists | back to summary |
|---|---|
| public boolean nodeExists(String pathName) throws BackingStoreException Returns true if the named node exists. Accepts a relative or absolute
pathname. Absolute pathnames (which begin with
If this node (or an ancestor) has already been removed with the
| |
| parent | back to summary |
|---|---|
| public Preferences parent() Returns the parent of this node, or
| |
| put | back to summary |
|---|---|
| public void put(String key, String value) Associates the specified value with the specified key in this node.
| |
| putBoolean | back to summary |
|---|---|
| public void putBoolean(String key, boolean value) Associates a
Implementor's note: it is not necessary that the value be
represented by a string in the backing store. If the backing store
supports
| |
| putByteArray | back to summary |
|---|---|
| public void putByteArray(String key, byte[] value) Associates a
Implementor's note: it is not necessary that the value be
represented by a
| |
| putDouble | back to summary |
|---|---|
| public void putDouble(String key, double value) Associates a
Implementor's note: it is not necessary that the value be
represented by a string in the backing store. If the backing store
supports
| |
| putFloat | back to summary |
|---|---|
| public void putFloat(String key, float value) Associates a
Implementor's note: it is not necessary that the value be
represented by a string in the backing store. If the backing store
supports
| |
| putInt | back to summary |
|---|---|
| public void putInt(String key, int value) Associates a
Implementor's note: it is not necessary that the property value
be represented by a
| |
| putLong | back to summary |
|---|---|
| public void putLong(String key, long value) Associates a
Implementor's note: it is not necessary that the
| |
| remove | back to summary |
|---|---|
| public void remove(String key) Removes the value associated with the specified
| |
| removeNode | back to summary |
|---|---|
| public void removeNode() throws BackingStoreException Removes this node and all of its descendants, invalidating any properties
contained in the removed nodes. Once a node has been removed, attempting
any method other than
The removal is not guaranteed to be persistent until the
| |
| sync | back to summary |
|---|---|
| public void sync() throws BackingStoreException Ensures that future reads from this node and its descendants reflect any
changes that were committed to the persistent store (from any VM) prior
to the
| |