public class DbPreferences extends Preferences implements PersistedPreferences
Preferences API.DbPreferencesNode: the nodes representing the preferences hierarchy.DbPreferencesKey: the key/value pairs corresponding to the nodes.ModificationTracker by use of the tableSerial.
Notice that events in the local JVM are enqueued at the time of change (i.e. put(),
remove(), node() or removeNode()) while other JVMs will become aware of the changes
only after the changes are flush()ed to persistent storage.
The underlying mechanism works as follows:
AbstractPreferences (which we can not simply extend
due to various design issues), the DbPreferences differ slightly in the following aspects:
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH| Constructor and Description |
|---|
DbPreferences(boolean userMode)
Special constructor for roots (both user and system).
|
DbPreferences(DbPreferences parent,
DbPreferencesNode node)
Constructs DbPreferences from a DbPreferencesNode.
|
DbPreferences(DbPreferences parent,
String name)
Creates a preference node with the specified parent and the specified
name relative to its parent.
|
| Modifier and Type | Method and Description |
|---|---|
String |
absolutePath() |
void |
addNodeChangeListener(NodeChangeListener ncl)
Registers the specified listener to receive node change events
for this node.
|
void |
addPreferenceChangeListener(PreferenceChangeListener pcl)
Registers the specified listener to receive preference change
events for this preference node.
|
boolean |
areNodeListenersRegistered() |
boolean |
arePreferenceListenersRegistered()
Returns whether reference listeners are registered.
|
String[] |
childrenNames() |
void |
clear() |
void |
exportNode(OutputStream os) |
void |
exportSubtree(OutputStream os) |
void |
flush() |
String |
get(String key,
String def) |
String |
getAbsolutePath()
Gets the absolute path.
|
boolean |
getBoolean(String key,
boolean def) |
byte[] |
getByteArray(String key,
byte[] def) |
Set<Long> |
getChildIds()
Gets the child IDs.
|
Map<String,DbPreferences> |
getChildPrefs()
Gets the child preferences.
|
double |
getDouble(String key,
double def) |
float |
getFloat(String key,
float def) |
int |
getInt(String key,
int def) |
Map<String,DbPreferencesKey> |
getKeys()
Gets the persistence key/value pairs.
|
long |
getLong(String key,
long def) |
String |
getName()
Gets the name.
|
DbPreferencesNode |
getNode()
Gets the persistence node.
|
DbPreferences |
getParent()
Gets the persistence parent.
|
DbPreferences |
getRoot()
Gets the root node.
|
boolean |
isUserMode()
Returns whether user-scope or system.
|
boolean |
isUserNode() |
String[] |
keys() |
String |
name() |
DbPreferences |
node(String path) |
boolean |
nodeExists(String pathName) |
DbPreferences |
parent() |
void |
put(String key,
String value) |
void |
putBoolean(String key,
boolean value) |
void |
putByteArray(String key,
byte[] value) |
void |
putDouble(String key,
double value) |
void |
putFloat(String key,
float value) |
void |
putInt(String key,
int value) |
void |
putLong(String key,
long value) |
void |
remove(String key) |
void |
removeNode() |
void |
removeNodeChangeListener(NodeChangeListener ncl) |
void |
removePreferenceChangeListener(PreferenceChangeListener pcl) |
void |
sync() |
String |
toString()
Returns the string represenation of this node.
|
protected void |
updateParentNode(DbPreferencesNode node)
Updates the serial and tableserial of a parent node.
|
importPreferences, systemNodeForPackage, systemRoot, userNodeForPackage, userRootclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsystemNodeForPackage, systemRoot, userNodeForPackage, userRootpublic DbPreferences(DbPreferences parent, String name)
parent - the parent of this preference nodename - the name of this preference node, relative to its parentIllegalArgumentException - if name contains a slash
('/'), or parent is null and
name isn't "".public DbPreferences(boolean userMode)
userMode - true if user mode, else system modepublic DbPreferences(DbPreferences parent, DbPreferencesNode node) throws BackingStoreException
parent - the parent preferencesnode - the nodeBackingStoreException - if creation failedpublic DbPreferencesNode getNode()
public DbPreferences getParent()
public String getName()
public String getAbsolutePath()
public boolean isUserMode()
public DbPreferences getRoot()
public Map<String,DbPreferences> getChildPrefs()
public Map<String,DbPreferencesKey> getKeys()
protected void updateParentNode(DbPreferencesNode node) throws BackingStoreException
node - the parent node to updateBackingStoreException - if update failedpublic boolean areNodeListenersRegistered()
public boolean arePreferenceListenersRegistered()
public String toString()
toString in class Preferencespublic String name()
name in interface PersistedPreferencesname in class Preferencespublic String absolutePath()
absolutePath in interface PersistedPreferencesabsolutePath in class Preferencespublic boolean isUserNode()
isUserNode in interface PersistedPreferencesisUserNode in class Preferencespublic void put(String key, String value)
put in interface PersistedPreferencesput in class Preferencespublic String get(String key, String def)
get in interface PersistedPreferencesget in class Preferencespublic void remove(String key)
remove in interface PersistedPreferencesremove in class Preferencespublic void clear()
throws BackingStoreException
clear in interface PersistedPreferencesclear in class PreferencesBackingStoreExceptionpublic void sync()
throws BackingStoreException
sync in interface PersistedPreferencessync in class PreferencesBackingStoreExceptionpublic void flush()
throws BackingStoreException
flush in interface PersistedPreferencesflush in class PreferencesBackingStoreExceptionpublic void putInt(String key, int value)
putInt in interface PersistedPreferencesputInt in class Preferencespublic int getInt(String key, int def)
getInt in interface PersistedPreferencesgetInt in class Preferencespublic void putLong(String key, long value)
putLong in interface PersistedPreferencesputLong in class Preferencespublic long getLong(String key, long def)
getLong in interface PersistedPreferencesgetLong in class Preferencespublic void putBoolean(String key, boolean value)
putBoolean in interface PersistedPreferencesputBoolean in class Preferencespublic boolean getBoolean(String key, boolean def)
getBoolean in interface PersistedPreferencesgetBoolean in class Preferencespublic void putFloat(String key, float value)
putFloat in interface PersistedPreferencesputFloat in class Preferencespublic float getFloat(String key, float def)
getFloat in interface PersistedPreferencesgetFloat in class Preferencespublic void putDouble(String key, double value)
putDouble in interface PersistedPreferencesputDouble in class Preferencespublic double getDouble(String key, double def)
getDouble in interface PersistedPreferencesgetDouble in class Preferencespublic void putByteArray(String key, byte[] value)
putByteArray in interface PersistedPreferencesputByteArray in class Preferencespublic byte[] getByteArray(String key, byte[] def)
getByteArray in interface PersistedPreferencesgetByteArray in class Preferencespublic String[] keys() throws BackingStoreException
keys in interface PersistedPreferenceskeys in class PreferencesBackingStoreExceptionpublic String[] childrenNames() throws BackingStoreException
childrenNames in interface PersistedPreferenceschildrenNames in class PreferencesBackingStoreExceptionpublic DbPreferences parent()
parent in interface PersistedPreferencesparent in class Preferencespublic DbPreferences node(String path)
node in interface PersistedPreferencesnode in class Preferencespublic boolean nodeExists(String pathName) throws BackingStoreException
This implementation differs from AbstractPreferences because it checks the persistent storage rather than the cache, i.e. a node only created in memory but not yet written to persistent storage is considered non-existant. As a consequence it is possible to decide whether a system-preference has been overridden by a user-preference. (see CompositePreferences). Notice that "" will return true even if not written to disk to denote "not deleted" (which does not mean "saved" -- a little confusing)
nodeExists in interface PersistedPreferencesnodeExists in class PreferencesBackingStoreExceptionpublic void removeNode()
throws BackingStoreException
removeNode in interface PersistedPreferencesremoveNode in class PreferencesBackingStoreExceptionpublic void addPreferenceChangeListener(PreferenceChangeListener pcl)
removeNode() method, which generates a node change event.
Preference change events are generated by the clear
method.)
Events are generated even for changes made outside this JVM. For the local JVM events are generated before the changes have been made persistent. For all other JVMs events are generated *after* flush()/sync().
addPreferenceChangeListener in interface PersistedPreferencesaddPreferenceChangeListener in class Preferencespcl - The preference change listener to add.NullPointerException - if pcl is null.IllegalStateException - if this node (or an ancestor) has been
removed with the removeNode() method.removePreferenceChangeListener(PreferenceChangeListener),
addNodeChangeListener(NodeChangeListener)public void removePreferenceChangeListener(PreferenceChangeListener pcl)
removePreferenceChangeListener in interface PersistedPreferencesremovePreferenceChangeListener in class Preferencespublic void addNodeChangeListener(NodeChangeListener ncl)
removeNode()
invocation results in multiple node change events, one for every
node in the subtree rooted at the removed node.)
Events are generated even for changes made outside this JVM. For the local JVM events are generated before the changes have been made persistent. For all other JVMs events are generated *after* flush()/sync().
Node creation will always generate an even for the local JVM. Other JVMs get that event only in case the node is created on disk (and not updated in case another JVM already created that node).
addNodeChangeListener in interface PersistedPreferencesaddNodeChangeListener in class Preferencesncl - The NodeChangeListener to add.NullPointerException - if ncl is null.IllegalStateException - if this node (or an ancestor) has been
removed with the removeNode() method.removeNodeChangeListener(NodeChangeListener),
addPreferenceChangeListener(PreferenceChangeListener)public void removeNodeChangeListener(NodeChangeListener ncl)
removeNodeChangeListener in interface PersistedPreferencesremoveNodeChangeListener in class Preferencespublic void exportNode(OutputStream os) throws IOException, BackingStoreException
exportNode in interface PersistedPreferencesexportNode in class PreferencesIOExceptionBackingStoreExceptionpublic void exportSubtree(OutputStream os) throws IOException, BackingStoreException
exportSubtree in interface PersistedPreferencesexportSubtree in class PreferencesIOExceptionBackingStoreExceptionCopyright © 2016 Krake Softwaretechnik. All rights reserved.