Class AbstractPreferencesService

java.lang.Object
rs.baselib.prefs.AbstractPreferencesService
All Implemented Interfaces:
IPreferencesService
Direct Known Subclasses:
PreferencesService

public abstract class AbstractPreferencesService
extends java.lang.Object
implements IPreferencesService
Common functionality of a preferences service. The service organizes all preferences in this scheme:
    /@application1/@USER   - user preferences of application 1
    /@application1/@SYSTEM - system preferences of application 1
    /@application2/@USER   - user preferences of application 2
    /@application2/@SYSTEM - system preferences of application 2
 
Author:
ralph
  • Constructor Details

  • Method Details

    • createRootNode

      protected abstract IPreferences createRootNode()
      Creates the root node.
      Returns:
      the root node for the service
    • getApplicationPreferences

      protected IPreferences getApplicationPreferences​(java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Returns the application preferences.
      Parameters:
      applicationName - name of application
      Returns:
      the root node for this application
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • createReadWriteLock

      protected java.util.concurrent.locks.ReadWriteLock createReadWriteLock()
      Creates a new ReadWriteLock.
      Returns:
      a new ReentrantReadWriteLock
    • getReadLock

      public java.util.concurrent.locks.Lock getReadLock​(IPreferences node)
      Returns the read lock object for the given node.
      Specified by:
      getReadLock in interface IPreferencesService
      Parameters:
      node - the node that requires a read lock
      Returns:
      the responsible Lock object
    • getWriteLock

      public java.util.concurrent.locks.Lock getWriteLock​(IPreferences node)
      Returns the write lock object for the given node.
      Specified by:
      getWriteLock in interface IPreferencesService
      Parameters:
      node - the node that requires a write lock
      Returns:
      the responsible Lock object
    • getReadWriteLock

      protected java.util.concurrent.locks.ReadWriteLock getReadWriteLock​(IPreferences node)
      Returns the correct lock for the given node.
      Parameters:
      node - node to get the lock for
      Returns:
      the ReadWriteLock
    • getLockNode

      protected IPreferences getLockNode​(IPreferences node)
      Returns the node where locks will be placed upon.
      Parameters:
      node - the node where a lock is required
      Returns:
      the node that needs to be locked
    • loadUserPreferences

      protected abstract void loadUserPreferences​(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Loads the user preferences into the given node.
      Parameters:
      node - node that shall be populated
      applicationName - name of application to be loaded
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • loadSystemPreferences

      protected abstract void loadSystemPreferences​(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Loads the system preferences into the given node.
      Parameters:
      node - node that shall be populated
      applicationName - name of application to be loaded
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • flushUserPreferences

      protected abstract void flushUserPreferences​(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Flushes the user preferences from the given node.
      Parameters:
      node - node that shall be flushed
      applicationName - name of application to be flushed
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • flushSystemPreferences

      protected abstract void flushSystemPreferences​(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Flushes the system preferences from the given node.
      Parameters:
      node - node that shall be flushed
      applicationName - name of application to be flushed
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • getUserPreferences

      public IPreferences getUserPreferences​(java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Returns the user preferences for the given application.
      Specified by:
      getUserPreferences in interface IPreferencesService
      Parameters:
      applicationName - name of application
      Returns:
      the preferences object
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • getSystemPreferences

      public IPreferences getSystemPreferences​(java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Returns the system preferences for the given application.
      Specified by:
      getSystemPreferences in interface IPreferencesService
      Parameters:
      applicationName - name of application
      Returns:
      the preferences object
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • checkNodeName

      protected static void checkNodeName​(java.lang.String s)
      Checks the name of the node to be correct. A node name must not contain whitespaces or special characters other than '@', '-' or '-' or '.'.
      Parameters:
      s - string to be checked
    • nodeChanged

      public void nodeChanged​(IPreferences node)
      A node changed. Schedules a flush.
      Parameters:
      node - the node that changed
    • flush

      public void flush​(IPreferences node) throws java.util.prefs.BackingStoreException
      Flushes any changes made in this node. The method does not return before the flush has been completed.
      Specified by:
      flush in interface IPreferencesService
      Parameters:
      node - the node to be flushed
      Throws:
      java.util.prefs.BackingStoreException - when there has been a communication problem with the backing store.
    • getApplicationNode

      protected IPreferences getApplicationNode​(IPreferences node)
      Returns the application node rom the given node
      Parameters:
      node - child node
      Returns:
      the application node
    • getApplicationName

      protected java.lang.String getApplicationName​(IPreferences node)
      Returns the application name of the given node.
      Parameters:
      node - any child node
      Returns:
      the application name this node belongs to
    • sync

      public void sync​(IPreferences node) throws java.util.prefs.BackingStoreException
      Wait for any modifications to be flushed. The method does not return before the next flush has been completed (in case modifications are pending).
      Specified by:
      sync in interface IPreferencesService
      Parameters:
      node - the node to be flushed
      Throws:
      java.util.prefs.BackingStoreException - when there has been a communication problem with the backing store.