Class PreferencesImpl

java.lang.Object
org.apache.felix.prefs.PreferencesImpl
All Implemented Interfaces:
org.osgi.service.prefs.Preferences

public class PreferencesImpl extends Object implements 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 Details

    • properties

      protected final Map<String,String> properties
      The properties.
    • valid

      protected boolean valid
      Has this node been removed?
    • parent

      protected final PreferencesImpl parent
      The parent.
    • children

      protected final Map<String,PreferencesImpl> children
      The child nodes.
    • name

      protected final String name
      The name of the properties.
    • description

      protected final PreferencesDescription description
      The description for this preferences.
    • storeManager

      protected final BackingStoreManager storeManager
      The backing store manager.
    • changeSet

      protected final ChangeSet changeSet
      The change set keeps track of all changes.
  • Constructor Details

    • PreferencesImpl

      public PreferencesImpl(PreferencesDescription d, BackingStoreManager storeManager)
      Construct the root node of the tree.
      Parameters:
      d - The unique description.
      storeManager - The backing store.
    • PreferencesImpl

      public PreferencesImpl(PreferencesImpl p, String name)
      Construct a child node.
      Parameters:
      p - The parent node.
      name - The node name
  • Method Details

    • getChangeSet

      public ChangeSet getChangeSet()
      Return the change set.
    • getDescription

      public PreferencesDescription getDescription()
      Return the preferences description.
      Returns:
      The preferences description.
    • getRoot

      public PreferencesImpl getRoot()
      Get the root preferences.
    • getChildren

      public Collection<PreferencesImpl> getChildren()
      Return all children or an empty collection.
      Returns:
      A collection containing the children.
    • getProperties

      public Map<String,String> getProperties()
      Return the properties set.
    • getBackingStoreManager

      public BackingStoreManager getBackingStoreManager()
      Return the backing store manager.
    • checkValidity

      protected void checkValidity() throws IllegalStateException
      Check if this node is still valid. It gets invalid if it has been removed.
      Throws:
      IllegalStateException
    • checkKey

      protected void checkKey(String key) throws NullPointerException
      The key is not allowed to be null.
      Throws:
      NullPointerException
    • checkValue

      protected void checkValue(Object value) throws NullPointerException
      The value is not allowed to be null.
      Throws:
      NullPointerException
    • isValid

      public boolean isValid()
    • put

      public void put(String key, String value)
      Specified by:
      put in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.put(java.lang.String, java.lang.String)
    • get

      public String get(String key, String def)
      Specified by:
      get in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.get(java.lang.String, java.lang.String)
    • remove

      public void remove(String key)
      Specified by:
      remove in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.remove(java.lang.String)
    • clear

      public void clear() throws org.osgi.service.prefs.BackingStoreException
      Specified by:
      clear in interface org.osgi.service.prefs.Preferences
      Throws:
      org.osgi.service.prefs.BackingStoreException
      See Also:
      • Preferences.clear()
    • putInt

      public void putInt(String key, int value)
      Specified by:
      putInt in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.putInt(java.lang.String, int)
    • getInt

      public int getInt(String key, int def)
      Specified by:
      getInt in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.getInt(java.lang.String, int)
    • putLong

      public void putLong(String key, long value)
      Specified by:
      putLong in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.putLong(java.lang.String, long)
    • getLong

      public long getLong(String key, long def)
      Specified by:
      getLong in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.getLong(java.lang.String, long)
    • putBoolean

      public void putBoolean(String key, boolean value)
      Specified by:
      putBoolean in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.putBoolean(java.lang.String, boolean)
    • getBoolean

      public boolean getBoolean(String key, boolean def)
      Specified by:
      getBoolean in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.getBoolean(java.lang.String, boolean)
    • putFloat

      public void putFloat(String key, float value)
      Specified by:
      putFloat in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.putFloat(java.lang.String, float)
    • getFloat

      public float getFloat(String key, float def)
      Specified by:
      getFloat in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.getFloat(java.lang.String, float)
    • putDouble

      public void putDouble(String key, double value)
      Specified by:
      putDouble in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.putDouble(java.lang.String, double)
    • getDouble

      public double getDouble(String key, double def)
      Specified by:
      getDouble in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.getDouble(java.lang.String, double)
    • putByteArray

      public void putByteArray(String key, byte[] value)
      Specified by:
      putByteArray in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.putByteArray(java.lang.String, byte[])
    • getByteArray

      public byte[] getByteArray(String key, byte[] def)
      Specified by:
      getByteArray in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.getByteArray(java.lang.String, byte[])
    • keys

      public String[] keys() throws org.osgi.service.prefs.BackingStoreException
      Specified by:
      keys in interface org.osgi.service.prefs.Preferences
      Throws:
      org.osgi.service.prefs.BackingStoreException
      See Also:
      • Preferences.keys()
    • childrenNames

      public String[] childrenNames() throws org.osgi.service.prefs.BackingStoreException
      Specified by:
      childrenNames in interface org.osgi.service.prefs.Preferences
      Throws:
      org.osgi.service.prefs.BackingStoreException
      See Also:
      • Preferences.childrenNames()
    • parent

      public org.osgi.service.prefs.Preferences parent()
      Specified by:
      parent in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.parent()
    • node

      public org.osgi.service.prefs.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.
      Specified by:
      node in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.node(java.lang.String)
    • getOrCreateNode

      public PreferencesImpl getOrCreateNode(String pathName)
      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

      protected PreferencesImpl getNode(String path, boolean saveNewlyCreatedNode, boolean create)
      Get a relative node.
      Parameters:
      path -
      Returns:
    • nodeExists

      public boolean nodeExists(String pathName) throws org.osgi.service.prefs.BackingStoreException
      We do not synchronize this method to avoid dead locks as this method might call another preferences object in the hierarchy.
      Specified by:
      nodeExists in interface org.osgi.service.prefs.Preferences
      Throws:
      org.osgi.service.prefs.BackingStoreException
      See Also:
      • Preferences.nodeExists(java.lang.String)
    • removeNode

      public void removeNode() throws org.osgi.service.prefs.BackingStoreException
      Specified by:
      removeNode in interface org.osgi.service.prefs.Preferences
      Throws:
      org.osgi.service.prefs.BackingStoreException
      See Also:
      • Preferences.removeNode()
    • safelyRemoveNode

      protected void safelyRemoveNode()
      Safely remove a node by resetting all properties and calling this method on all children recursively.
    • removeChild

      protected void removeChild(PreferencesImpl child)
    • name

      public String name()
      Specified by:
      name in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.name()
    • absolutePath

      public String absolutePath()
      Specified by:
      absolutePath in interface org.osgi.service.prefs.Preferences
      See Also:
      • Preferences.absolutePath()
    • flush

      public void flush() throws org.osgi.service.prefs.BackingStoreException
      Specified by:
      flush in interface org.osgi.service.prefs.Preferences
      Throws:
      org.osgi.service.prefs.BackingStoreException
      See Also:
      • Preferences.flush()
    • sync

      public void sync() throws org.osgi.service.prefs.BackingStoreException
      Specified by:
      sync in interface org.osgi.service.prefs.Preferences
      Throws:
      org.osgi.service.prefs.BackingStoreException
      See Also:
      • Preferences.sync()
    • update

      public void update(PreferencesImpl impl)
      Update from the preferences impl.
      Parameters:
      impl -
    • applyChanges

      public void applyChanges(PreferencesImpl prefs)
      Apply the changes done to the passed preferences object.
      Parameters:
      prefs -