|
intarsys runtime library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.intarsys.tools.preferences.PreferencesAdapter
public class PreferencesAdapter
Adapt 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 | |
---|---|
PreferencesAdapter(PreferencesAdapter parent,
Preferences jPrefs)
|
Method Summary | |
---|---|
String |
absolutePath()
Returns this preference node's absolute path name. |
void |
addNotificationListener(EventType type,
INotificationListener listener)
Add listener to the collection of objects to be informed
when the receiver triggers an event of type name . |
IPreferences[] |
children()
The array of all child preferences. |
String[] |
childrenNames()
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. |
void |
flush()
Forces any changes in the contents of this preference node and its descendants to the persistent store. |
String |
get(String name)
Returns the current value of the string-valued preference with the given name. |
String |
get(String key,
String def)
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 |
getDouble(String name)
Returns the current value of the double-valued preference with the given name. |
double |
getDouble(String key,
double def)
Returns the double value represented by the string associated with the specified key in this preference node. |
float |
getFloat(String name)
Returns the current value of the float-valued preference with the given name. |
float |
getFloat(String key,
float def)
Returns the float value represented by the string associated with the specified key in this preference node. |
int |
getInt(String name)
Returns the current value of the integer-valued preference with the given name. |
int |
getInt(String key,
int def)
Returns the int value represented by the string associated with the specified key in this preference node. |
long |
getLong(String name)
Returns the current value of the long-valued preference with the given name. |
long |
getLong(String key,
long def)
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. |
String |
name()
Returns this preference node's name, relative to its parent. |
IPreferences |
node(String pathName)
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. |
boolean |
nodeExists(String pathName)
Returns true if the named preference node exists in the same tree as this node. |
IPreferences |
parent()
Returns the parent of this preference node, or null if this is the root. |
void |
preferenceChange(PreferenceChangeEvent evt)
|
Map<String,String> |
properties()
A map of all property mappings in this IPreferences node. |
void |
put(String name,
boolean value)
Sets the current value of the boolean-valued preference with the given name. |
void |
put(String name,
byte[] value)
Associates a string representing the specified byte array with the specified key in this preference node. |
void |
put(String name,
double value)
Sets the current value of the double-valued preference with the given name. |
void |
put(String name,
float value)
Sets the current value of the float-valued preference with the given name. |
void |
put(String name,
int value)
Sets the current value of the integer-valued preference with the given name. |
void |
put(String name,
long value)
Sets the current value of the long-valued preference with the given name. |
void |
put(String name,
String value)
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 |
putDouble(String key,
double value)
Set the current value. |
void |
putFloat(String key,
float value)
Set the current value. |
void |
putInt(String key,
int value)
Set the current value. |
void |
putLong(String key,
long value)
Set the current value. |
void |
remove(String name)
Removes the value associated with the specified key in this preference node, if any. |
void |
removeNode()
Removes this preference node and all of its descendants, invalidating any preferences contained in the removed nodes. |
void |
removeNotificationListener(EventType type,
INotificationListener listener)
Remove listener from the collection of objects to be
informed about events of type name . |
IPreferences |
restrict(String scopeName)
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. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PreferencesAdapter(PreferencesAdapter parent, Preferences jPrefs)
Method Detail |
---|
public String absolutePath()
IPreferences
absolutePath
in interface IPreferences
public void addNotificationListener(EventType type, INotificationListener listener)
INotificationSupport
listener
to the collection of objects to be informed
when the receiver triggers an event of type name
.
addNotificationListener
in interface INotificationSupport
type
- The event type we are interested in.listener
- The object to be informed about an event occurrencepublic IPreferences[] children()
IPreferences
children
in interface IPreferences
public String[] childrenNames()
IPreferences
childrenNames
in interface IPreferences
public void clear() throws BackingStoreException
IPreferences
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.
clear
in interface IPreferences
BackingStoreException
- if this operation cannot be completed due to a failure in the
backing store, or inability to communicate with it.IPreferences.removeNode()
public void flush()
IPreferences
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.
flush
in interface IPreferences
IPreferences.sync()
public String get(String name)
IPreferences
""
)
if there is no preference with the given name, or if the current value
cannot be treated as a string.
get
in interface IPreferences
name
- the name of the preference
public String get(String key, String def)
IPreferences
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.
get
in interface IPreferences
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 boolean getBoolean(String name)
IPreferences
false
) if there
is no preference with the given name, or if the current value cannot be
treated as a boolean.
getBoolean
in interface IPreferences
name
- the name of the preference
public boolean getBoolean(String key, boolean def)
IPreferences
IPreferences.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.
getBoolean
in interface IPreferences
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.
IPreferences.get(String,String)
,
IPreferences.putBoolean(String,boolean)
public byte[] getByteArray(String key, byte[] def)
IPreferences
IPreferences.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.
getByteArray
in interface IPreferences
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.
IPreferences.get(String,String)
,
IPreferences.putByteArray(String,byte[])
public double getDouble(String name)
IPreferences
0.0
) if there
is no preference with the given name, or if the current value cannot be
treated as a double.
getDouble
in interface IPreferences
name
- the name of the preference
public double getDouble(String key, double def)
IPreferences
Double.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
a NumberFormatException
if the associated value were passed. This
method is intended for use in conjunction with IPreferences.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.
getDouble
in interface IPreferences
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.
IPreferences.putDouble(String,double)
,
IPreferences.get(String,String)
public float getFloat(String name)
IPreferences
0.0f
) if there
is no preference with the given name, or if the current value cannot be
treated as a float.
getFloat
in interface IPreferences
name
- the name of the preference
public float getFloat(String key, float def)
IPreferences
Float.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 a
NumberFormatException
if the associated value were passed. This
method is intended for use in conjunction with IPreferences.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.
getFloat
in interface IPreferences
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.
IPreferences.putFloat(String,float)
,
IPreferences.get(String,String)
public int getInt(String name)
IPreferences
0
) if there is
no preference with the given name, or if the current value cannot be
treated as an integter.
getInt
in interface IPreferences
name
- the name of the preference
public int getInt(String key, int def)
IPreferences
Integer.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 a
NumberFormatException
if the associated value were passed. This
method is intended for use in conjunction with IPreferences.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.
getInt
in interface IPreferences
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.
IPreferences.putInt(String,int)
,
IPreferences.get(String,String)
public long getLong(String name)
IPreferences
0L
) if there is
no preference with the given name, or if the current value cannot be
treated as a long.
getLong
in interface IPreferences
name
- the name of the preference
public long getLong(String key, long def)
IPreferences
Long.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 a
NumberFormatException
if the associated value were passed. This
method is intended for use in conjunction with IPreferences.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.
getLong
in interface IPreferences
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.
IPreferences.putLong(String,long)
,
IPreferences.get(String,String)
public String[] keys()
IPreferences
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.
keys
in interface IPreferences
public String name()
IPreferences
name
in interface IPreferences
public IPreferences node(String pathName)
IPreferences
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).
node
in interface IPreferences
pathName
- the path name of the preference node to return.
IPreferences.flush()
public boolean nodeExists(String pathName) throws BackingStoreException
IPreferences
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.
nodeExists
in interface IPreferences
pathName
- the path name of the node whose existence is to be checked.
BackingStoreException
- if this operation cannot be completed due to a failure in the
backing store, or inability to communicate with it.public IPreferences parent()
IPreferences
parent
in interface IPreferences
public void preferenceChange(PreferenceChangeEvent evt)
preferenceChange
in interface PreferenceChangeListener
public Map<String,String> properties()
IPreferences
IPreferences
node.
properties
in interface IPreferences
IPreferences
node.public void put(String name, boolean value)
IPreferences
put
in interface IPreferences
name
- the name of the preferencevalue
- the new current value of the preferencepublic void put(String name, byte[] value)
IPreferences
IPreferences.getByteArray(java.lang.String, byte[])
.
put
in interface IPreferences
name
- key with which the string form of value is to be associated.value
- value whose string form is to be associated with key.IPreferences.getByteArray(String,byte[])
,
IPreferences.get(String,String)
public void put(String name, double value)
IPreferences
put
in interface IPreferences
name
- the name of the preferencevalue
- the new current value of the preferencepublic void put(String name, float value)
IPreferences
put
in interface IPreferences
name
- the name of the preferencevalue
- the new current value of the preferencepublic void put(String name, int value)
IPreferences
put
in interface IPreferences
name
- the name of the preferencevalue
- the new current value of the preferencepublic void put(String name, long value)
IPreferences
put
in interface IPreferences
name
- the name of the preferencevalue
- the new current value of the preferencepublic void put(String name, String value)
IPreferences
put
in interface IPreferences
name
- the name of the preferencevalue
- the new current value of the preferencepublic void putBoolean(String key, boolean value)
IPreferences
putBoolean
in interface IPreferences
public void putByteArray(String name, byte[] value)
IPreferences
putByteArray
in interface IPreferences
public void putDouble(String key, double value)
IPreferences
putDouble
in interface IPreferences
public void putFloat(String key, float value)
IPreferences
putFloat
in interface IPreferences
public void putInt(String key, int value)
IPreferences
putInt
in interface IPreferences
public void putLong(String key, long value)
IPreferences
putLong
in interface IPreferences
public void remove(String name)
IPreferences
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.
remove
in interface IPreferences
name
- key whose mapping is to be removed from the preference node.public void removeNode() throws BackingStoreException
IPreferences
IPreferences.name()
,
IPreferences.absolutePath()
, #isUserNode()
, IPreferences.flush()
or
nodeExists("")
on the corresponding
Preferences instance will fail with an
IllegalStateException. (The methods defined on Object
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.
removeNode
in interface IPreferences
BackingStoreException
- if this operation cannot be completed due to a failure in the
backing store, or inability to communicate with it.IPreferences.flush()
public void removeNotificationListener(EventType type, INotificationListener listener)
INotificationSupport
listener
from the collection of objects to be
informed about events of type name
.
removeNotificationListener
in interface INotificationSupport
type
- The event type we are no longer interested in.listener
- The object registered for the event till now.public IPreferences restrict(String scopeName)
IPreferences
restrict
in interface IPreferences
public void sync() throws BackingStoreException
IPreferences
sync
in interface IPreferences
BackingStoreException
- if this operation cannot be completed due to a failure in the
backing store, or inability to communicate with it.IPreferences.flush()
|
intarsys runtime library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |