Package rs.baselib.prefs
Class AbstractPreferencesService
java.lang.Object
rs.baselib.prefs.AbstractPreferencesService
- All Implemented Interfaces:
IPreferencesService
- Direct Known Subclasses:
PreferencesService
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
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
A thread running all flushs. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static void
Checks the name of the node to be correct.protected ReadWriteLock
Creates a newReadWriteLock
.protected abstract IPreferences
Creates the root node.void
flush
(IPreferences node) Flushes any changes made in this node.protected abstract void
flushSystemPreferences
(IPreferences node, String applicationName) Flushes the system preferences from the given node.protected abstract void
flushUserPreferences
(IPreferences node, String applicationName) Flushes the user preferences from the given node.protected String
Returns the application name of the given node.protected IPreferences
Returns the application node rom the given nodeprotected IPreferences
getApplicationPreferences
(String applicationName) Returns the application preferences.protected IPreferences
getLockNode
(IPreferences node) Returns the node where locks will be placed upon.getReadLock
(IPreferences node) Returns the read lock object for the given node.protected ReadWriteLock
getReadWriteLock
(IPreferences node) Returns the correct lock for the given node.getSystemPreferences
(String applicationName) Returns the system preferences for the given application.getUserPreferences
(String applicationName) Returns the user preferences for the given application.getWriteLock
(IPreferences node) Returns the write lock object for the given node.protected abstract void
loadSystemPreferences
(IPreferences node, String applicationName) Loads the system preferences into the given node.protected abstract void
loadUserPreferences
(IPreferences node, String applicationName) Loads the user preferences into the given node.void
nodeChanged
(IPreferences node) A node changed.void
sync
(IPreferences node) Wait for any modifications to be flushed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface rs.baselib.prefs.IPreferencesService
getSystemPreferencesHome, getUserPreferencesHome
-
Constructor Details
-
AbstractPreferencesService
public AbstractPreferencesService()Constructor.
-
-
Method Details
-
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
Creates a newReadWriteLock
.- Returns:
- a new
ReentrantReadWriteLock
-
getReadLock
Returns the read lock object for the given node.- Specified by:
getReadLock
in interfaceIPreferencesService
- Parameters:
node
- the node that requires a read lock- Returns:
- the responsible
Lock
object
-
getWriteLock
Returns the write lock object for the given node.- Specified by:
getWriteLock
in interfaceIPreferencesService
- Parameters:
node
- the node that requires a write lock- Returns:
- the responsible
Lock
object
-
getReadWriteLock
Returns the correct lock for the given node.- Parameters:
node
- node to get the lock for- Returns:
- the
ReadWriteLock
-
getLockNode
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 populatedapplicationName
- 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 populatedapplicationName
- 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 flushedapplicationName
- 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 flushedapplicationName
- name of application to be flushed- Throws:
BackingStoreException
- when the storage fails
-
getUserPreferences
Returns the user preferences for the given application.- Specified by:
getUserPreferences
in interfaceIPreferencesService
- Parameters:
applicationName
- name of application- Returns:
- the preferences object
- Throws:
BackingStoreException
- when the storage fails
-
getSystemPreferences
Returns the system preferences for the given application.- Specified by:
getSystemPreferences
in interfaceIPreferencesService
- Parameters:
applicationName
- name of application- Returns:
- the preferences object
- Throws:
BackingStoreException
- when the storage fails
-
checkNodeName
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
A node changed. Schedules a flush.- Parameters:
node
- the node that changed
-
flush
Flushes any changes made in this node. The method does not return before the flush has been completed.- Specified by:
flush
in interfaceIPreferencesService
- Parameters:
node
- the node to be flushed- Throws:
BackingStoreException
- when there has been a communication problem with the backing store.
-
getApplicationNode
Returns the application node rom the given node- Parameters:
node
- child node- Returns:
- the application node
-
getApplicationName
Returns the application name of the given node.- Parameters:
node
- any child node- Returns:
- the application name this node belongs to
-
sync
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 interfaceIPreferencesService
- Parameters:
node
- the node to be flushed- Throws:
BackingStoreException
- when there has been a communication problem with the backing store.
-