public class PreferencesExt extends AbstractPreferences implements PersistenceManager
To save Java beans, use putBean() and putBeanCollection(). This uses reflection to get/set properties that have simple single-valued accessor methods of primitive and String type.
For arbitrary objects, use putBeanObject(), which uses the XMLEncode/XMLDecode API (jdk 1.4). To obtain a PreferencesExt object, instantiate an XMLStore object and call XMLStore.getPreferences().
XMLStore
,
Preferences
lock, newNode
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH
Constructor and Description |
---|
PreferencesExt(PreferencesExt parent,
String name)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected String[] |
childrenNamesSpi()
Implements AbstractPreferences childrenNamesSpi() method.
|
protected Collection |
childrenNamesSpi(String nodePath) |
protected AbstractPreferences |
childSpi(String name) |
protected void |
flushSpi()
Empty, never used implementation of AbstractPreferences.flushSpi().
|
Object |
getBean(String key,
Object def)
Get the object that has the specified key.
|
List |
getList(String key,
List def)
Get an arrayList.
|
Object |
getObject(String key) |
protected String |
getSpi(String keyName) |
boolean |
isUserNode()
return true unless this is the systemRoot node
|
protected String[] |
keysSpi() |
protected Collection |
keysSpi(String nodePath) |
void |
putBean(String key,
Object newValue)
Stores an object using simple bean properties.
|
void |
putBeanCollection(String key,
Collection newValue)
Stores a Collection of beans.
|
void |
putBeanObject(String key,
Object newValue)
Stores an object using XMLEncoder/XMLDecoder.
|
void |
putList(String key,
List newValue)
Stores the value with this key, if the exact key and value are not already in
the storedDefaults (using equals() to test for equality).
|
void |
putObject(String keyName,
Object value) |
protected void |
putSpi(String key,
String newValue) |
protected void |
removeNodeSpi() |
protected void |
removeSpi(String key)
removes key/value if exists, no effect on storedDefaults
Remove the association (if any) for the specified key at this preference node.
|
static void |
setSystemRoot(PreferencesExt prefs)
Set the system root you get when you call Preferences.systemRoot().
|
static void |
setUserRoot(PreferencesExt prefs)
Set the user root you get when you call Preferences.userRoot().
|
protected void |
syncSpi() |
absolutePath, addNodeChangeListener, addPreferenceChangeListener, cachedChildren, childrenNames, clear, exportNode, exportSubtree, flush, get, getBoolean, getByteArray, getChild, getDouble, getFloat, getInt, getLong, isRemoved, keys, name, node, nodeExists, parent, put, putBoolean, putByteArray, putDouble, putFloat, putInt, putLong, remove, removeNode, removeNodeChangeListener, removePreferenceChangeListener, sync, toString
importPreferences, systemNodeForPackage, systemRoot, userNodeForPackage, userRoot
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addPreferenceChangeListener, get, getBoolean, getDouble, getInt, getLong, put, putBoolean, putDouble, putInt, putLong
public PreferencesExt(PreferencesExt parent, String name)
public static void setUserRoot(PreferencesExt prefs)
public static void setSystemRoot(PreferencesExt prefs)
public boolean isUserNode()
isUserNode
in class AbstractPreferences
public Object getBean(String key, Object def)
key
- get the object with this key.def
- the default value to be returned in the event that this
preference node has no value associated with key.IllegalStateException
- if this node (or an ancestor) has been
removed with the AbstractPreferences.removeNode()
method.NullPointerException
- if key is null. (A
null default is permitted.)public void putBean(String key, Object newValue)
key
- key with which the specified value is to be associated.newValue
- store this bean.NullPointerException
- if key or value is null.IllegalStateException
- if this node (or an ancestor) has been
removed with the AbstractPreferences.removeNode()
method.public void putBeanCollection(String key, Collection newValue)
key
- key with which the specified collection is to be associated.newValue
- store this collection of beans.NullPointerException
- if key or value is null.IllegalStateException
- if this node (or an ancestor) has been
removed with the AbstractPreferences.removeNode()
method.public void putBeanObject(String key, Object newValue)
key
- key with which the specified value is to be associated.newValue
- store this bean object.NullPointerException
- if key or value is null.IllegalStateException
- if this node (or an ancestor) has been
removed with the AbstractPreferences.removeNode()
method.public List getList(String key, List def)
getList
in interface PersistenceManager
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 void putList(String key, List newValue)
putList
in interface PersistenceManager
key
- key with which the specified value is to be associated.newValue
- value to be associated with the specified key.protected String[] childrenNamesSpi()
childrenNamesSpi
in class AbstractPreferences
protected Collection childrenNamesSpi(String nodePath)
protected String[] keysSpi() throws BackingStoreException
keysSpi
in class AbstractPreferences
BackingStoreException
protected Collection keysSpi(String nodePath)
protected AbstractPreferences childSpi(String name)
childSpi
in class AbstractPreferences
protected void flushSpi() throws BackingStoreException
flushSpi
in class AbstractPreferences
BackingStoreException
protected String getSpi(String keyName)
getSpi
in class AbstractPreferences
protected void putSpi(String key, String newValue)
putSpi
in class AbstractPreferences
protected void removeNodeSpi() throws BackingStoreException
removeNodeSpi
in class AbstractPreferences
BackingStoreException
protected void removeSpi(String key)
removeSpi
in class AbstractPreferences
protected void syncSpi() throws BackingStoreException
syncSpi
in class AbstractPreferences
BackingStoreException
public void putObject(String keyName, Object value)
putObject
in interface PersistenceManager
public Object getObject(String key)
getObject
in interface PersistenceManager
Copyright © 1999–2014 UCAR/Unidata. All rights reserved.