org.speakright.core
Class SRConfig

java.lang.Object
  extended by org.speakright.core.SRConfig

public class SRConfig
extends java.lang.Object

Reads property files. Currently reads a single .property file for the app. Properties can be overriden (but only in unit tests)

Later we may hook this in with Jakarta Commons or DB-based config

Author:
IanRaeLaptop

Constructor Summary
SRConfig()
           
 
Method Summary
static java.lang.String configPath()
          Path of the config file (eg.
static boolean getBooleanProperty(java.lang.String propName)
          Get property as a boolean.
static java.lang.String getProperty(java.lang.String propName)
          Get a property.
static void init(java.lang.String path, java.lang.String fileName)
          MUST be called the first SpeakRight method called in an application.
static void overrideProperty(java.lang.String propName, java.lang.String val)
          Add an override value for a property.
static void uninit()
          Reset so init needs to be called again.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SRConfig

public SRConfig()
Method Detail

init

public static void init(java.lang.String path,
                        java.lang.String fileName)
MUST be called the first SpeakRight method called in an application. The constructors of flow objects often get config properties, so the app needs to first init SRConfig.

Parameters:
path - full path to the properties file. The path is normally the same as the project dir.
fileName - name of the properties file.

configPath

public static java.lang.String configPath()
Path of the config file (eg. c:\apps\app1\app1.properties)

Returns:
path

uninit

public static void uninit()
Reset so init needs to be called again. Only used by unit tests.


overrideProperty

public static void overrideProperty(java.lang.String propName,
                                    java.lang.String val)
Add an override value for a property. Calls to getProperty after this will return the override value. The override is stored in memory; the property file is not modified. This method is NOT thread-safe, so generally only used by unit tests that need to tweak a property.

Parameters:
propName -
val -

getProperty

public static java.lang.String getProperty(java.lang.String propName)
Get a property. Look first in overrides then in property file. Only loads the property file once. Throws IllegalStateException if init hasn't yet been called.

Parameters:
propName -
Returns:
value of the property or "" if not found. Never returns null.

getBooleanProperty

public static boolean getBooleanProperty(java.lang.String propName)
Get property as a boolean. expects "true" or "false"

Parameters:
propName -
Returns:
true if property equals "true" (case-sensitive).