com.jstatcom.engine
Class ConfigHolder

java.lang.Object
  extended by com.jstatcom.engine.ConfigHolder

public final class ConfigHolder
extends java.lang.Object

This class is used by Engine instances to get all information that is necessary to run a specific engine. The types of configuration settings are defined in the ConfigKeys implementation for the underlying engine type. Instances of this class store information according to the respective configuration keys.

For every engine type there exists only one instance of this class. Instances for engine types are created or referenced by the static factory method valueOf.

All information is stored permanently in an XML file defined in the respective engine type.

Author:
Markus Kraetzig
See Also:
EngineTypes, ConfigKeys

Nested Class Summary
static class ConfigHolder.KeyValPair
          Inner class for storing key value pairs of this collection as XML elements.
 
Field Summary
static javolution.xml.XmlFormat<ConfigHolder> ConfigHolder_XML
          XML format field for (de)serialization.
 
Method Summary
 void adjustConfig()
          Creates a dialog to change the configuration settings for the respective engine.
 java.lang.String getConfig(ConfigKeys key)
          Get a configuration value for a key.
 java.util.Set<ConfigKeys> getConfigKeys()
          Gets a Set of all available ConfigKeys.
 EngineTypes getEngineType()
          Returns the engine type associated with this.
 void setConfig(ConfigKeys configKey, java.lang.String value)
          Set a key value pair to be stored by the config holder.
static ConfigHolder valueOf(EngineTypes engineType)
          Static initializer to return an instance of ConfigHolder.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ConfigHolder_XML

public static final javolution.xml.XmlFormat<ConfigHolder> ConfigHolder_XML
XML format field for (de)serialization.

Method Detail

adjustConfig

public void adjustConfig()
Creates a dialog to change the configuration settings for the respective engine. It updates the XML configuration file if the changes were successful.


getConfig

public java.lang.String getConfig(ConfigKeys key)
Get a configuration value for a key.

Parameters:
key - that defines type of setting
Returns:
a string containing the setting associated with key or null if the key is not contained
Throws:
java.lang.IllegalArgumentException - if (key == null)

getConfigKeys

public java.util.Set<ConfigKeys> getConfigKeys()
Gets a Set of all available ConfigKeys.

Returns:
a set of all keys

getEngineType

public final EngineTypes getEngineType()
Returns the engine type associated with this.

Returns:
the engine type

setConfig

public void setConfig(ConfigKeys configKey,
                      java.lang.String value)
Set a key value pair to be stored by the config holder.

Parameters:
configKey - the key
value - the value
Throws:
java.lang.IllegalArgumentException - if (configKey == null) or if configKey is not valid for the underlying engine type

valueOf

public static ConfigHolder valueOf(EngineTypes engineType)
Static initializer to return an instance of ConfigHolder. It parses the XML config file if it exists and tries to get all necessary configuration information. If the config file does not exist or if something is wrong with the settings, an input dialog is shown. The configuration file is updated if something has changed.

Parameters:
engineType - to define a specific engine
Returns:
the initialized instance
Throws:
java.lang.IllegalArgumentException - if (engineType == null)
java.lang.IllegalStateException - if the user input dialog is cancelled but the settings are still invalid