Package ucar.util.prefs
Class PreferencesExt
java.lang.Object
java.util.prefs.Preferences
java.util.prefs.AbstractPreferences
ucar.util.prefs.PreferencesExt
- All Implemented Interfaces:
PersistenceManager
An extension of java.util.prefs.Preferences (jdk 1.4) that provides a
platform-independent implementation using XML files as backing store.
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().
- See Also:
-
Field Summary
Fields inherited from class java.util.prefs.AbstractPreferences
lock, newNodeFields inherited from class java.util.prefs.Preferences
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String[]Implements AbstractPreferences childrenNamesSpi() method.protected CollectionchildrenNamesSpi(String nodePath) protected AbstractPreferencesprotected voidflushSpi()Empty, never used implementation of AbstractPreferences.flushSpi().Get the object that has the specified key.Get an arrayList.protected Stringbooleanreturn true unless this is the systemRoot nodeprotected String[]keysSpi()protected CollectionvoidStores an object using simple bean properties.voidputBeanCollection(String key, Collection newValue) Stores a Collection of beans.voidputBeanObject(String key, Object newValue) Stores an object using XMLEncoder/XMLDecoder.voidStores the value with this key, if the exact key and value are not already in the storedDefaults (using equals() to test for equality).voidprotected voidprotected voidprotected voidremoves key/value if exists, no effect on storedDefaults Remove the association (if any) for the specified key at this preference node.static voidsetSystemRoot(PreferencesExt prefs) Set the system root you get when you call Preferences.systemRoot().static voidsetUserRoot(PreferencesExt prefs) Set the user root you get when you call Preferences.userRoot().protected voidsyncSpi()Methods inherited from class java.util.prefs.AbstractPreferences
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, toStringMethods inherited from class java.util.prefs.Preferences
importPreferences, systemNodeForPackage, systemRoot, userNodeForPackage, userRootMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ucar.util.prefs.PersistenceManager
addPreferenceChangeListener, get, getBoolean, getDouble, getInt, getLong, put, putBoolean, putDouble, putInt, putLong
-
Constructor Details
-
PreferencesExt
Constructor. Usually you get a PreferencesExt object from XMLStore.getPrefs(), rather than constructing one directly. For the root node, parent = null and name = "".
-
-
Method Details
-
setUserRoot
Set the user root you get when you call Preferences.userRoot(). -
setSystemRoot
Set the system root you get when you call Preferences.systemRoot(). -
isUserNode
public boolean isUserNode()return true unless this is the systemRoot node- Overrides:
isUserNodein classAbstractPreferences
-
getBean
Get the object that has the specified key. This returns the object itself, not a copy, so if you change the bean and call store.save(), any changes to the object will be saved, even without calling putBean(). If you want to change the object without saving the changes, you must make a copy of the object yourself.- Parameters:
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.- Returns:
- the value associated with key, or def if no value is associated with key.
- Throws:
IllegalStateException- if this node (or an ancestor) has been removed with theAbstractPreferences.removeNode()method.NullPointerException- if key is null. (A null default is permitted.)
-
putBean
Stores an object using simple bean properties. If the exact key and value are already in the storedDefaults (using equals() to test for equality), then it is not stored.- Parameters:
key- key with which the specified value is to be associated.newValue- store this bean.- Throws:
NullPointerException- if key or value is null.IllegalStateException- if this node (or an ancestor) has been removed with theAbstractPreferences.removeNode()method.
-
putBeanCollection
Stores a Collection of beans. The beans are stored using simple bean properties. The collection of beans must all be of the same class.- Parameters:
key- key with which the specified collection is to be associated.newValue- store this collection of beans.- Throws:
NullPointerException- if key or value is null.IllegalStateException- if this node (or an ancestor) has been removed with theAbstractPreferences.removeNode()method.
-
putBeanObject
Stores an object using XMLEncoder/XMLDecoder. Use this for arbitrary objects. If the exact key and value are already in the storedDefaults (using equals() to test for equality), then it is not stored.- Parameters:
key- key with which the specified value is to be associated.newValue- store this bean object.- Throws:
NullPointerException- if key or value is null.IllegalStateException- if this node (or an ancestor) has been removed with theAbstractPreferences.removeNode()method.
-
getList
Get an arrayList. This returns a copy of the stored list.- Specified by:
getListin interfacePersistenceManager- Parameters:
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.- Returns:
- the value associated with key, or def if no value is associated with key.
-
putList
Stores the value with this key, if the exact key and value are not already in the storedDefaults (using equals() to test for equality). "Two lists are defined to be equal if they contain the same elements in the same order."- Specified by:
putListin interfacePersistenceManager- Parameters:
key- key with which the specified value is to be associated.newValue- value to be associated with the specified key.
-
childrenNamesSpi
Implements AbstractPreferences childrenNamesSpi() method. Find all children nodes of this node (or of identically named nodes in storedDefaults)- Specified by:
childrenNamesSpiin classAbstractPreferences
-
childrenNamesSpi
-
keysSpi
- Specified by:
keysSpiin classAbstractPreferences- Throws:
BackingStoreException
-
keysSpi
-
childSpi
- Specified by:
childSpiin classAbstractPreferences
-
flushSpi
Empty, never used implementation of AbstractPreferences.flushSpi().- Specified by:
flushSpiin classAbstractPreferences- Throws:
BackingStoreException
-
getSpi
- Specified by:
getSpiin classAbstractPreferences
-
putSpi
- Specified by:
putSpiin classAbstractPreferences
-
removeNodeSpi
- Specified by:
removeNodeSpiin classAbstractPreferences- Throws:
BackingStoreException
-
removeSpi
removes key/value if exists, no effect on storedDefaults Remove the association (if any) for the specified key at this preference node. It is guaranteed that key is non-null. Also, it is guaranteed that this node has not been removed. (The implementor needn't check for either of these things.) This method is invoked with the lock on this node held.- Specified by:
removeSpiin classAbstractPreferences
-
syncSpi
- Specified by:
syncSpiin classAbstractPreferences- Throws:
BackingStoreException
-
putObject
- Specified by:
putObjectin interfacePersistenceManager
-
getObject
- Specified by:
getObjectin interfacePersistenceManager
-