net.sf.jameleon.util
Class Configurator

java.lang.Object
  extended by net.sf.jameleon.util.Configurator

public class Configurator
extends Object


Field Summary
protected  String configName
           
static String DEFAULT_CONFIG_NAME
           
protected  Properties props
           
protected static boolean warningMsgGiven
           
 
Method Summary
static void clearInstance()
          Cleans everything up and sets the current instance to null
protected  void configure()
          Set everything up by reading the configuration file.
 String getConfigName()
          Gets the name of the configuration file.
protected  InputStream getInputStream(String fileName)
           
static Configurator getInstance()
          Gets an instance Configurator if one has already been created or creates a new one if not.
 Set getKeys()
           
 Set getKeysStartingWith(String prefix)
           
 Properties getProperties()
           
 String getValue(String key)
          Gets a value from the provided configuration file.
 String getValue(String key, String defaultValue)
          Gets a value from the provided configuration file or if it's not set, then set it's default value
 String[] getValueAsArray(String key)
          Gets a value from the provided configuration file as an array.
 String[] getValueAsArray(String key, String separator)
          Gets a value from the provided configuration file as an array.
 void setConfigName(String configName)
          Sets the name of the configuration file.
 void setValue(String key, String value)
          Sets a value of a given property
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONFIG_NAME

public static final String DEFAULT_CONFIG_NAME
See Also:
Constant Field Values

configName

protected String configName

warningMsgGiven

protected static boolean warningMsgGiven

props

protected Properties props
Method Detail

getInstance

public static Configurator getInstance()
Gets an instance Configurator if one has already been created or creates a new one if not.

Returns:
An instance Configurator if one has already been created or creates a new one if not.

getKeys

public Set getKeys()

getProperties

public Properties getProperties()

getKeysStartingWith

public Set getKeysStartingWith(String prefix)

getValue

public String getValue(String key,
                       String defaultValue)
Gets a value from the provided configuration file or if it's not set, then set it's default value

Parameters:
key - - the name of the variable in the configuration file.
defaultValue - - the default value to set if the variable is not set in the configuration file.
Returns:
A value from the provided configuration file or a default value

getValue

public String getValue(String key)
Gets a value from the provided configuration file.

Parameters:
key - - the name of the variable in the configuration file.
Returns:
A value from the provided configuration file.

getValueAsArray

public String[] getValueAsArray(String key)
Gets a value from the provided configuration file as an array. This is used for space-separated variables that have values which represent arrays

Returns:
A value from the provided configuration file.

getValueAsArray

public String[] getValueAsArray(String key,
                                String separator)
Gets a value from the provided configuration file as an array. This is used for space-separated variables that have values which represent arrays

Returns:
A value from the provided configuration file.

setValue

public void setValue(String key,
                     String value)
Sets a value of a given property

Parameters:
key - - the name of the variable to set
value - - the value to the variable to.

configure

protected void configure()
Set everything up by reading the configuration file. This method is called by getValue(java.lang.String, java.lang.String) and is only executed if things aren't already set up. In other words, once a file has been read in, this method will no longer do anything. To read in a new file, call clearInstance() first.


getInputStream

protected InputStream getInputStream(String fileName)
                              throws IOException
Throws:
IOException

setConfigName

public void setConfigName(String configName)
Sets the name of the configuration file.

Parameters:
configName - - the name and path of the config file. The default location is from where the JVM was started from.

getConfigName

public String getConfigName()
Gets the name of the configuration file.

Returns:
the name and path of the config file.

clearInstance

public static void clearInstance()
Cleans everything up and sets the current instance to null



Copyright © 2003-2008 Christian Hargraves. All Rights Reserved.