org.argouml.application.configuration
Class ConfigurationHandler

java.lang.Object
  extended byorg.argouml.application.configuration.ConfigurationHandler
Direct Known Subclasses:
ConfigurationProperties

public abstract class ConfigurationHandler
extends java.lang.Object

This class provides a user configuration based upon properties. This provides an implementation-free interface to a configuration repository. Any classes which need to implement a configuration datastore must extend this class. All of the required behavioral logic for the configuration is contained within this class, as public final methods. Any storage-related logic must be handled by the extending class. These methods are abstract. This class is intimately related to Configuration.

Since:
0.9.4

Field Summary
private static org.apache.log4j.Logger _cat
           
private  boolean _changeable
          Internal flag indicating whether the configuration can be updated.
private  boolean _changed
          Internal flag indicating whether the configuration has been modified after it was loaded.
private  boolean _loaded
          Internal flag indicating whether the configuration has been loaded.
private  java.io.File _loadedFromFile
          Internal storage for the File the configuration was loaded from, otherwise null.
private  java.net.URL _loadedFromURL
          Internal storage for the URL the configuration was loaded from, otherwise null.
private static java.beans.PropertyChangeSupport _pcl
          Internal worker for property change.
 
Constructor Summary
ConfigurationHandler()
          Anonymous constructor allows configuration changes.
ConfigurationHandler(boolean changeable)
          Constructor which optionally allows configuration changes.
 
Method Summary
 void addListener(ConfigurationKey key, java.beans.PropertyChangeListener pcl)
          Adds a property change listener.Static for simplicity of use.
 void addListener(java.beans.PropertyChangeListener pcl)
          Adds a property change listener.
 boolean getBoolean(ConfigurationKey key, boolean defaultValue)
          Returns the boolean value of a configuration property.
abstract  java.lang.String getDefaultPath()
          Returns a default configuration path.
 double getDouble(ConfigurationKey key, double defaultValue)
          Returns the numeric value of a configuration property.
 int getInteger(ConfigurationKey key, int defaultValue)
          Returns the numeric value of a configuration property.
 java.lang.String getString(ConfigurationKey key, java.lang.String defaultValue)
          Returns the string value of a configuration property.
abstract  java.lang.String getValue(java.lang.String key, java.lang.String defaultValue)
          Returns the string value of a configuration property.
 boolean hasKey(ConfigurationKey key)
          Allows query for the existence of a configuration property.
 boolean isChangeable()
          Indicates whether the configuration can be saved.
 boolean isChanged()
          Indicates whether the configuration can be saved.
 boolean isLoaded()
          Indicates whether the configuration has been loaded.
 boolean load(java.io.File file)
          Load the configuration from a File.
 boolean load(java.net.URL url)
          Load the configuration from a URL.
 boolean loadDefault()
          Load the configuration from the default location.
(package private) abstract  boolean loadFile(java.io.File file)
          Internal processing to load a File.
private  void loadIfNecessary()
          Internal worker which is called prior to any getValue or setValue to ensure that the default load is done if it was not loaded previously.
(package private)  boolean loadUnspecified()
          Internal processing to load from an unspecified source.
(package private) abstract  boolean loadURL(java.net.URL url)
          Internal processing to load a URL.
 void removeListener(ConfigurationKey key, java.beans.PropertyChangeListener pcl)
          Removes a property change listener.
 void removeListener(java.beans.PropertyChangeListener pcl)
          Removes a property change listener.
 boolean save(java.io.File file)
          Save the configuration to a File.
 boolean save(java.net.URL url)
          Save the configuration to a URL.
 boolean saveDefault()
          Save the configuration to the location it was loaded from.
 boolean saveDefault(boolean force)
          Save the configuration to the location it was loaded from.
(package private) abstract  boolean saveFile(java.io.File file)
          Internal processing to save a File.
(package private)  boolean saveUnspecified()
          Internal processing to save to an unspecified source.
(package private) abstract  boolean saveURL(java.net.URL url)
          Internal processing to save a URL.
 void setBoolean(ConfigurationKey key, boolean value)
          Sets the boolean value of a configuration property.
 void setDouble(ConfigurationKey key, double value)
          Sets the numeric value of a configuration property.
 void setInteger(ConfigurationKey key, int value)
          Sets the numeric value of a configuration property.
 void setString(ConfigurationKey key, java.lang.String newValue)
          Sets the string value of a configuration property.
(package private) abstract  void setValue(java.lang.String key, java.lang.String value)
          Sets the string value of a configuration property.
private  void workerSetValue(ConfigurationKey key, java.lang.String newValue)
          Internal routine which calls the abstract setValue and handles all necessary functionality including firing property change notifications and tracing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_loadedFromFile

private java.io.File _loadedFromFile
Internal storage for the File the configuration was loaded from, otherwise null.


_loadedFromURL

private java.net.URL _loadedFromURL
Internal storage for the URL the configuration was loaded from, otherwise null.


_changeable

private boolean _changeable
Internal flag indicating whether the configuration can be updated.


_loaded

private boolean _loaded
Internal flag indicating whether the configuration has been loaded. Configuration rules allow a single load, whether manual or automatic.


_changed

private boolean _changed
Internal flag indicating whether the configuration has been modified after it was loaded.


_pcl

private static java.beans.PropertyChangeSupport _pcl
Internal worker for property change.


_cat

private static org.apache.log4j.Logger _cat
Constructor Detail

ConfigurationHandler

public ConfigurationHandler()
Anonymous constructor allows configuration changes.


ConfigurationHandler

public ConfigurationHandler(boolean changeable)
Constructor which optionally allows configuration changes.

Parameters:
changeable - indicates if the configuration can be changed
Method Detail

getDefaultPath

public abstract java.lang.String getDefaultPath()
Returns a default configuration path. This could be a filename or a URL. It is not guaranteed to be usable across different implementations of ConfigurationHandler.

Returns:
the default configuration path or url.

loadIfNecessary

private void loadIfNecessary()
Internal worker which is called prior to any getValue or setValue to ensure that the default load is done if it was not loaded previously.


loadDefault

public final boolean loadDefault()
Load the configuration from the default location.

Returns:
true if this call loaded the configuration, otherwise false, not distinguishing between a load error or a previously loaded configuration.
See Also:
isLoaded()

saveDefault

public final boolean saveDefault()
Save the configuration to the location it was loaded from. Do not force it if the configuration was not loaded already.

Returns:
true if the save was successful, false if it was not attempted or encountered an error.

saveDefault

public final boolean saveDefault(boolean force)
Save the configuration to the location it was loaded from.

Parameters:
force - the save even if it would not normally be done.
Returns:
true if the save was successful, false if it was not attempted or encountered an error.

isChangeable

public final boolean isChangeable()
Indicates whether the configuration can be saved.

Returns:
true if the configuration can be saved.

isChanged

public final boolean isChanged()
Indicates whether the configuration can be saved.

Returns:
true if the configuration has been changed after load.

isLoaded

public final boolean isLoaded()
Indicates whether the configuration has been loaded.

Returns:
true if the configuration has been loaded.

load

public final boolean load(java.io.File file)
Load the configuration from a File.

Parameters:
file - to load from.
Returns:
true if this call loaded the configuration, otherwise false, not distinguishing between a load error or a previously loaded configuration.

load

public final boolean load(java.net.URL url)
Load the configuration from a URL.

Parameters:
url - to load from.
Returns:
true if this call loaded the configuration, otherwise false, not distinguishing between a load error or a previously loaded configuration.

save

public final boolean save(java.io.File file)
Save the configuration to a File.

Parameters:
file - to save to.
Returns:
true if this call saved the configuration, otherwise false.

save

public final boolean save(java.net.URL url)
Save the configuration to a URL.

Parameters:
url - to save to.
Returns:
true if this call saved the configuration, otherwise false.

getString

public final java.lang.String getString(ConfigurationKey key,
                                        java.lang.String defaultValue)
Returns the string value of a configuration property.

Parameters:
key - the configuration key to return.
defaultValue - the default value key to return if the key is not found.
Returns:
the value of the key or the default value if the key does not exist.

getInteger

public final int getInteger(ConfigurationKey key,
                            int defaultValue)
Returns the numeric value of a configuration property.

Parameters:
key - the configuration key to return.
defaultValue - the default value key to return if the key is not found.
Returns:
the value of the key or the default value if the key does not exist.

getDouble

public final double getDouble(ConfigurationKey key,
                              double defaultValue)
Returns the numeric value of a configuration property.

Parameters:
key - the configuration key to return.
defaultValue - the default value key to return if the key is not found.
Returns:
the value of the key or the default value if the key does not exist.

getBoolean

public final boolean getBoolean(ConfigurationKey key,
                                boolean defaultValue)
Returns the boolean value of a configuration property.

Parameters:
key - the configuration key to return.
defaultValue - the default value key to return if the key is not found.
Returns:
the value of the key or the default value if the key does not exist.

workerSetValue

private final void workerSetValue(ConfigurationKey key,
                                  java.lang.String newValue)
Internal routine which calls the abstract setValue and handles all necessary functionality including firing property change notifications and tracing.

Parameters:
key - the configuration key to modify.
newValue - the new value of the key.

setString

public final void setString(ConfigurationKey key,
                            java.lang.String newValue)
Sets the string value of a configuration property.

Parameters:
key - the configuration key to modify.
newValue - the value to set the key to.

setInteger

public final void setInteger(ConfigurationKey key,
                             int value)
Sets the numeric value of a configuration property.

Parameters:
key - the configuration key to modify.
value - the value to set the key to.

setDouble

public final void setDouble(ConfigurationKey key,
                            double value)
Sets the numeric value of a configuration property.

Parameters:
key - the configuration key to modify.
value - the value to set the key to.

setBoolean

public final void setBoolean(ConfigurationKey key,
                             boolean value)
Sets the boolean value of a configuration property.

Parameters:
key - the configuration key to modify.
value - the value to set the key to.

addListener

public final void addListener(java.beans.PropertyChangeListener pcl)
Adds a property change listener.

Parameters:
pcl - The class which will listen for property changes.

removeListener

public final void removeListener(java.beans.PropertyChangeListener pcl)
Removes a property change listener.

Parameters:
pcl - The class to remove as a property change listener.

addListener

public final void addListener(ConfigurationKey key,
                              java.beans.PropertyChangeListener pcl)
Adds a property change listener.Static for simplicity of use.

Parameters:
key - The specific key to listen for.
pcl - The class which will listen for property changes.

removeListener

public final void removeListener(ConfigurationKey key,
                                 java.beans.PropertyChangeListener pcl)
Removes a property change listener.

Parameters:
key - The specific key being listened for.
pcl - The class to remove as a property change listener.

loadUnspecified

boolean loadUnspecified()
Internal processing to load from an unspecified source.

Returns:
true if the load was successful, otherwise false.

saveUnspecified

boolean saveUnspecified()
Internal processing to save to an unspecified source.

Returns:
true if the save was successful, otherwise false.

loadFile

abstract boolean loadFile(java.io.File file)
Internal processing to load a File.

Parameters:
file - the file to load.
Returns:
true if the load was successful, otherwise false.

loadURL

abstract boolean loadURL(java.net.URL url)
Internal processing to load a URL.

Parameters:
url - the url to load.
Returns:
true if the load was successful, otherwise false.

saveFile

abstract boolean saveFile(java.io.File file)
Internal processing to save a File.

Parameters:
file - the file to save.
Returns:
true if the save was successful, otherwise false.

saveURL

abstract boolean saveURL(java.net.URL url)
Internal processing to save a URL.

Parameters:
url - the url to save.
Returns:
true if the save was successful, otherwise false.

hasKey

public boolean hasKey(ConfigurationKey key)
Allows query for the existence of a configuration property. This may be overridden if the implementation has a more efficient method.

Parameters:
key - the property being checked.
Returns:
true if the key exists, otherwise false.

getValue

public abstract java.lang.String getValue(java.lang.String key,
                                          java.lang.String defaultValue)
Returns the string value of a configuration property.

Parameters:
key - the configuration key to return.
defaultValue - the configuration key to return.
Returns:
the value of the key or the default value if the key does not exist.

setValue

abstract void setValue(java.lang.String key,
                       java.lang.String value)
Sets the string value of a configuration property.

Parameters:
key - the configuration key to modify.
value - the value to set the key to.


ArgoUML © 1996-2004 (20040316)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook