Package rs.baselib.prefs
Class PreferencesService
java.lang.Object
rs.baselib.prefs.AbstractPreferencesService
rs.baselib.prefs.PreferencesService
- All Implemented Interfaces:
IPreferencesService
The default implementation of
IPreferencesService
.
System preferences are stored in a common location depending on the OS. User
preferences are stored in a hidden directory of the user's home directory.- Author:
- ralph
-
Nested Class Summary
Nested classes/interfaces inherited from class rs.baselib.prefs.AbstractPreferencesService
AbstractPreferencesService.FlushingThread
-
Field Summary
Modifier and TypeFieldDescriptionstatic final IPreferencesService
The default global preference service -
Method Summary
Modifier and TypeMethodDescriptionprotected IPreferences
Creates the root node.protected void
flushSystemPreferences
(IPreferences node, String applicationName) Flushes the system preferences from the given node.protected void
flushUserPreferences
(IPreferences node, String applicationName) Flushes the user preferences from the given node.protected InputStream
Returns an input stream that can be safely read.protected OutputStream
Returns an output stream that can be written to.protected File
Returns the system home dir to store system prefs at.protected File
getSystemPreferencesFile
(String applicationName) Returns the application's preferences file of the system.getSystemPreferencesHome
(String applicationName) Returns the home directory for system preferences of the given application.protected File
Returns the home directory of the user.protected File
getUserPreferencesFile
(String applicationName) Returns the application's preferences file of the user.getUserPreferencesHome
(String applicationName) Returns the home directory for user preferences of the given application.protected void
load
(IPreferences node, InputStream in) Loads the information from the stream into the nodeprotected void
loadSystemPreferences
(IPreferences node, String applicationName) Loads the system preferences into the given node.protected void
loadUserPreferences
(IPreferences node, String applicationName) Loads the user preferences into the given node.protected void
put
(IPreferences node, String key, String value) Stores the key at the appropriate sub-node.protected void
save
(String prefix, IPreferences node, PrintWriter out) Recursively stores the given node into the writer.protected void
save
(IPreferences node, OutputStream out) Saves the node information into the streamMethods inherited from class rs.baselib.prefs.AbstractPreferencesService
checkNodeName, createReadWriteLock, flush, getApplicationName, getApplicationNode, getApplicationPreferences, getLockNode, getReadLock, getReadWriteLock, getSystemPreferences, getUserPreferences, getWriteLock, nodeChanged, sync
-
Field Details
-
INSTANCE
The default global preference service
-
-
Method Details
-
createRootNode
Creates the root node.- Specified by:
createRootNode
in classAbstractPreferencesService
- Returns:
- the root node for the service
-
loadUserPreferences
protected void loadUserPreferences(IPreferences node, String applicationName) throws BackingStoreException Loads the user preferences into the given node.- Specified by:
loadUserPreferences
in classAbstractPreferencesService
- Parameters:
node
- node that shall be populatedapplicationName
- name of application to be loaded- Throws:
BackingStoreException
- when the storage fails
-
loadSystemPreferences
protected void loadSystemPreferences(IPreferences node, String applicationName) throws BackingStoreException Loads the system preferences into the given node.- Specified by:
loadSystemPreferences
in classAbstractPreferencesService
- Parameters:
node
- node that shall be populatedapplicationName
- name of application to be loaded- Throws:
BackingStoreException
- when the storage fails
-
flushUserPreferences
protected void flushUserPreferences(IPreferences node, String applicationName) throws BackingStoreException Flushes the user preferences from the given node.- Specified by:
flushUserPreferences
in classAbstractPreferencesService
- Parameters:
node
- node that shall be flushedapplicationName
- name of application to be flushed- Throws:
BackingStoreException
- when the storage fails
-
flushSystemPreferences
protected void flushSystemPreferences(IPreferences node, String applicationName) throws BackingStoreException Flushes the system preferences from the given node.- Specified by:
flushSystemPreferences
in classAbstractPreferencesService
- Parameters:
node
- node that shall be flushedapplicationName
- name of application to be flushed- Throws:
BackingStoreException
- when the storage fails
-
getInputStream
Returns an input stream that can be safely read.- Parameters:
f
- file- Returns:
- input stream (will be empty is file does not exists or cannot be read)
- Throws:
BackingStoreException
- when the file cannot be opened
-
getOutputStream
Returns an output stream that can be written to.- Parameters:
f
- file- Returns:
- output stream (intermediate directories will be created if required)
- Throws:
BackingStoreException
- when the file cannot be opened
-
load
Loads the information from the stream into the node- Parameters:
node
- node to be filledin
- input stream- Throws:
BackingStoreException
- when the stream contains errors
-
put
Stores the key at the appropriate sub-node.- Parameters:
node
- nodekey
- path of key (including node)value
- value of key
-
save
Saves the node information into the stream- Parameters:
node
- node to be savedout
- output stream- Throws:
BackingStoreException
- when the stream produces errors
-
save
Recursively stores the given node into the writer.- Parameters:
prefix
- prefix to be used for keys (can be null)node
- node to be writtenout
- print writer- Throws:
BackingStoreException
- when a node cannot be written
-
getUserPreferencesHome
Returns the home directory for user preferences of the given application.- Parameters:
applicationName
- name of application- Returns:
- user preferences home
-
getUserHome
Returns the home directory of the user.- Returns:
- the user home dir
-
getUserPreferencesFile
Returns the application's preferences file of the user.- Parameters:
applicationName
- name of the application- Returns:
- the preferences file
-
getSystemPreferencesHome
Returns the home directory for system preferences of the given application.- Parameters:
applicationName
- name of application- Returns:
- system preferences home
-
getSystemPreferencesFile
Returns the application's preferences file of the system.- Parameters:
applicationName
- name of the application- Returns:
- the preferences file
-
getSystemHome
Returns the system home dir to store system prefs at.- Returns:
- the system home dir (usually /var or C:\Users\AllUsers)
-