|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.felix.prefs.PreferencesImpl
public class PreferencesImpl
This is an implementation of the preferences. The access to the preferences is synchronized on the instance by making (nearly) all public methods synchronized. This avoids the heavy management of a separate read/write lock. Such a lock is too heavy for the simple operations preferences support. The various getXX and putXX methods are not synchronized as they all use the get/put methods which are synchronized.
Field Summary | |
---|---|
protected ChangeSet |
changeSet
The change set keeps track of all changes. |
protected Map |
children
The child nodes. |
protected PreferencesDescription |
description
The description for this preferences. |
protected String |
name
The name of the properties. |
protected PreferencesImpl |
parent
The parent. |
protected Map |
properties
The properties. |
protected BackingStoreManager |
storeManager
The backing store manager. |
protected boolean |
valid
Has this node been removed? |
Constructor Summary | |
---|---|
PreferencesImpl(PreferencesDescription d,
BackingStoreManager storeManager)
Construct the root node of the tree. |
|
PreferencesImpl(PreferencesImpl p,
String name)
Construct a child node. |
Method Summary | |
---|---|
String |
absolutePath()
Returns this node's absolute path name. |
void |
applyChanges(PreferencesImpl prefs)
Apply the changes done to the passed preferences object. |
protected void |
checkKey(String key)
The key is not allowed to be null. |
protected void |
checkValidity()
Check if this node is still valid. |
protected void |
checkValue(Object value)
The value is not allowed to be null. |
String[] |
childrenNames()
Returns the names of the children of this node. |
void |
clear()
Removes all of the properties (key-value associations) in this node. |
void |
flush()
Forces any changes in the contents of this node and its descendants to the persistent store. |
String |
get(String key,
String def)
Returns the value associated with the specified key in this
node. |
BackingStoreManager |
getBackingStoreManager()
Return the backing store manager. |
boolean |
getBoolean(String key,
boolean def)
Returns the boolean value represented by the String
object associated with the specified key in this node. |
byte[] |
getByteArray(String key,
byte[] def)
Returns the byte[] value represented by the String
object associated with the specified key in this node. |
ChangeSet |
getChangeSet()
Return the change set. |
Collection |
getChildren()
Return all children or an empty collection. |
PreferencesDescription |
getDescription()
Return the preferences description. |
double |
getDouble(String key,
double def)
Returns the double value represented by the String
object associated with the specified key in this node. |
float |
getFloat(String key,
float def)
Returns the float value represented by the String
object associated with the specified key in this node. |
int |
getInt(String key,
int def)
Returns the int value represented by the String
object associated with the specified key in this node. |
long |
getLong(String key,
long def)
Returns the long value represented by the String
object associated with the specified key in this node. |
protected PreferencesImpl |
getNode(String path,
boolean saveNewlyCreatedNode,
boolean create)
Get a relative node. |
PreferencesImpl |
getOrCreateNode(String pathName)
Get or create the node. |
Map |
getProperties()
Return the properties set. |
PreferencesImpl |
getRoot()
Get the root preferences. |
boolean |
isValid()
|
String[] |
keys()
Returns all of the keys that have an associated value in this node. |
String |
name()
Returns this node's name, relative to its parent. |
Preferences |
node(String pathName)
We do not synchronize this method to avoid dead locks as this method might call another preferences object in the hierarchy. |
boolean |
nodeExists(String pathName)
We do not synchronize this method to avoid dead locks as this method might call another preferences object in the hierarchy. |
Preferences |
parent()
Returns the parent of this node, or null if this is the root. |
void |
put(String key,
String value)
Associates the specified value with the specified key in this node. |
void |
putBoolean(String key,
boolean value)
Associates a String object representing the specified
boolean value with the specified key in this node. |
void |
putByteArray(String key,
byte[] value)
Associates a String object representing the specified
byte[] with the specified key in this node. |
void |
putDouble(String key,
double value)
Associates a String object representing the specified
double value with the specified key in this node. |
void |
putFloat(String key,
float value)
Associates a String object representing the specified
float value with the specified key in this node. |
void |
putInt(String key,
int value)
Associates a String object representing the specified
int value with the specified key in this node. |
void |
putLong(String key,
long value)
Associates a String object representing the specified
long value with the specified key in this node. |
void |
remove(String key)
Removes the value associated with the specified key in this
node, if any. |
protected void |
removeChild(PreferencesImpl child)
|
void |
removeNode()
Removes this node and all of its descendants, invalidating any properties contained in the removed nodes. |
protected void |
safelyRemoveNode()
Safely remove a node by resetting all properties and calling this method on all children recursively. |
void |
sync()
Ensures that future reads from this node and its descendants reflect any changes that were committed to the persistent store (from any VM) prior to the sync invocation. |
void |
update(PreferencesImpl impl)
Update from the preferences impl. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Map properties
protected boolean valid
protected final PreferencesImpl parent
protected final Map children
protected final String name
protected final PreferencesDescription description
protected final BackingStoreManager storeManager
protected final ChangeSet changeSet
Constructor Detail |
---|
public PreferencesImpl(PreferencesDescription d, BackingStoreManager storeManager)
d
- The unique description.storeManager
- The backing store.public PreferencesImpl(PreferencesImpl p, String name)
p
- The parent node.name
- The node nameMethod Detail |
---|
public ChangeSet getChangeSet()
public PreferencesDescription getDescription()
public PreferencesImpl getRoot()
public Collection getChildren()
public Map getProperties()
public BackingStoreManager getBackingStoreManager()
protected void checkValidity() throws IllegalStateException
IllegalStateException
protected void checkKey(String key) throws NullPointerException
NullPointerException
protected void checkValue(Object value) throws NullPointerException
NullPointerException
public boolean isValid()
public void put(String key, String value)
Preferences
put
in interface Preferences
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.Preferences.put(java.lang.String, java.lang.String)
public String get(String key, String def)
Preferences
key
in this
node. Returns the specified default if there is no value associated with
the key
, or the backing store is inaccessible.
get
in interface Preferences
key
- key whose associated value is to be returned.def
- the value to be returned in the event that this node has no
value associated with key
or the backing store is
inaccessible.
key
, or def
if
no value is associated with key
.Preferences.get(java.lang.String, java.lang.String)
public void remove(String key)
Preferences
key
in this
node, if any.
remove
in interface Preferences
key
- key whose mapping is to be removed from this node.Preferences.remove(java.lang.String)
public void clear() throws BackingStoreException
Preferences
clear
in interface Preferences
BackingStoreException
- if this operation cannot be completed due
to a failure in the backing store, or inability to communicate
with it.Preferences.clear()
public void putInt(String key, int value)
Preferences
String
object representing the specified
int
value with the specified key
in this node. The
associated string is the one that would be returned if the int
value were passed to Integer.toString(int)
. This method is
intended for use in conjunction with Preferences.getInt(java.lang.String, int)
method.
Implementor's note: it is not necessary that the property value
be represented by a String
object in the backing store. If the
backing store supports integer values, it is not unreasonable to use
them. This implementation detail is not visible through the
Preferences
API, which allows the value to be read as an
int
(with getInt
or a String
(with
get
) type.
putInt
in interface Preferences
key
- key with which the string form of value is to be associated.value
- value
whose string form is to be associated with
key
.Preferences.putInt(java.lang.String, int)
public int getInt(String key, int def)
Preferences
int
value represented by the String
object associated with the specified key
in this node. The
String
object is converted to an int
as by
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 the
Preferences.putInt(java.lang.String, int)
method.
getInt
in interface Preferences
key
- key whose associated value is to be returned as an
int
.def
- the value to be returned in the event that this node has no
value associated with key
or the associated value
cannot be interpreted as an int
or the backing store is
inaccessible.
int
value represented by the String
object associated with key
in this node, or
def
if the associated value does not exist or cannot
be interpreted as an int
type.Preferences.getInt(java.lang.String, int)
public void putLong(String key, long value)
Preferences
String
object representing the specified
long
value with the specified key
in this node. The
associated String
object is the one that would be returned if
the long
value were passed to Long.toString(long)
.
This method is intended for use in conjunction with the Preferences.getLong(java.lang.String, long)
method.
Implementor's note: it is not necessary that the value
be represented by a String
type in the backing store. If the
backing store supports long
values, it is not unreasonable to
use them. This implementation detail is not visible through the
Preferences
API, which allows the value to be read as a
long
(with getLong
or a String
(with
get
) type.
putLong
in interface Preferences
key
- key
with which the string form of value
is to be associated.value
- value
whose string form is to be associated with
key
.Preferences.putLong(java.lang.String, long)
public long getLong(String key, long def)
Preferences
long
value represented by the String
object associated with the specified key
in this node. The
String
object is converted to a long
as by
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 the
Preferences.putLong(java.lang.String, long)
method.
getLong
in interface Preferences
key
- key
whose associated value is to be returned as a
long
value.def
- the value to be returned in the event that this node has no
value associated with key
or the associated value
cannot be interpreted as a long
type or the backing
store is inaccessible.
long
value represented by the String
object associated with key
in this node, or
def
if the associated value does not exist or cannot
be interpreted as a long
type.Preferences.getLong(java.lang.String, long)
public void putBoolean(String key, boolean value)
Preferences
String
object representing the specified
boolean
value with the specified key in this node. The
associated string is "true" if the value is true
, and "false"
if it is false
. This method is intended for use in
conjunction with the Preferences.getBoolean(java.lang.String, boolean)
method.
Implementor's note: it is not necessary that the value be
represented by a string in the backing store. If the backing store
supports boolean
values, it is not unreasonable to use them.
This implementation detail is not visible through the Preferences
API, which allows the value to be read as a boolean
(with getBoolean
) or a String
(with get
)
type.
putBoolean
in interface Preferences
key
- key
with which the string form of value is to be
associated.value
- value whose string form is to be associated with
key
.Preferences.putBoolean(java.lang.String, boolean)
public boolean getBoolean(String key, boolean def)
Preferences
boolean
value represented by the String
object associated with the specified key
in this 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 with the Preferences.putBoolean(java.lang.String, boolean)
method.
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.
getBoolean
in interface Preferences
key
- key
whose associated value is to be returned as a
boolean
.def
- the value to be returned in the event that this node has no
value associated with key
or the associated value
cannot be interpreted as a boolean
or the backing store
is inaccessible.
boolean
value represented by the String
object associated with key
in this node, or
null
if the associated value does not exist or cannot
be interpreted as a boolean
.Preferences.getBoolean(java.lang.String, boolean)
public void putFloat(String key, float value)
Preferences
String
object representing the specified
float
value with the specified key
in this node.
The associated String
object is the one that would be returned
if the float
value were passed to
Float.toString(float)
. This method is intended for use in
conjunction with the Preferences.getFloat(java.lang.String, float)
method.
Implementor's note: it is not necessary that the value be
represented by a string in the backing store. If the backing store
supports float
values, it is not unreasonable to use them.
This implementation detail is not visible through the Preferences
API, which allows the value to be read as a float
(with
getFloat
) or a String
(with get
) type.
putFloat
in interface Preferences
key
- key
with which the string form of value is to be
associated.value
- value whose string form is to be associated with
key
.Preferences.putFloat(java.lang.String, float)
public float getFloat(String key, float def)
Preferences
value
represented by the String
object associated with the specified key
in this node. The
String
object is converted to a float
value as by
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 the Preferences.putFloat(java.lang.String, float)
method.
getFloat
in interface Preferences
key
- key
whose associated value is to be returned as a
float
value.def
- the value to be returned in the event that this node has no
value associated with key
or the associated value
cannot be interpreted as a float
type or the backing
store is inaccessible.
float
value represented by the string associated
with key
in this node, or def
if the
associated value does not exist or cannot be interpreted as a
float
type.Preferences.getFloat(java.lang.String, float)
public void putDouble(String key, double value)
Preferences
String
object representing the specified
double
value with the specified key
in this node.
The associated String
object is the one that would be returned
if the double
value were passed to
Double.toString(double)
. This method is intended for use in
conjunction with the Preferences.getDouble(java.lang.String, double)
method
Implementor's note: it is not necessary that the value be
represented by a string in the backing store. If the backing store
supports double
values, it is not unreasonable to use them.
This implementation detail is not visible through the Preferences
API, which allows the value to be read as a double
(with
getDouble
) or a String
(with get
)
type.
putDouble
in interface Preferences
key
- key
with which the string form of value is to be
associated.value
- value whose string form is to be associated with
key
.Preferences.putDouble(java.lang.String, double)
public double getDouble(String key, double def)
Preferences
double
value represented by the String
object associated with the specified key
in this node. The
String
object is converted to a double
value as by
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 the
Preferences.putDouble(java.lang.String, double)
method.
getDouble
in interface Preferences
key
- key
whose associated value is to be returned as a
double
value.def
- the value to be returned in the event that this node has no
value associated with key
or the associated value
cannot be interpreted as a double
type or the backing
store is inaccessible.
double
value represented by the String
object associated with key
in this node, or
def
if the associated value does not exist or cannot
be interpreted as a double
type.Preferences.getDouble(java.lang.String, double)
public void putByteArray(String key, byte[] value)
Preferences
String
object representing the specified
byte[]
with the specified key
in this node. The
associated String
object the Base64 encoding of the
byte[]
, 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.
This method is intended for use in conjunction with the
Preferences.getByteArray(java.lang.String, byte[])
method.
Implementor's note: it is not necessary that the value be
represented by a String
type in the backing store. If the
backing store supports byte[]
values, it is not unreasonable
to use them. This implementation detail is not visible through the
Preferences
API, which allows the value to be read as an a
byte[]
object (with getByteArray
) or a
String
object (with get
).
putByteArray
in interface Preferences
key
- key
with which the string form of value
is to be associated.value
- value
whose string form is to be associated with
key
.Preferences.putByteArray(java.lang.String, byte[])
public byte[] getByteArray(String key, byte[] def)
Preferences
byte[]
value represented by the String
object associated with the specified key
in this node. Valid
String
objects 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 with the Preferences.putByteArray(java.lang.String, byte[])
method.
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).
getByteArray
in interface Preferences
key
- key
whose associated value is to be returned as a
byte[]
object.def
- the value to be returned in the event that this node has no
value associated with key
or the associated value
cannot be interpreted as a byte[]
type, or the backing
store is inaccessible.
byte[]
value represented by the String
object associated with key
in this node, or
def
if the associated value does not exist or cannot
be interpreted as a byte[]
.Preferences.getByteArray(java.lang.String, byte[])
public String[] keys() throws BackingStoreException
Preferences
null
!)
keys
in interface Preferences
BackingStoreException
- if this operation cannot be completed due
to a failure in the backing store, or inability to communicate
with it.Preferences.keys()
public String[] childrenNames() throws BackingStoreException
Preferences
null
!)
childrenNames
in interface Preferences
BackingStoreException
- if this operation cannot be completed due
to a failure in the backing store, or inability to communicate
with it.Preferences.childrenNames()
public Preferences parent()
Preferences
null
if this is the root.
parent
in interface Preferences
Preferences.parent()
public Preferences node(String pathName)
node
in interface Preferences
pathName
- the path name of the Preferences
object to
return.
Preferences
object.Preferences.node(java.lang.String)
public PreferencesImpl getOrCreateNode(String pathName)
pathName
-
protected PreferencesImpl getNode(String path, boolean saveNewlyCreatedNode, boolean create)
path
-
public boolean nodeExists(String pathName) throws BackingStoreException
nodeExists
in interface Preferences
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.Preferences.nodeExists(java.lang.String)
public void removeNode() throws BackingStoreException
Preferences
name()
,absolutePath()
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 the parent of this node.
removeNode
in interface Preferences
BackingStoreException
- if this operation cannot be completed due
to a failure in the backing store, or inability to communicate
with it.Preferences.removeNode()
protected void safelyRemoveNode()
protected void removeChild(PreferencesImpl child)
public String name()
Preferences
name
in interface Preferences
Preferences.name()
public String absolutePath()
Preferences
"/"
.
'/'
).
"."
and ".."
have no
special significance in path names.
absolutePath
in interface Preferences
Preferences.absolutePath()
public void flush() throws BackingStoreException
Preferences
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 properties value changes in ancestors are not guaranteed to be made persistent.
flush
in interface Preferences
BackingStoreException
- if this operation cannot be completed due
to a failure in the backing store, or inability to communicate
with it.Preferences.flush()
public void sync() throws BackingStoreException
Preferences
sync
invocation. As a side-effect, forces any changes
in the contents of this node and its descendants to the persistent store,
as if the flush
method had been invoked on this node.
sync
in interface Preferences
BackingStoreException
- if this operation cannot be completed due
to a failure in the backing store, or inability to communicate
with it.Preferences.sync()
public void update(PreferencesImpl impl)
impl
- public void applyChanges(PreferencesImpl prefs)
prefs
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |