net.sourceforge.java.feednread.backend.configuration
Class ConfigurationStore

java.lang.Object
  extended bynet.sourceforge.java.feednread.backend.configuration.ConfigurationStore
All Implemented Interfaces:
IPersistentPreferenceStore, IPreferenceStore

public class ConfigurationStore
extends Object
implements IPersistentPreferenceStore

ConfigurationStore is an IPersistentPreferenceStore that allows arbitrary persistent mediums and/or persistence strategies by decoupling the IPersistentPreferenceStore from the underlying persistence layer. It uses the IConfigurationPersistenceEngine interface to retrieve/persist the configuration data.

XMLConfigurationPersistenceEngine represents a default implementation of a xml based persistence layer.

Author:
Sebastian Machhausen

Field Summary
private  IConfigurationPersistenceEngine configPersistence
           
private  Map configuration
           
private  IConfigurationPersistenceEngine defaultConfigPersistence
           
private  Map defaults
           
private  ListenerList listeners
           
private  boolean modified
           
 
Fields inherited from interface org.eclipse.jface.preference.IPreferenceStore
BOOLEAN_DEFAULT_DEFAULT, DOUBLE_DEFAULT_DEFAULT, FALSE, FLOAT_DEFAULT_DEFAULT, INT_DEFAULT_DEFAULT, LONG_DEFAULT_DEFAULT, STRING_DEFAULT_DEFAULT, TRUE
 
Constructor Summary
ConfigurationStore(IConfigurationPersistenceEngine configPersistence, IConfigurationPersistenceEngine defaultConfigPersistence)
           Creates a new ConfigurationStore instance using the specified IConfigurationPersistenceEngines for retrieval/storage of the configuration and default settings.
 
Method Summary
 void addPropertyChangeListener(IPropertyChangeListener listener)
           Adds the specified IPropertyChangeListener to the list of registered listeners.
 boolean contains(String key)
           Returns true if the underlying configuration contains a value for the denoted key.
 void firePropertyChangeEvent(String key, Object oldValue, Object newValue)
           Fires a property change event corresponding to a change to the current value of the preference with the given key.
private  boolean getBoolean(Map data, String key)
           Helper function: gets a boolean value for a given key.
 boolean getBoolean(String key)
           Gets the boolean value for the specified key.
 boolean getDefaultBoolean(String key)
           Gets the default boolean value for the specified key.
 double getDefaultDouble(String key)
           Gets the default double value for the specified key.
 float getDefaultFloat(String key)
           Gets the default float value for the specified key.
 int getDefaultInt(String key)
           Gets the default int value for the specified key.
 long getDefaultLong(String key)
           Gets the default long value for the specified key.
 String getDefaultString(String key)
           Gets the default String value for the specified key.
private  double getDouble(Map data, String key)
           Helper function: gets a double value for a given key.
 double getDouble(String key)
           Gets the double value for the specified key.
private  float getFloat(Map data, String key)
           Helper function: gets a float value for a given key.
 float getFloat(String key)
           Gets the float value for the specified key.
private  int getInt(Map data, String key)
           Helper function: gets an int value for a given key.
 int getInt(String key)
           Gets the int value for the specified key.
private  long getLong(Map data, String key)
           Helper function: gets a long value for a given key.
 long getLong(String key)
           Gets the long value for the specified key.
private  String getString(Map data, String key)
           Helper function: gets a String value for a given key.
 String getString(String key)
           Gets the String value for the specified key.
 boolean isDefault(String key)
           Returns true if the specified key is currently set to its default value, i.e. has not been modified.
 boolean needsSaving()
           Returns true if this ConfigurationStore needs to be saved due to a modified configuration.
 void putValue(String key, String value)
           Sets the value of the setting denoted by the given key to the given value without sending a property change.
 void removePropertyChangeListener(IPropertyChangeListener listener)
           Removes the specified IPropertyChangeListener from the list of registered listeners.
 void save()
           Saves the configuration.
 void setDefault(String key, boolean value)
           Sets the default value for the specified key.
 void setDefault(String key, double value)
           Sets the default value for the specified key.
 void setDefault(String key, float value)
           Sets the default value for the specified key.
 void setDefault(String key, int value)
           Sets the default value for the specified key.
 void setDefault(String key, long value)
           Sets the default value for the specified key.
 void setDefault(String key, String value)
           Sets the default value for the specified key.
 void setToDefault(String key)
           Sets the value denoted by the specified key back to its default value.
private  void setValue(Map data, String key, boolean value)
           Helper method: Sets a boolean value for a given key.
private  void setValue(Map data, String key, double value)
           Helper method: Sets a double value for a given key.
private  void setValue(Map data, String key, float value)
           Helper method: Sets a float value for a given key.
private  void setValue(Map data, String key, int value)
           Helper method: Sets an int value for a given key.
private  void setValue(Map data, String key, long value)
           Helper method: Sets a long value for a given key.
private  void setValue(Map data, String key, String value)
           Helper method: Sets a String value for a given key.
 void setValue(String key, boolean value)
           Sets the value for the specified key.
 void setValue(String key, double value)
           Sets the value for the specified key.
 void setValue(String key, float value)
           Sets the value for the specified key.
 void setValue(String key, int value)
           Sets the value for the specified key.
 void setValue(String key, long value)
           Sets the value for the specified key.
 void setValue(String key, String value)
           Sets the value for the specified key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

private ListenerList listeners

configPersistence

private IConfigurationPersistenceEngine configPersistence

defaultConfigPersistence

private IConfigurationPersistenceEngine defaultConfigPersistence

configuration

private Map configuration

defaults

private Map defaults

modified

private boolean modified
Constructor Detail

ConfigurationStore

public ConfigurationStore(IConfigurationPersistenceEngine configPersistence,
                          IConfigurationPersistenceEngine defaultConfigPersistence)
                   throws PersistenceException

Creates a new ConfigurationStore instance using the specified IConfigurationPersistenceEngines for retrieval/storage of the configuration and default settings.

Parameters:
configPersistence - the PersistenceEngine responsible for retrieving/storing the configuration data
defaultConfigPersistence - the PersistenceEngine responsible for retrieving/storing the default settings
Throws:
PersistenceException - if an error occured while retreiving/storing the configuration data through the specified PersistenceEngine instances
Method Detail

save

public void save()
          throws IOException

Saves the configuration. By default calls IConfigurationPersistenceEngine.persist() on both, the configuration itself and the default settings.

Specified by:
save in interface IPersistentPreferenceStore
Throws:
IOException
See Also:
IPersistentPreferenceStore.save()

addPropertyChangeListener

public void addPropertyChangeListener(IPropertyChangeListener listener)

Adds the specified IPropertyChangeListener to the list of registered listeners. These listeners are to be informed when the current value of a preference changes.

Specified by:
addPropertyChangeListener in interface IPreferenceStore
Parameters:
listener - the IPropertyChangeListener to add
See Also:
IPreferenceStore.addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(IPropertyChangeListener listener)

Removes the specified IPropertyChangeListener from the list of registered listeners.

Specified by:
removePropertyChangeListener in interface IPreferenceStore
Parameters:
listener - the IPropertyChangeListener to removed
See Also:
IPreferenceStore.removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)

contains

public boolean contains(String key)

Returns true if the underlying configuration contains a value for the denoted key.

Specified by:
contains in interface IPreferenceStore
Parameters:
key - the key to test for existence
Returns:
true if the underlying configuration contains a value for the key denoted by the specified name; false otherwise
See Also:
IPreferenceStore.contains(java.lang.String)

firePropertyChangeEvent

public void firePropertyChangeEvent(String key,
                                    Object oldValue,
                                    Object newValue)

Fires a property change event corresponding to a change to the current value of the preference with the given key. This method is provided on this interface to simplify the implementation of decorators. There is normally no need to call this method since setValue and setToDefault report such events in due course. Implementations should funnel all preference changes through this method.

Specified by:
firePropertyChangeEvent in interface IPreferenceStore
Parameters:
key - the key identifying the setting to be used as the property in the event object
oldValue - the old value
newValue - the new value
See Also:
IPreferenceStore.firePropertyChangeEvent(java.lang.String, java.lang.Object, java.lang.Object)

getBoolean

public boolean getBoolean(String key)

Gets the boolean value for the specified key.

Specified by:
getBoolean in interface IPreferenceStore
Parameters:
key - the key to get the boolean value for
Returns:
the boolean value for the specified key
See Also:
IPreferenceStore.getBoolean(java.lang.String)

getDouble

public double getDouble(String key)

Gets the double value for the specified key.

Specified by:
getDouble in interface IPreferenceStore
Parameters:
key - the key to get the double value for
Returns:
the double value for the specified key
See Also:
IPreferenceStore.getDouble(java.lang.String)

getFloat

public float getFloat(String key)

Gets the float value for the specified key.

Specified by:
getFloat in interface IPreferenceStore
Parameters:
key - the key to get the float value for
Returns:
the float value for the specified key
See Also:
IPreferenceStore.getFloat(java.lang.String)

getInt

public int getInt(String key)

Gets the int value for the specified key.

Specified by:
getInt in interface IPreferenceStore
Parameters:
key - the key to get the int value for
Returns:
the int value for the specified key
See Also:
IPreferenceStore.getInt(java.lang.String)

getLong

public long getLong(String key)

Gets the long value for the specified key.

Specified by:
getLong in interface IPreferenceStore
Parameters:
key - the key to get the long value for
Returns:
the long value for the specified key
See Also:
IPreferenceStore.getLong(java.lang.String)

getString

public String getString(String key)

Gets the String value for the specified key.

Specified by:
getString in interface IPreferenceStore
Parameters:
key - the key to get the String value for
Returns:
the String value for the specified key
See Also:
IPreferenceStore.getString(java.lang.String)

getDefaultBoolean

public boolean getDefaultBoolean(String key)

Gets the default boolean value for the specified key.

Specified by:
getDefaultBoolean in interface IPreferenceStore
Parameters:
key - the key to get the default boolean value for
Returns:
the default boolean value for the specified key
See Also:
IPreferenceStore.getDefaultBoolean(java.lang.String)

getDefaultDouble

public double getDefaultDouble(String key)

Gets the default double value for the specified key.

Specified by:
getDefaultDouble in interface IPreferenceStore
Parameters:
key - the key to get the default double value for
Returns:
the default double value for the specified key
See Also:
IPreferenceStore.getDefaultDouble(java.lang.String)

getDefaultFloat

public float getDefaultFloat(String key)

Gets the default float value for the specified key.

Specified by:
getDefaultFloat in interface IPreferenceStore
Parameters:
key - the key to get the default float value for
Returns:
the default float value for the specified key
See Also:
IPreferenceStore.getDefaultFloat(java.lang.String)

getDefaultInt

public int getDefaultInt(String key)

Gets the default int value for the specified key.

Specified by:
getDefaultInt in interface IPreferenceStore
Parameters:
key - the key to get the default int value for
Returns:
the default int value for the specified key
See Also:
IPreferenceStore.getDefaultInt(java.lang.String)

getDefaultLong

public long getDefaultLong(String key)

Gets the default long value for the specified key.

Specified by:
getDefaultLong in interface IPreferenceStore
Parameters:
key - the key to get the default long value for
Returns:
the default long value for the specified key
See Also:
IPreferenceStore.getDefaultLong(java.lang.String)

getDefaultString

public String getDefaultString(String key)

Gets the default String value for the specified key.

Specified by:
getDefaultString in interface IPreferenceStore
Parameters:
key - the key to get the default String value for
Returns:
the default String value for the specified key
See Also:
IPreferenceStore.getDefaultString(java.lang.String)

isDefault

public boolean isDefault(String key)

Returns true if the specified key is currently set to its default value, i.e. has not been modified.

Specified by:
isDefault in interface IPreferenceStore
Parameters:
key - the key to test
Returns:
true if the specified key is currently set to its default value, i.e. has not been modified; false otherwise
See Also:
IPreferenceStore.isDefault(java.lang.String)

needsSaving

public boolean needsSaving()

Returns true if this ConfigurationStore needs to be saved due to a modified configuration.

Specified by:
needsSaving in interface IPreferenceStore
Returns:
true if this ConfigurationStore needs to be saved due to a modified configuration; false otherwise
See Also:
IPreferenceStore.needsSaving()

putValue

public void putValue(String key,
                     String value)

Sets the value of the setting denoted by the given key to the given value without sending a property change. This method does not fire a property change event and should only be used for setting internal preferences that are not meant to be processed by listeners. Normal clients should instead call #setValue.

Specified by:
putValue in interface IPreferenceStore
Parameters:
key - the key identifying the setting to be set
value - the new value to set
See Also:
IPreferenceStore.putValue(java.lang.String, java.lang.String)

setDefault

public void setDefault(String key,
                       double value)

Sets the default value for the specified key.

Specified by:
setDefault in interface IPreferenceStore
Parameters:
key - the key to set the default value for
value - the value to set as new default value
See Also:
IPreferenceStore.setDefault(java.lang.String, double)

setDefault

public void setDefault(String key,
                       float value)

Sets the default value for the specified key.

Specified by:
setDefault in interface IPreferenceStore
Parameters:
key - the key to set the default value for
value - the value to set as new default value
See Also:
IPreferenceStore.setDefault(java.lang.String, float)

setDefault

public void setDefault(String key,
                       int value)

Sets the default value for the specified key.

Specified by:
setDefault in interface IPreferenceStore
Parameters:
key - the key to set the default value for
value - the value to set as new default value
See Also:
IPreferenceStore.setDefault(java.lang.String, int)

setDefault

public void setDefault(String key,
                       long value)

Sets the default value for the specified key.

Specified by:
setDefault in interface IPreferenceStore
Parameters:
key - the key to set the default value for
value - the value to set as new default value
See Also:
IPreferenceStore.setDefault(java.lang.String, long)

setDefault

public void setDefault(String key,
                       String value)

Sets the default value for the specified key.

Specified by:
setDefault in interface IPreferenceStore
Parameters:
key - the key to set the default value for
value - the value to set as new default value
See Also:
IPreferenceStore.setDefault(java.lang.String, java.lang.String)

setDefault

public void setDefault(String key,
                       boolean value)

Sets the default value for the specified key.

Specified by:
setDefault in interface IPreferenceStore
Parameters:
key - the key to set the default value for
value - the value to set as new default value
See Also:
IPreferenceStore.setDefault(java.lang.String, boolean)

setToDefault

public void setToDefault(String key)

Sets the value denoted by the specified key back to its default value.

Specified by:
setToDefault in interface IPreferenceStore
Parameters:
key - the key whose value to be set back to default
See Also:
IPreferenceStore.setToDefault(java.lang.String)

setValue

public void setValue(String key,
                     double value)

Sets the value for the specified key.

Specified by:
setValue in interface IPreferenceStore
Parameters:
key - the key to set the value for
value - the value to set
See Also:
IPreferenceStore.setValue(java.lang.String, double)

setValue

public void setValue(String key,
                     float value)

Sets the value for the specified key.

Specified by:
setValue in interface IPreferenceStore
Parameters:
key - the key to set the value for
value - the value to set
See Also:
IPreferenceStore.setValue(java.lang.String, float)

setValue

public void setValue(String key,
                     int value)

Sets the value for the specified key.

Specified by:
setValue in interface IPreferenceStore
Parameters:
key - the key to set the value for
value - the value to set
See Also:
IPreferenceStore.setValue(java.lang.String, int)

setValue

public void setValue(String key,
                     long value)

Sets the value for the specified key.

Specified by:
setValue in interface IPreferenceStore
Parameters:
key - the key to set the value for
value - the value to set
See Also:
IPreferenceStore.setValue(java.lang.String, long)

setValue

public void setValue(String key,
                     String value)

Sets the value for the specified key.

Specified by:
setValue in interface IPreferenceStore
Parameters:
key - the key to set the value for
value - the value to set
See Also:
IPreferenceStore.setValue(java.lang.String, java.lang.String)

setValue

public void setValue(String key,
                     boolean value)

Sets the value for the specified key.

Specified by:
setValue in interface IPreferenceStore
Parameters:
key - the key to set the value for
value - the value to set
See Also:
IPreferenceStore.setValue(java.lang.String, boolean)

getBoolean

private boolean getBoolean(Map data,
                           String key)

Helper function: gets a boolean value for a given key.

Parameters:
data - the Map holding the value
key - the key to access the value for
Returns:
the boolean value

getDouble

private double getDouble(Map data,
                         String key)

Helper function: gets a double value for a given key.

Parameters:
data - the Map holding the value
key - the key to access the value for
Returns:
the double value

getFloat

private float getFloat(Map data,
                       String key)

Helper function: gets a float value for a given key.

Parameters:
data - the Map holding the value
key - the key to access the value for
Returns:
the float value

getInt

private int getInt(Map data,
                   String key)

Helper function: gets an int value for a given key.

Parameters:
data - the Map holding the value
key - the key to access the value for
Returns:
the int value

getLong

private long getLong(Map data,
                     String key)

Helper function: gets a long value for a given key.

Parameters:
data - the Map holding the value
key - the key to access the value for
Returns:
the long value

getString

private String getString(Map data,
                         String key)

Helper function: gets a String value for a given key.

Parameters:
data - the Map holding the value
key - the key to access the value for
Returns:
the String value

setValue

private void setValue(Map data,
                      String key,
                      double value)

Helper method: Sets a double value for a given key.

Parameters:
data - the Map to store the value in
key - the key to set the value for
value - the updated value

setValue

private void setValue(Map data,
                      String key,
                      float value)

Helper method: Sets a float value for a given key.

Parameters:
data - the Map to store the value in
key - the key to set the value for
value - the updated value

setValue

private void setValue(Map data,
                      String key,
                      int value)

Helper method: Sets an int value for a given key.

Parameters:
data - the Map to store the value in
key - the key to set the value for
value - the updated value

setValue

private void setValue(Map data,
                      String key,
                      long value)

Helper method: Sets a long value for a given key.

Parameters:
data - the Map to store the value in
key - the key to set the value for
value - the updated value

setValue

private void setValue(Map data,
                      String key,
                      boolean value)

Helper method: Sets a boolean value for a given key.

Parameters:
data - the Map to store the value in
key - the key to set the value for
value - the updated value

setValue

private void setValue(Map data,
                      String key,
                      String value)

Helper method: Sets a String value for a given key.

Parameters:
data - the Map to store the value in
key - the key to set the value for
value - the updated value