Class AbstractPreferencesService

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

public abstract class AbstractPreferencesService extends 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

    • AbstractPreferencesService

      public AbstractPreferencesService()
      Constructor.
  • Method Details

    • createRootNode

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

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

      protected ReadWriteLock createReadWriteLock()
      Creates a new ReadWriteLock.
      Returns:
      a new ReentrantReadWriteLock
    • getReadLock

      public 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 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 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, String applicationName) throws BackingStoreException
      Loads the user preferences into the given node.
      Parameters:
      node - node that shall be populated
      applicationName - name of application to be loaded
      Throws:
      BackingStoreException - when the storage fails
    • loadSystemPreferences

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

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

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

      public IPreferences getUserPreferences(String applicationName) throws 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:
      BackingStoreException - when the storage fails
    • getSystemPreferences

      public IPreferences getSystemPreferences(String applicationName) throws 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:
      BackingStoreException - when the storage fails
    • checkNodeName

      protected static void checkNodeName(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 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:
      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 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 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:
      BackingStoreException - when there has been a communication problem with the backing store.