Package org.apache.felix.prefs
Class PreferencesImpl
java.lang.Object
org.apache.felix.prefs.PreferencesImpl
- All Implemented Interfaces:
org.osgi.service.prefs.Preferences
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
FieldsModifier and TypeFieldDescriptionprotected final ChangeSetThe change set keeps track of all changes.protected final Map<String, PreferencesImpl> The child nodes.protected final PreferencesDescriptionThe description for this preferences.protected final StringThe name of the properties.protected final PreferencesImplThe parent.The properties.protected final BackingStoreManagerThe backing store manager.protected booleanHas this node been removed? -
Constructor Summary
ConstructorsConstructorDescriptionPreferencesImpl(PreferencesDescription d, BackingStoreManager storeManager) Construct the root node of the tree.PreferencesImpl(PreferencesImpl p, String name) Construct a child node. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyChanges(PreferencesImpl prefs) Apply the changes done to the passed preferences object.protected voidThe key is not allowed to be null.protected voidCheck if this node is still valid.protected voidcheckValue(Object value) The value is not allowed to be null.String[]voidclear()voidflush()Return the backing store manager.booleangetBoolean(String key, boolean def) byte[]getByteArray(String key, byte[] def) Return the change set.Return all children or an empty collection.Return the preferences description.doublefloatintlongprotected PreferencesImplGet a relative node.getOrCreateNode(String pathName) Get or create the node.Return the properties set.getRoot()Get the root preferences.booleanisValid()String[]keys()name()org.osgi.service.prefs.PreferencesWe do not synchronize this method to avoid dead locks as this method might call another preferences object in the hierarchy.booleannodeExists(String pathName) We do not synchronize this method to avoid dead locks as this method might call another preferences object in the hierarchy.org.osgi.service.prefs.Preferencesparent()voidvoidputBoolean(String key, boolean value) voidputByteArray(String key, byte[] value) voidvoidvoidvoidvoidprotected voidremoveChild(PreferencesImpl child) voidprotected voidSafely remove a node by resetting all properties and calling this method on all children recursively.voidsync()voidupdate(PreferencesImpl impl) Update from the preferences impl.
-
Field Details
-
properties
The properties. -
valid
protected boolean validHas this node been removed? -
parent
The parent. -
children
The child nodes. -
name
The name of the properties. -
description
The description for this preferences. -
storeManager
The backing store manager. -
changeSet
The change set keeps track of all changes.
-
-
Constructor Details
-
PreferencesImpl
Construct the root node of the tree.- Parameters:
d- The unique description.storeManager- The backing store.
-
PreferencesImpl
Construct a child node.- Parameters:
p- The parent node.name- The node name
-
-
Method Details
-
getChangeSet
Return the change set. -
getDescription
Return the preferences description.- Returns:
- The preferences description.
-
getRoot
Get the root preferences. -
getChildren
Return all children or an empty collection.- Returns:
- A collection containing the children.
-
getProperties
Return the properties set. -
getBackingStoreManager
Return the backing store manager. -
checkValidity
Check if this node is still valid. It gets invalid if it has been removed.- Throws:
IllegalStateException
-
checkKey
The key is not allowed to be null.- Throws:
NullPointerException
-
checkValue
The value is not allowed to be null.- Throws:
NullPointerException
-
isValid
public boolean isValid() -
put
- Specified by:
putin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
get
- Specified by:
getin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
remove
- Specified by:
removein interfaceorg.osgi.service.prefs.Preferences- See Also:
-
clear
public void clear() throws org.osgi.service.prefs.BackingStoreException- Specified by:
clearin interfaceorg.osgi.service.prefs.Preferences- Throws:
org.osgi.service.prefs.BackingStoreException- See Also:
-
putInt
- Specified by:
putIntin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
getInt
- Specified by:
getIntin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
putLong
- Specified by:
putLongin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
getLong
- Specified by:
getLongin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
putBoolean
- Specified by:
putBooleanin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
getBoolean
- Specified by:
getBooleanin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
putFloat
- Specified by:
putFloatin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
getFloat
- Specified by:
getFloatin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
putDouble
- Specified by:
putDoublein interfaceorg.osgi.service.prefs.Preferences- See Also:
-
getDouble
- Specified by:
getDoublein interfaceorg.osgi.service.prefs.Preferences- See Also:
-
putByteArray
- Specified by:
putByteArrayin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
getByteArray
- Specified by:
getByteArrayin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
keys
- Specified by:
keysin interfaceorg.osgi.service.prefs.Preferences- Throws:
org.osgi.service.prefs.BackingStoreException- See Also:
-
childrenNames
- Specified by:
childrenNamesin interfaceorg.osgi.service.prefs.Preferences- Throws:
org.osgi.service.prefs.BackingStoreException- See Also:
-
parent
public org.osgi.service.prefs.Preferences parent()- Specified by:
parentin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
node
We do not synchronize this method to avoid dead locks as this method might call another preferences object in the hierarchy.- Specified by:
nodein interfaceorg.osgi.service.prefs.Preferences- See Also:
-
getOrCreateNode
Get or create the node. If the node already exists, it's just returned. If not it is created.- Parameters:
pathName-- Returns:
- The preferences impl for the path.
-
getNode
Get a relative node.- Parameters:
path-- Returns:
-
nodeExists
We do not synchronize this method to avoid dead locks as this method might call another preferences object in the hierarchy.- Specified by:
nodeExistsin interfaceorg.osgi.service.prefs.Preferences- Throws:
org.osgi.service.prefs.BackingStoreException- See Also:
-
removeNode
public void removeNode() throws org.osgi.service.prefs.BackingStoreException- Specified by:
removeNodein interfaceorg.osgi.service.prefs.Preferences- Throws:
org.osgi.service.prefs.BackingStoreException- See Also:
-
safelyRemoveNode
protected void safelyRemoveNode()Safely remove a node by resetting all properties and calling this method on all children recursively. -
removeChild
-
name
- Specified by:
namein interfaceorg.osgi.service.prefs.Preferences- See Also:
-
absolutePath
- Specified by:
absolutePathin interfaceorg.osgi.service.prefs.Preferences- See Also:
-
flush
public void flush() throws org.osgi.service.prefs.BackingStoreException- Specified by:
flushin interfaceorg.osgi.service.prefs.Preferences- Throws:
org.osgi.service.prefs.BackingStoreException- See Also:
-
sync
public void sync() throws org.osgi.service.prefs.BackingStoreException- Specified by:
syncin interfaceorg.osgi.service.prefs.Preferences- Throws:
org.osgi.service.prefs.BackingStoreException- See Also:
-
update
Update from the preferences impl.- Parameters:
impl-
-
applyChanges
Apply the changes done to the passed preferences object.- Parameters:
prefs-
-