Class PreferencesAdapter
- All Implemented Interfaces:
INotificationSupport
,IPreferences
,EventListener
,PreferenceChangeListener
Preferences
to IPreferences
.-
Field Summary
Fields inherited from interface de.intarsys.tools.preferences.IPreferences
SCOPE_DEFAULT, SCOPE_GLOBAL, SCOPE_INSTALLATION, SCOPE_TEAM, SCOPE_USER
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns this preference node's absolute path name.void
addNotificationListener
(EventType type, INotificationListener listener) Addlistener
to the collection of objects to be informed when the receiver triggers an event of typename
.children()
The array of all child preferences.String[]
Returns the names of the children of this preference node, relative to this node.void
clear()
Removes all of the preferences (key-value associations) in this preference node.protected PreferencesAdapter
createPreferencesNode
(String pathName) void
flush()
Forces any changes in the contents of this preference node and its descendants to the persistent store.Returns the current value of the string-valued preference with the given name.Returns the value associated with the specified key in this preference node.boolean
getBoolean
(String name) Returns the current value of the boolean-valued preference with the given name.boolean
getBoolean
(String key, boolean def) Returns the boolean value represented by the string associated with the specified key in this preference node.byte[]
getByteArray
(String key, byte[] def) Returns the byte array value represented by the string associated with the specified key in this preference node.double
Returns the current value of the double-valued preference with the given name.double
Returns the double value represented by the string associated with the specified key in this preference node.float
Returns the current value of the float-valued preference with the given name.float
Returns the float value represented by the string associated with the specified key in this preference node.int
Returns the current value of the integer-valued preference with the given name.int
Returns the int value represented by the string associated with the specified key in this preference node.long
Returns the current value of the long-valued preference with the given name.long
Returns the long value represented by the string associated with the specified key in this preference node.String[]
keys()
Returns all of the keys that have an associated value in this preference node.name()
Returns this preference node's name, relative to its parent.Returns the named preference node in the same tree as this node, creating it and any of its ancestors if they do not already exist.protected IPreferences
node
(StringTokenizer path) boolean
nodeExists
(String pathName) Returns true if the named preference node exists in the same tree as this node.parent()
Returns the parent of this preference node, or null if this is the root.void
A map of all property mappings in thisIPreferences
node.void
Sets the current value of the boolean-valued preference with the given name.void
Associates a string representing the specified byte array with the specified key in this preference node.void
Sets the current value of the double-valued preference with the given name.void
Sets the current value of the float-valued preference with the given name.void
Sets the current value of the integer-valued preference with the given name.void
Sets the current value of the long-valued preference with the given name.void
Sets the current value of the string-valued preference with the given name.void
putBoolean
(String key, boolean value) Set the current value.void
putByteArray
(String name, byte[] value) Set the current value.void
Set the current value.void
Set the current value.void
Set the current value.void
Set the current value.void
Removes the value associated with the specified key in this preference node, if any.void
Removes this preference node and all of its descendants, invalidating any preferences contained in the removed nodes.void
removeNotificationListener
(EventType type, INotificationListener listener) Removelistener
from the collection of objects to be informed about events of typename
.Create a new IPreferences object whose scopes include all scopes from the receiver before and including "scopeName".void
sync()
Ensures that future reads from this preference node and its descendants reflect any changes that were committed to the persistent store (from any VM) prior to the sync invocation.protected void
triggerChange
(PreferenceChangeEvent jEvent) protected void
triggerEvent
(Event event)
-
Constructor Details
-
PreferencesAdapter
-
-
Method Details
-
absolutePath
Description copied from interface:IPreferences
Returns this preference node's absolute path name.- Specified by:
absolutePath
in interfaceIPreferences
- Returns:
- this preference node's absolute path name.
-
addNotificationListener
Description copied from interface:INotificationSupport
Addlistener
to the collection of objects to be informed when the receiver triggers an event of typename
.- Specified by:
addNotificationListener
in interfaceINotificationSupport
- Parameters:
type
- The event type we are interested in.listener
- The object to be informed about an event occurrence
-
children
Description copied from interface:IPreferences
The array of all child preferences.- Specified by:
children
in interfaceIPreferences
- Returns:
- The array of all child preferences.
-
childrenNames
Description copied from interface:IPreferences
Returns the names of the children of this preference node, relative to this node. (The returned array will be of size zero if this node has no children.)- Specified by:
childrenNames
in interfaceIPreferences
- Returns:
- the names of the children of this preference node.
-
clear
Description copied from interface:IPreferences
Removes all of the preferences (key-value associations) in this preference node. This call has no effect on any descendants of this node.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.
- Specified by:
clear
in interfaceIPreferences
- Throws:
BackingStoreException
- if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.- See Also:
-
createPreferencesNode
-
flush
public void flush()Description copied from interface:IPreferences
Forces any changes in the contents of this preference node and its descendants to the persistent store. Once this method returns successfully, it is safe to assume that all changes made in the subtree rooted at this node prior to the method invocation have become permanent.Implementations are free to flush changes into the persistent store at any time. They do not need to wait for this method to be called.
When a flush occurs on a newly created node, it is made persistent, as are any ancestors (and descendants) that have yet to be made persistent. Note however that any preference value changes in ancestors are not guaranteed to be made persistent.
If this method is invoked on a node that has been removed with the
IPreferences.removeNode()
method, flushSpi() is invoked on this node, but not on others.- Specified by:
flush
in interfaceIPreferences
- See Also:
-
get
Description copied from interface:IPreferences
Returns the current value of the string-valued preference with the given name. Returns the default-default value (the empty string""
) if there is no preference with the given name, or if the current value cannot be treated as a string.- Specified by:
get
in interfaceIPreferences
- Parameters:
name
- the name of the preference- Returns:
- the string-valued preference
-
get
Description copied from interface:IPreferences
Returns the value associated with the specified key in this preference node. Returns the specified default if there is no value associated with the key, or the backing store is inaccessible.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 stored default, it is returned in preference to the specified default.
- Specified by:
get
in interfaceIPreferences
- 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, or the backing store is inaccessible.
-
getBoolean
Description copied from interface:IPreferences
Returns the current value of the boolean-valued preference with the given name. Returns the default-default value (false
) if there is no preference with the given name, or if the current value cannot be treated as a boolean.- Specified by:
getBoolean
in interfaceIPreferences
- Parameters:
name
- the name of the preference- Returns:
- the boolean-valued preference
-
getBoolean
Description copied from interface:IPreferences
Returns the boolean value represented by the string associated with the specified key in this preference node. Valid strings are "true", which represents true, and "false", which represents false. Case is ignored, so, for example, "TRUE" and "False" are also valid. This method is intended for use in conjunction withIPreferences.putBoolean(java.lang.String, boolean)
.Returns the specified default if there is no value associated with the key, the backing store is inaccessible, or if the associated value is something other than "true" or "false", ignoring case.
If the implementation supports stored defaults and such a default exists and is accessible, it is used in preference to the specified default, unless the stored default is something other than "true" or "false", ignoring case, in which case the specified default is used.
- Specified by:
getBoolean
in interfaceIPreferences
- Parameters:
key
- key whose associated value is 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 or the associated value cannot be interpreted as a boolean, or the backing store is inaccessible.- Returns:
- the boolean value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as a boolean.
- See Also:
-
getByteArray
Description copied from interface:IPreferences
Returns the byte array value represented by the string associated with the specified key in this preference node. Valid strings are Base64 encoded binary data, as defined in RFC 2045, Section 6.8, with one minor change: the string must consist solely of characters from the Base64 Alphabet; no newline characters or extraneous characters are permitted. This method is intended for use in conjunction withIPreferences.putByteArray(java.lang.String, byte[])
.Returns the specified default if there is no value associated with the key, the backing store is inaccessible, or if the associated value is not a valid Base64 encoded byte array (as defined above).
If the implementation supports stored defaults and such a default exists and is accessible, it is used in preference to the specified default, unless the stored default is not a valid Base64 encoded byte array (as defined above), in which case the specified default is used.
- Specified by:
getByteArray
in interfaceIPreferences
- Parameters:
key
- key whose associated value is to be returned as a byte array.def
- the value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as a byte array, or the backing store is inaccessible.- Returns:
- the byte array value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as a byte array.
- See Also:
-
getDouble
Description copied from interface:IPreferences
Returns the current value of the double-valued preference with the given name. Returns the default-default value (0.0
) if there is no preference with the given name, or if the current value cannot be treated as a double.- Specified by:
getDouble
in interfaceIPreferences
- Parameters:
name
- the name of the preference- Returns:
- the double-valued preference
-
getDouble
Description copied from interface:IPreferences
Returns the double value represented by the string associated with the specified key in this preference node. The string is converted to an integer as byDouble.parseDouble(String)
. Returns the specified default if there is no value associated with the key, the backing store is inaccessible, or if Double.parseDouble(String) would throw aNumberFormatException
if the associated value were passed. This method is intended for use in conjunction withIPreferences.putDouble(java.lang.String, double)
.If the implementation supports stored defaults and such a default exists, is accessible, and could be converted to a double with Double.parseDouble, this double is returned in preference to the specified default.
- Specified by:
getDouble
in interfaceIPreferences
- Parameters:
key
- key whose associated value is to be returned as a double.def
- the value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as a double, or the backing store is inaccessible.- Returns:
- the double value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as a double.
- See Also:
-
getFloat
Description copied from interface:IPreferences
Returns the current value of the float-valued preference with the given name. Returns the default-default value (0.0f
) if there is no preference with the given name, or if the current value cannot be treated as a float.- Specified by:
getFloat
in interfaceIPreferences
- Parameters:
name
- the name of the preference- Returns:
- the float-valued preference
-
getFloat
Description copied from interface:IPreferences
Returns the float value represented by the string associated with the specified key in this preference node. The string is converted to an integer as byFloat.parseFloat(String)
. Returns the specified default if there is no value associated with the key, the backing store is inaccessible, or if Float.parseFloat(String) would throw aNumberFormatException
if the associated value were passed. This method is intended for use in conjunction withIPreferences.putFloat(java.lang.String, float)
.If the implementation supports stored defaults and such a default exists, is accessible, and could be converted to a float with Float.parseFloat, this float is returned in preference to the specified default.
- Specified by:
getFloat
in interfaceIPreferences
- Parameters:
key
- key whose associated value is to be returned as a float.def
- the value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as a float, or the backing store is inaccessible.- Returns:
- the float value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as a float.
- See Also:
-
getInt
Description copied from interface:IPreferences
Returns the current value of the integer-valued preference with the given name. Returns the default-default value (0
) if there is no preference with the given name, or if the current value cannot be treated as an integer.- Specified by:
getInt
in interfaceIPreferences
- Parameters:
name
- the name of the preference- Returns:
- the int-valued preference
-
getInt
Description copied from interface:IPreferences
Returns the int value represented by the string associated with the specified key in this preference node. The string is converted to an integer as byInteger.parseInt(String)
. Returns the specified default if there is no value associated with the key, the backing store is inaccessible, or if Integer.parseInt(String) would throw aNumberFormatException
if the associated value were passed. This method is intended for use in conjunction withIPreferences.putInt(java.lang.String, int)
.If the implementation supports stored defaults and such a default exists, is accessible, and could be converted to an int with Integer.parseInt, this int is returned in preference to the specified default.
- Specified by:
getInt
in interfaceIPreferences
- Parameters:
key
- key whose associated value is 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 or the associated value cannot be interpreted as an int, or the backing store is inaccessible.- Returns:
- the int value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as an int.
- See Also:
-
getLong
Description copied from interface:IPreferences
Returns the current value of the long-valued preference with the given name. Returns the default-default value (0L
) if there is no preference with the given name, or if the current value cannot be treated as a long.- Specified by:
getLong
in interfaceIPreferences
- Parameters:
name
- the name of the preference- Returns:
- the long-valued preference
-
getLong
Description copied from interface:IPreferences
Returns the long value represented by the string associated with the specified key in this preference node. The string is converted to a long as byLong.parseLong(String)
. Returns the specified default if there is no value associated with the key, the backing store is inaccessible, or if Long.parseLong(String) would throw aNumberFormatException
if the associated value were passed. This method is intended for use in conjunction withIPreferences.putLong(java.lang.String, long)
.If the implementation supports stored defaults and such a default exists, is accessible, and could be converted to a long with Long.parseLong, this long is returned in preference to the specified default.
- Specified by:
getLong
in interfaceIPreferences
- Parameters:
key
- key whose associated value is to be returned as a long.def
- the value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as a long, or the backing store is inaccessible.- Returns:
- the long value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as a long.
- See Also:
-
keys
Description copied from interface:IPreferences
Returns all of the keys that have an associated value in this preference node. (The returned array will be of size zero if this node has no preferences.)If the implementation supports stored defaults and there are any such defaults at this node that have not been overridden, by explicit preferences, the defaults are returned in the array in addition to any explicit preferences.
- Specified by:
keys
in interfaceIPreferences
- Returns:
- an array of the keys that have an associated value in this preference node.
-
name
Description copied from interface:IPreferences
Returns this preference node's name, relative to its parent.- Specified by:
name
in interfaceIPreferences
- Returns:
- this preference node's name, relative to its parent.
-
node
Description copied from interface:IPreferences
Returns the named preference node in the same tree as this node, creating it and any of its ancestors if they do not already exist. Accepts a relative or absolute path name. Relative path names (which do not begin with the slash character ('/')) are interpreted relative to this preference node.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 permanent until the flush method is called on the returned node (or one of its ancestors or descendants).
- Specified by:
node
in interfaceIPreferences
- Parameters:
pathName
- the path name of the preference node to return.- Returns:
- the specified preference node.
- See Also:
-
node
-
nodeExists
Description copied from interface:IPreferences
Returns true if the named preference node exists in the same tree as this node. Relative path names (which do not begin with the slash character ('/')) are interpreted relative to this preference node.If this node (or an ancestor) has already been removed with the
IPreferences.removeNode()
method, it is legal to invoke this method, but only with the path name ""; the invocation will return false. Thus, the idiom p.nodeExists("") may be used to test whether p has been removed.- Specified by:
nodeExists
in interfaceIPreferences
- Parameters:
pathName
- the path name of the node whose existence is to be checked.- Returns:
- true if the specified node exists.
- Throws:
BackingStoreException
- if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
-
parent
Description copied from interface:IPreferences
Returns the parent of this preference node, or null if this is the root.- Specified by:
parent
in interfaceIPreferences
- Returns:
- the parent of this preference node.
-
preferenceChange
- Specified by:
preferenceChange
in interfacePreferenceChangeListener
-
properties
Description copied from interface:IPreferences
A map of all property mappings in thisIPreferences
node.- Specified by:
properties
in interfaceIPreferences
- Returns:
- A map of all property mappings in this
IPreferences
node.
-
put
Description copied from interface:IPreferences
Sets the current value of the boolean-valued preference with the given name.- Specified by:
put
in interfaceIPreferences
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
put
Description copied from interface:IPreferences
Associates a string representing the specified byte array with the specified key in this preference node. The associated string is the Base64 encoding of the byte array, as defined in RFC 2045, Section 6.8, with one minor change: the string will consist solely of characters from the Base64 Alphabet; it will not contain any newline characters. Note that the maximum length of the byte array is limited to three quarters of MAX_VALUE_LENGTH so that the length of the Base64 encoded String does not exceed MAX_VALUE_LENGTH. This method is intended for use in conjunction withIPreferences.getByteArray(java.lang.String, byte[])
.- Specified by:
put
in interfaceIPreferences
- Parameters:
name
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.- See Also:
-
put
Description copied from interface:IPreferences
Sets the current value of the double-valued preference with the given name.- Specified by:
put
in interfaceIPreferences
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
put
Description copied from interface:IPreferences
Sets the current value of the float-valued preference with the given name.- Specified by:
put
in interfaceIPreferences
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
put
Description copied from interface:IPreferences
Sets the current value of the integer-valued preference with the given name.- Specified by:
put
in interfaceIPreferences
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
put
Description copied from interface:IPreferences
Sets the current value of the long-valued preference with the given name.- Specified by:
put
in interfaceIPreferences
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
put
Description copied from interface:IPreferences
Sets the current value of the string-valued preference with the given name.- Specified by:
put
in interfaceIPreferences
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
putBoolean
Description copied from interface:IPreferences
Set the current value. This is for drop in compatibility to Java platform preferences.- Specified by:
putBoolean
in interfaceIPreferences
-
putByteArray
Description copied from interface:IPreferences
Set the current value. This is for drop in compatibility to Java platform preferences.- Specified by:
putByteArray
in interfaceIPreferences
-
putDouble
Description copied from interface:IPreferences
Set the current value. This is for drop in compatibility to Java platform preferences.- Specified by:
putDouble
in interfaceIPreferences
-
putFloat
Description copied from interface:IPreferences
Set the current value. This is for drop in compatibility to Java platform preferences.- Specified by:
putFloat
in interfaceIPreferences
-
putInt
Description copied from interface:IPreferences
Set the current value. This is for drop in compatibility to Java platform preferences.- Specified by:
putInt
in interfaceIPreferences
-
putLong
Description copied from interface:IPreferences
Set the current value. This is for drop in compatibility to Java platform preferences.- Specified by:
putLong
in interfaceIPreferences
-
remove
Description copied from interface:IPreferences
Removes the value associated with the specified key in this preference node, if any.If this implementation supports stored defaults, and there is such a default for the specified preference, the stored default will be "exposed" by this call, in the sense that it will be returned by a succeeding call to get.
- Specified by:
remove
in interfaceIPreferences
- Parameters:
name
- key whose mapping is to be removed from the preference node.
-
removeNode
Description copied from interface:IPreferences
Removes this preference node and all of its descendants, invalidating any preferences contained in the removed nodes. Once a node has been removed, attempting any method other thanIPreferences.name()
,IPreferences.absolutePath()
,IPreferences.flush()
ornodeExists("")
on the corresponding Preferences instance will fail with an IllegalStateException. (The methods defined onObject
can still be invoked on a node after it has been removed; they will not throw IllegalStateException.)The removal is not guaranteed to be persistent until the flush method is called on this node (or an ancestor).
If this implementation supports stored defaults, removing a node exposes any stored defaults at or below this node. Thus, a subsequent call to nodeExists on this node's path name may return true, and a subsequent call to node on this path name may may return a (different) Preferences instance representing a non-empty collection of preferences and/or children.
- Specified by:
removeNode
in interfaceIPreferences
- Throws:
BackingStoreException
- if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.- See Also:
-
removeNotificationListener
Description copied from interface:INotificationSupport
Removelistener
from the collection of objects to be informed about events of typename
.- Specified by:
removeNotificationListener
in interfaceINotificationSupport
- Parameters:
type
- The event type we are no longer interested in.listener
- The object registered for the event till now.
-
restrict
Description copied from interface:IPreferences
Create a new IPreferences object whose scopes include all scopes from the receiver before and including "scopeName".- Specified by:
restrict
in interfaceIPreferences
- Returns:
- a new IPreferences object whose scopes include all scopes from the receiver before and including "scopeName".
-
sync
Description copied from interface:IPreferences
Ensures that future reads from this preference node and its descendants reflect any changes that were committed to the persistent store (from any VM) prior to the sync invocation. As a side-effect, forces any changes in the contents of this preference node and its descendants to the persistent store, as if the flush method had been invoked on this node.- Specified by:
sync
in interfaceIPreferences
- Throws:
BackingStoreException
- if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.- See Also:
-
triggerChange
-
triggerEvent
-