|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.ntnu.item.jt.system.PropertiesReader
public class PropertiesReader
Singleton responsible for maintaining a Properties object. Provides static access via getters. Contains logic for reading a config file from disk. The config reader is only intended as a means for providing access to constants, and thus does not provide any setProperty() functions.
Properties
Method Summary | |
---|---|
boolean |
getBool(java.lang.String key,
boolean defaultValue)
Reads the value stored with a given key and attempts to cast it to boolean. |
double |
getDouble(java.lang.String key,
double defaultValue)
Reads the value stored with a given key and attempts to cast it to double. |
static PropertiesReader |
getInstance()
Returns the config reader instance. |
int |
getInt(java.lang.String key,
int defaultValue)
Reads the value stored with a given key and attempts to cast it to int. |
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
Attempts to read the string associated with a given key. |
static PropertiesReader |
initialize(java.lang.String configFile)
Initialize a config reader object, reading the properties from a given location on the local file system. |
static void |
main(java.lang.String[] args)
Contains simple test reads. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static PropertiesReader initialize(java.lang.String configFile) throws AlreadyInitializedException, java.io.IOException
configFile
- path to the configuration file on the local file system. Note that any backslashes will have to be escaped. For example "c:\powerscan\powerscan.properties" becomes "c:\\powerscan\\powerscan.properties". The file will have to be structured on a format accepted by the java Properties class.
AlreadyInitializedException
- if the config reader has already been initialized.
java.io.IOException
- if reading from the file failed. In this case, the config reader may be initialized again, or calls to getInstance() will try to load the default config file.Properties
public static PropertiesReader getInstance()
public int getInt(java.lang.String key, int defaultValue)
key
- key from which to read the value.defaultValue
- default value to be returned if reading fails.
public double getDouble(java.lang.String key, double defaultValue)
key
- key from which to read the value.defaultValue
- default value to be returned if reading fails.
public boolean getBool(java.lang.String key, boolean defaultValue)
key
- key from which to read the value.defaultValue
- default value to be returned if reading fails.
public java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
key
- key from which to read the value.defaultValue
- default value to be returned if reading fails.
public static void main(java.lang.String[] args) throws java.lang.Exception
args
-
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |