|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.util.prefs.Preferences
![]()
![]()
![]()
java.util.prefs.AbstractPreferences
public abstract class AbstractPreferences

This class provides a skeletal implementation of the Preferences
class, greatly easing the task of implementing it.
This class is for Preferences implementers only.
Normal users of the Preferences facility should have no need to
consult this documentation. The Preferences
documentation
should suffice.
Implementors must override the nine abstract service-provider interface
(SPI) methods: getSpi(String)
, putSpi(String,String)
,
removeSpi(String)
, childSpi(String)
, removeNodeSpi()
, keysSpi()
, childrenNamesSpi()
, syncSpi()
and flushSpi()
. All of the concrete methods specify
precisely how they are implemented atop these SPI methods. The implementor
may, at his discretion, override one or more of the concrete methods if the
default implementation is unsatisfactory for any reason, such as
performance.
The SPI methods fall into three groups concerning exception
behavior. The getSpi method should never throw exceptions, but it
doesn't really matter, as any exception thrown by this method will be
intercepted by get(String,String)
, which will return the specified
default value to the caller. The removeNodeSpi, keysSpi,
childrenNamesSpi, syncSpi and flushSpi methods are specified
to throw BackingStoreException
, and the implementation is required
to throw this checked exception if it is unable to perform the operation.
The exception propagates outward, causing the corresponding API method
to fail.
The remaining SPI methods putSpi(String,String)
, removeSpi(String)
and childSpi(String)
have more complicated
exception behavior. They are not specified to throw
BackingStoreException, as they can generally obey their contracts
even if the backing store is unavailable. This is true because they return
no information and their effects are not required to become permanent until
a subsequent call to {Preferences#flush()} or
{Preferences#sync()}. Generally speaking, these SPI methods should not
throw exceptions. In some implementations, there may be circumstances
under which these calls cannot even enqueue the requested operation for
later processing. Even under these circumstances it is generally better to
simply ignore the invocation and return, rather than throwing an
exception. Under these circumstances, however, all subsequent invocations
of flush() and sync should return false, as
returning true would imply that all previous operations had
successfully been made permanent.
There is one circumstance under which putSpi, removeSpi and
childSpi should throw an exception: if the caller lacks
sufficient privileges on the underlying operating system to perform the
requested operation. This will, for instance, occur on most systems
if a non-privileged user attempts to modify system preferences.
(The required privileges will vary from implementation to
implementation. On some implementations, they are the right to modify the
contents of some directory in the file system; on others they are the right
to modify contents of some key in a registry.) Under any of these
circumstances, it would generally be undesirable to let the program
continue executing as if these operations would become permanent at a later
time. While implementations are not required to throw an exception under
these circumstances, they are encouraged to do so. A SecurityException
would be appropriate.
Most of the SPI methods require the implementation to read or write information at a preferences node. The implementor should beware of the fact that another VM may have concurrently deleted this node from the backing store. It is the implementation's responsibility to recreate the node if it has been deleted.
Implementation note: In Sun's default Preferences
implementations, the user's identity is inherited from the underlying
operating system and does not change for the lifetime of the virtual
machine. It is recognized that server-side Preferences
implementations may have the user identity change from request to request,
implicitly passed to Preferences methods via the use of a
static ThreadLocal
instance. Authors of such implementations are
strongly encouraged to determine the user at the time preferences
are accessed (for example by the get(String,String)
or put(String,String)
method) rather than permanently associating a user
with each Preferences instance. The latter behavior conflicts
with normal Preferences usage and would lead to great confusion.
Preferences

| 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 |
| Constructor Summary | |
|---|---|
protected |
AbstractPreferences
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
Registers the specified listener to receive node change events for this node. |
void |
addPreferenceChangeListener
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
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
Implements the exportNode method as per the specification in Preferences.exportNode(OutputStream) . |
void |
exportSubtree
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
Implements the get method as per the specification in Preferences.get(String,String) . |
boolean |
getBoolean
Implements the getBoolean method as per the specification in Preferences.getBoolean(String,boolean) . |
byte[] |
getByteArray
Implements the getByteArray method as per the specification in Preferences.getByteArray(String,byte[]) . |
protected AbstractPreferences |
getChild
Returns the named child if it exists, or null if it does not. |
double |
getDouble
Implements the getDouble method as per the specification in Preferences.getDouble(String,double) . |
float |
getFloat
Implements the getFloat method as per the specification in Preferences.getFloat(String,float) . |
int |
getInt
Implements the getInt method as per the specification in Preferences.getInt(String,int) . |
long |
getLong
Implements the getLong method as per the specification in Preferences.getLong(String,long) . |
protected abstract String |
getSpi
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
Implements the node method as per the specification in Preferences.node(String) . |
boolean |
nodeExists
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
Implements the put method as per the specification in Preferences.put(String,String) . |
void |
putBoolean
Implements the putBoolean method as per the specification in Preferences.putBoolean(String,boolean) . |
void |
putByteArray
Implements the putByteArray method as per the specification in Preferences.putByteArray(String,byte[]) . |
void |
putDouble
Implements the putDouble method as per the specification in Preferences.putDouble(String,double) . |
void |
putFloat
Implements the putFloat method as per the specification in Preferences.putFloat(String,float) . |
void |
putInt
Implements the putInt method as per the specification in Preferences.putInt(String,int) . |
void |
putLong
Implements the putLong method as per the specification in Preferences.putLong(String,long) . |
protected abstract void |
putSpi
Put the given key-value association into this preference node. |
void |
remove
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
Removes the specified NodeChangeListener, so it no longer receives change events. |
protected abstract void |
removeNodeSpi |