org.pf.settings.impl
Class GenericSettingsImpl

java.lang.Object
  extended by org.pf.settings.impl.GenericSettingsImpl
All Implemented Interfaces:
CaseSensitivity, ReadOnlySettings, Settings
Direct Known Subclasses:
MultiValueSettingsImpl, SettingsImpl

public abstract class GenericSettingsImpl
extends java.lang.Object
implements Settings, CaseSensitivity

Generic implementation the Settings interface.

Version:
1.1
Author:
Manfred Duchrow

Field Summary
static java.lang.String DEFAULT_CATEGORY_NAME
          The name of the default category (i.e."") which is also representing null as value for category.
 
Constructor Summary
GenericSettingsImpl()
          Initialize the new instance with default values.
GenericSettingsImpl(java.lang.String aName)
          Create a new instance with the specified name.
 
Method Summary
 void defaultSettings(ReadOnlySettings newValue)
           
 boolean getCaseSensitive()
          Returns true, if the search for category and key names is case sensitive.
 java.lang.String[] getCategoryNames()
          Returns an array of all currently known categories.
 ReadOnlySettings getDefaults()
          Gets the defaults that are looked up, if a setting can't be found in the main settings object.
 java.lang.String[] getKeyNamesOf(java.lang.String categoryName)
          Returns all currently known key names in the category with the specified name.
 java.lang.String[] getKeyNamesOfDefaultCategory()
          Returns all currently known key names in the default category.
 java.lang.String getName()
          Returns the name of the settings object as a whole.
 java.lang.String getSettingsNameOf(java.lang.String keyName)
          Returns the name of the name of the settings where the specified key is found in the default category.
 java.lang.String getSettingsNameOf(java.lang.String categoryName, java.lang.String keyName)
          Returns the name of the name of the settings where the specified category and key are found.
 java.lang.String getValueOf(java.lang.String keyName)
          Returns the value of keyName in the default category.
 java.lang.String getValueOf(java.lang.String categoryName, java.lang.String keyName)
          Returns the value of keyName in the specified category.
 void removeCategory(java.lang.String categoryName)
          Removes the category with the specified name and all its key/value pairs.
 void removeDefaultCategory()
          Removes the default category and all its key/value pairs.
 void removeKey(java.lang.String keyName)
          Removes the key and its associated value from the default category.
 void removeKey(java.lang.String categoryName, java.lang.String keyName)
          Removes the key and its associated value from the specified category.
 void setCaseSensitive(boolean isCaseSensitive)
          Sets whether or not the internal search for category names and key names must be case sensitive.
 void setDefaults(ReadOnlySettings defaults)
          Sets defaults that must be looked up, if a setting can't be found in the main settings object.
 void setName(java.lang.String aName)
          Sets the name of the settings object as a whole.
 void setValueOf(java.lang.String keyName, java.lang.String value)
          Sets the value of given key in the default category.
 void setValueOf(java.lang.String categoryName, java.lang.String keyName, java.lang.String value)
          Sets the value of given key in the specified category.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CATEGORY_NAME

public static final java.lang.String DEFAULT_CATEGORY_NAME
The name of the default category (i.e."") which is also representing null as value for category.

See Also:
Constant Field Values
Constructor Detail

GenericSettingsImpl

public GenericSettingsImpl()
Initialize the new instance with default values.


GenericSettingsImpl

public GenericSettingsImpl(java.lang.String aName)
Create a new instance with the specified name.

Method Detail

defaultSettings

public void defaultSettings(ReadOnlySettings newValue)

getValueOf

public java.lang.String getValueOf(java.lang.String categoryName,
                                   java.lang.String keyName)
Returns the value of keyName in the specified category.

Specified by:
getValueOf in interface ReadOnlySettings
Parameters:
categoryName - The name of the category (null means the default category)
keyName - The name of a key inside the category
Returns:
The associated value or null if either the category or the key could not be found

getValueOf

public java.lang.String getValueOf(java.lang.String keyName)
Returns the value of keyName in the default category.

Specified by:
getValueOf in interface ReadOnlySettings
Parameters:
keyName - The name of a key inside the default category
Returns:
The associated value or null if the key could not be found

setValueOf

public void setValueOf(java.lang.String categoryName,
                       java.lang.String keyName,
                       java.lang.String value)
Sets the value of given key in the specified category. If the category does not yet exist, it will be created. If the key does not yet exist, it will be created otherwise the old value will be replaced.

Specified by:
setValueOf in interface Settings
Parameters:
categoryName - The name of the category (null means the default category)
keyName - The name of the key the value should be assigned to.
value - The value to be assigned to the key

setValueOf

public void setValueOf(java.lang.String keyName,
                       java.lang.String value)
Sets the value of given key in the default category. If the default category does not yet exist, it will be created. If the key does not yet exist, it will be created otherwise the old value will be replaced.

Specified by:
setValueOf in interface Settings
Parameters:
keyName - The name of the key the value should be assigned to.
value - The value to be assigned to the key

getCategoryNames

public java.lang.String[] getCategoryNames()
Returns an array of all currently known categories. An empty string is the name for the default category!

Specified by:
getCategoryNames in interface ReadOnlySettings

getKeyNamesOf

public java.lang.String[] getKeyNamesOf(java.lang.String categoryName)
Returns all currently known key names in the category with the specified name. If the category name is null or an empty string, the default category's keys will be returned.

Specified by:
getKeyNamesOf in interface ReadOnlySettings
Parameters:
categoryName - The name of the category the keys are wanted from

getKeyNamesOfDefaultCategory

public java.lang.String[] getKeyNamesOfDefaultCategory()
Returns all currently known key names in the default category.

Specified by:
getKeyNamesOfDefaultCategory in interface ReadOnlySettings

removeKey

public void removeKey(java.lang.String categoryName,
                      java.lang.String keyName)
Removes the key and its associated value from the specified category. If the categoryName is null or an empty string the key/value pair will be removed from the default category.
This method will never remove anything from the default settings!

Specified by:
removeKey in interface Settings
Parameters:
categoryName - The name of the category the key should be removed from
keyName - The name of the key to remove

removeKey

public void removeKey(java.lang.String keyName)
Removes the key and its associated value from the default category.
This method will never remove anything from the default settings!

Specified by:
removeKey in interface Settings
Parameters:
keyName - The name of the key to remove

removeCategory

public void removeCategory(java.lang.String categoryName)
Removes the category with the specified name and all its key/value pairs. If the categoryName is null or an empty string the default category will be removed.
This method will never remove anything from the default settings!

Specified by:
removeCategory in interface Settings
Parameters:
categoryName - The name of the category to removed

removeDefaultCategory

public void removeDefaultCategory()
Removes the default category and all its key/value pairs.
This method will never remove anything from the default settings!

Specified by:
removeDefaultCategory in interface Settings

getSettingsNameOf

public java.lang.String getSettingsNameOf(java.lang.String categoryName,
                                          java.lang.String keyName)
Returns the name of the name of the settings where the specified category and key are found. That is a lookup in this settings object and then, if not found, in its defaults and so on.

Specified by:
getSettingsNameOf in interface ReadOnlySettings
Parameters:
categoryName - The name of the category (null means the default category)
keyName - The name of a key inside the category
Returns:
The name of the settings object or null

getSettingsNameOf

public java.lang.String getSettingsNameOf(java.lang.String keyName)
Returns the name of the name of the settings where the specified key is found in the default category. That is a lookup in this settings object and then, if not found, in its defaults and so on.

Specified by:
getSettingsNameOf in interface ReadOnlySettings
Parameters:
keyName - The name of a key inside the default category
Returns:
The name of the settings object or null

getName

public java.lang.String getName()
Returns the name of the settings object as a whole. This might be a simple name or a resource locator or a filename. However, naming a setting is obtional and therefore this method can also return null.

Specified by:
getName in interface ReadOnlySettings

setName

public void setName(java.lang.String aName)
Sets the name of the settings object as a whole. This might be a simple name or a resource locator or a filename.

Specified by:
setName in interface ReadOnlySettings

getCaseSensitive

public boolean getCaseSensitive()
Returns true, if the search for category and key names is case sensitive.

Specified by:
getCaseSensitive in interface CaseSensitivity

setCaseSensitive

public void setCaseSensitive(boolean isCaseSensitive)
Sets whether or not the internal search for category names and key names must be case sensitive.
If there are default settings set in this thettings their case-sensitivity will be changed accordingly.

Specified by:
setCaseSensitive in interface CaseSensitivity
Parameters:
isCaseSensitive - The new value that determins if names are compared case sensitive or not

getDefaults

public ReadOnlySettings getDefaults()
Gets the defaults that are looked up, if a setting can't be found in the main settings object.

Specified by:
getDefaults in interface ReadOnlySettings
Returns:
A settings object with default values or null

setDefaults

public void setDefaults(ReadOnlySettings defaults)
Sets defaults that must be looked up, if a setting can't be found in the main settings object.

Specified by:
setDefaults in interface ReadOnlySettings
Parameters:
defaults - A settings object with default values or null