![]() ![]()
Use of JCP site is subject to the
JCP Terms of Use and the
Oracle Privacy Policy
![]() ![]() ![]() ![]() |
![]() |
javax.prefs
|
Constructor Summary | |
protected |
Preferences()
Creates a new uninitialized Preferences object. |
protected |
Preferences(Preferences parent,
java.lang.String name)
Creates a new preference node with the specified parent and the specified name relative to its parent. |
Method Summary | |
void |
addNodeChangeListener(NodeChangeListener ncl)
Adds the specified listener to receive NodeChange events for this node. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Adds the specified listener to receive property change events for this preference node. |
protected abstract Preferences |
child(java.lang.String name)
Returns the named child of this preference node, creating it if it does not already exist. |
abstract Preferences[] |
children()
Returns the children of this preference node. |
void |
clear()
Removes all of the preferences (key-value associations) in this preference node. |
abstract void |
flush()
Forces any changes in the contents of this preference node and its descendants to the persistent store. |
static Preferences |
forClass(java.lang.Object o)
Returns the preference node associated (by convention) with the specified object's class. |
static Preferences |
forPackage(java.lang.Object o)
Returns the preference node associated (by convention) with the specified object's package. |
java.lang.String |
fullName()
Returns this preference node's absolute path name. |
abstract java.lang.String |
get(java.lang.String key,
java.lang.String def)
Returns the value associated with the specified key in this preference node. |
boolean |
getBoolean(java.lang.String key,
boolean def)
Returns the boolean value represented by the string associated with the specified key in this preference node. |
int |
getInt(java.lang.String key,
int def)
Returns the int value represented by the string associated with the specified key in this preference node. |
protected void |
init(Preferences parent,
java.lang.String name)
Initializes this Preferences object, which must be uninitialized prior to this call. |
abstract java.lang.String[] |
keys()
Returns all of the keys that have an associated value in this preference node. |
java.lang.String |
name()
Returns this preference node's name, relative to its parent. |
Preferences |
node(java.lang.String pathName)
Returns the named preference node, creating it and any of its ancestors if they do not already exist. |
boolean |
nodeExists(java.lang.String pathName)
Returns true if the named preference node exists. |
Preferences |
parent()
Returns the parent of this preference node, or null if this is the root. |
abstract java.lang.String |
put(java.lang.String key,
java.lang.String value)
Associates the specified value with the specified key in this preference node. |
void |
putBoolean(java.lang.String key,
boolean value)
Associates a string representing the specified boolean value with the specified key in this preference node. |
void |
putInt(java.lang.String key,
int value)
Associates a string representing the specified int value with the specified key in this preference node. |
abstract void |
refresh()
Ensures that future reads from this preference node and its descendants reflect any changes that have been committed to the persistent store (from any VM). |
abstract java.lang.String |
remove(java.lang.String key)
Removes the value associated with the specified key in this preference node, if any. |
protected abstract boolean |
removeChild(java.lang.String name)
Removes the named child of this preference node and all of its descendants, invalidating any preferences contained in the removed nodes. |
boolean |
removeNode(java.lang.String pathName)
Removes the named preference node and all of its descendants, invalidating any preferences contained in the removed nodes. |
void |
removeNodeChangeListener(NodeChangeListener tcl)
Removes the specified NodeChangeListener, so it no longer receives change events. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
Removes the specified property change listener, so it no longer receives change events. |
static Preferences |
root()
Returns the root preference node for the calling user. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
protected Preferences(Preferences parent, java.lang.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.protected Preferences()
init(Preferences,String)
Method Detail |
protected void init(Preferences parent, java.lang.String name)
name
- the name of this preference node, relative to its parent,
or "" if this is the root.parent
- the parent of this preference node, or null if this
is the root.Preferences()
public static Preferences forClass(java.lang.Object o)
An object wishing to access preferences pertaining to its class can obtain a preference node as follows:
Preferences prefs = Preferences.forClass(this);(This idiom obviates the need for hard-coding the package and class names, reducing the likelihood of error.)
public static Preferences forPackage(java.lang.Object o)
An object wishing to access preferences pertaining to its package can obtain a preference node as follows:
Preferences prefs = Preferences.forPackage(this);(This idiom obviates the need for hard-coding the package name, reducing the likelihood of error.)
public static Preferences root()
public abstract java.lang.String put(java.lang.String key, java.lang.String value)
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.public abstract java.lang.String get(java.lang.String key, java.lang.String def)
Some implementations may store default values in their backing stores. If there is no value associated with the specified key but there is such a persistent default, it is returned in preference to the specified default.
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.public abstract java.lang.String remove(java.lang.String key)
If this implementation supports stored defaults, and there is such a default for the specified property, the stored default will be "exposed" by this call, in the sense that it will be returned by a succeeding call to get.
key
- key whose mapping is to be removed from the preference
node.get(String,String)
public void putInt(java.lang.String key, int value)
This convenience method is intended to be used in conjunction with getInt.
Implementor's note: it is not necessary that the preference value be represented by a string in the backing store. If the backing store supports integer values, it is not unreasonable to use them. This implementation detail is not visible through the Preferences API, which allows the value to be read as an int (with getInt) or a string (with get).
key
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.getInt(String,int)
,
get(String,String)
public int getInt(java.lang.String key, int def)
If the implementation supports stored defaults and such a default exists and is accessible, it is used in preference to the specified default.
This convenience method is intended to be used in conjunction with putInt.
key
- key whose associated value is to be converted 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
the associated value cannot be interpreted as an int.get(String,String)
,
putInt(String,int)
public void putBoolean(java.lang.String key, boolean value)
This convenience method is intended to be used in conjunction with getBoolean.
Implementor's note: it is not necessary that the preference value be represented by a string in the backing store. If the backing store supports boolean values, it is not unreasonable to use them. This implementation detail is not visible through the Preferences API, which allows the value to be read as an boolean (with getBoolean) or a string (with get).
key
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.getBoolean(String,boolean)
,
get(String,String)
public boolean getBoolean(java.lang.String key, boolean def)
If the implementation supports stored defaults and such a default exists and is accessible, it is used in preference to the specified default. This convenience method is intended to be used in conjunction with putBoolean.
key
- key whose associated value is to be converted 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
the associated value cannot be interpreted as a boolean.get(String,String)
,
putBoolean(String,boolean)
public abstract java.lang.String[] keys()
public void clear()
If this implementation supports stored defaults, and this node in the preferences hierarchy contains any such defaults, the stored defaults will be "exposed" by this call, in the sense that they will be returned by succeeding calls to get.
public abstract Preferences[] children()
public Preferences parent()
public Preferences node(java.lang.String pathName)
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 flush method is called on the returned node (or one of its descendants).
pathName
- the path name of the preference node to return.flush()
public boolean nodeExists(java.lang.String pathName)
pathName
- the path name of the node whose existence
is to be checked.public boolean removeNode(java.lang.String pathName)
Once a node has been removed, attempting any operation on the corresponding Preferences object may fail with an IllegalStateOperation.
If this implementation supports stored defaults, this call may not appear to remove the specified node, in the sense that the node object will still be usable. If this node or any of its descendants have any stored defaults, they will be "exposed" by this call, in the sense that they will be returned by succeeding calls to get.
The removal of the specified node is not guaranteed to be persistent until the flush method is called on an ancestor of the specified node. (It is illegal to remove the root node.)
pathName
- the path name of the preference node to remove.flush()
protected abstract Preferences child(java.lang.String name)
If this call causes a node to be created, this node is not guaranteed to be persistent until the flush method is called on this node or one of its ancestors (or descendants).
name
- The name of the child node to return, relative to
this preference node.protected abstract boolean removeChild(java.lang.String name)
If this implementation supports stored defaults, this call may not appear to remove the specified node, in the sense that the node object will still be usable. If this node or any of its descendants have any stored defaults, they will be "exposed" by this call, in the sense that they will be returned by succeeding calls to get.
The removal of the specified node is not guaranteed to be persistent until the flush method is called on an ancestor of the specified node.
name
- The name of the child node to remove, relative to
this preference node.public java.lang.String name()
public java.lang.String fullName()
public abstract void flush() throws java.io.IOException
Once this method returns successfully, it is safe to assume that all changes made prior to the call have become permanent.
Implementors note: the foregoing implies that once a call to this method fails, all succeeding calls must fail until any pending changes have been made permanent.
public abstract void refresh() throws java.io.IOException
Some implementations may, as a side-effect, cause this VM's pending updates (if any) to be flushed to the persistent store, but this behavior is not required. (A pending update is an update that has not yet propagated to the persistent store.) Some implementations, however, may cause this VM's pending updates (if any) to be lost. If the caller wishes to ensure that this does not happen, flush should be called prior to refresh.
Implementation note: implementors should generally strive to avoid the loss of any pending updates when this method is called.
flush()
public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
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 permanent. Events are not generated when preferences are modified in descendants of this node; a caller desiring such events must register with each descendant.
public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
public void addNodeChangeListener(NodeChangeListener ncl)
public void removeNodeChangeListener(NodeChangeListener tcl)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |