org.erowid.sperowider.configuration
Class Configuration

java.lang.Object
  extended byorg.erowid.sperowider.configuration.Configuration
Direct Known Subclasses:
SperowiderConfiguration

public class Configuration
extends Object

Holds configuration information for constructing an object. It enforces default values, overrides, etc. The general rule is this : every field has :

*

Version:
: $Header: /cvsroot/sperowider/SPEROWIDER_MODULE/javasource/org/erowid/sperowider/configuration/Configuration.java,v 1.4 2005/01/15 23:26:15 gurustu Exp $
Author:
: $Author: gurustu $

Constructor Summary
Configuration()
           
 
Method Summary
protected  void addSetting(String name, boolean required)
          Adds a setting, with no default.
protected  void addSetting(String name, Object defaultValue)
          Adds a setting, with a default.
 void generateConfigurationReport(PrintWriter writer)
          Generates a list of what the configured settings are.
 Object get(String name)
          Returns the value for a setting.
 boolean getAsBoolean(String name)
          Returns the value for a setting.
 Collection getAsCollection(String name)
          Returns the value for a setting.
 long getAsLong(String name)
          Returns the value for a setting.
 String getAsString(String name)
          Returns the value for a setting.
 String getMessage(String name)
          Returns the default/required message for a setting.
 List getMissingSettings()
          Returns a List of String names that are required, but are not filled in (either by defaults or by calling set(String, Object) or setUnlessSet(String, Object).
 boolean isValid()
          Returns true if all required settings have been set by calling set(String, Object) or setUnlessSet(String, Object), or have defaults.
 void set(String name, Object value)
          Sets the value of the setting.
protected  void setDefault(String name, Object value)
          Sets the default value of the setting.
 void setIgnoreNull(String name, Object value)
          Sets the value of the setting, unless value is null.
protected  void setMessage(String name, String message)
          Sets the required/default message for a setting.
 void setUnlessSet(String name, Object value)
          If the setting has not already been set, this will set it.
 void setUnlessSetIgnoreNull(String name, Object value)
          Executes setUnlessSet(String, Object), unless the value is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Configuration

public Configuration()
Method Detail

addSetting

protected void addSetting(String name,
                          Object defaultValue)
Adds a setting, with a default.


addSetting

protected void addSetting(String name,
                          boolean required)
Adds a setting, with no default.


setMessage

protected void setMessage(String name,
                          String message)
                   throws SettingDoesNotExistException
Sets the required/default message for a setting.

Throws:
SettingDoesNotExistException

setDefault

protected void setDefault(String name,
                          Object value)
                   throws SettingDoesNotExistException
Sets the default value of the setting.

Throws:
SettingDoesNotExistException

getMessage

public String getMessage(String name)
                  throws SettingDoesNotExistException
Returns the default/required message for a setting.

Throws:
SettingDoesNotExistException

get

public Object get(String name)
           throws SettingDoesNotExistException
Returns the value for a setting. If the setting has not been set, this will be the default value if any, and null if no default value has been set.

Throws:
SettingDoesNotExistException

getAsString

public String getAsString(String name)
                   throws SettingDoesNotExistException
Returns the value for a setting. If the setting has not been set, this will be the default value if any, and null if no default value has been set.

Throws:
SettingDoesNotExistException

getAsBoolean

public boolean getAsBoolean(String name)
                     throws SettingDoesNotExistException
Returns the value for a setting. If the setting has not been set, this will be the default value if any, and null if no default value has been set.

Throws:
SettingDoesNotExistException

getAsLong

public long getAsLong(String name)
               throws SettingDoesNotExistException
Returns the value for a setting. If the setting has not been set, this will be the default value if any, and null if no default value has been set.

Throws:
SettingDoesNotExistException

getAsCollection

public Collection getAsCollection(String name)
                           throws SettingDoesNotExistException
Returns the value for a setting. If the setting has not been set, this will be the default value if any, and an empty collection if no default value has been set.

Throws:
SettingDoesNotExistException

set

public void set(String name,
                Object value)
         throws SettingDoesNotExistException
Sets the value of the setting.

Throws:
SettingDoesNotExistException

setIgnoreNull

public void setIgnoreNull(String name,
                          Object value)
                   throws SettingDoesNotExistException
Sets the value of the setting, unless value is null. In that case, do nothing.

Throws:
SettingDoesNotExistException

setUnlessSet

public void setUnlessSet(String name,
                         Object value)
                  throws SettingDoesNotExistException
If the setting has not already been set, this will set it. Otherwise, this request will be ignored.

Throws:
SettingDoesNotExistException

setUnlessSetIgnoreNull

public void setUnlessSetIgnoreNull(String name,
                                   Object value)
                            throws SettingDoesNotExistException
Executes setUnlessSet(String, Object), unless the value is null.

Throws:
SettingDoesNotExistException

getMissingSettings

public List getMissingSettings()
Returns a List of String names that are required, but are not filled in (either by defaults or by calling set(String, Object) or setUnlessSet(String, Object). Returns an empty list if there are none missing.


isValid

public boolean isValid()
Returns true if all required settings have been set by calling set(String, Object) or setUnlessSet(String, Object), or have defaults.


generateConfigurationReport

public void generateConfigurationReport(PrintWriter writer)
Generates a list of what the configured settings are.


spero logo small Sperowider is
© 2005 Erowid.org