|
andyLib v0.9 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.andynaz.config.ConfigMgr
public class ConfigMgr
Class to centralize the configuration of a program as a set of parameters. Parameters can be stored (for instance, at the beginning of the execution) and then retrived
The parameters can be stored in the class using one (or more) of the
init
methods provided or the setConfigParam(String, String)
method (to store them manually). When storing a value, only the last one is
saved (so different invocation of one of the init
methods override
old values of the same parameter - this can be used also to choose the
priority of different source of config parameters).
Note that the init
methods consider only the parameter which name
begin with he suffix "it.andynaz.", and when storing the value the suffix
is removed.
Parameters can be retrived using the getConfigParam(String)
method.
All of its methods are static, as there have to be only one instance of
the configuration. However, the class can return a copy of all the params
stored as a Properties
object with the getConfigParams()
method.
Field Summary | |
---|---|
private static Properties |
p
|
private static String |
prefix
|
Constructor Summary | |
---|---|
ConfigMgr()
|
Method Summary | |
---|---|
static String |
getConfigParam(String propName)
Return the config parameter associated with the name. |
static Properties |
getConfigParams()
Returns a Properties object with all the properties stored. |
static void |
init()
Loads the parameters stored in System.getProperties() . |
static void |
init(Properties props)
Loads the parameters stored in the Properties object. |
static void |
list()
List all the parameters currently stored. |
static void |
removeConfigParam(String name)
Remove a parameter value. |
static void |
setConfigParam(String name,
String value)
Set a parameter value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static String prefix
private static Properties p
Constructor Detail |
---|
public ConfigMgr()
Method Detail |
---|
public static void init()
System.getProperties()
.
This method consider only the properties that began with the prefix
"it.andynaz." and store them without the prefix.
public static void init(Properties props)
Properties
object.
This method consider only the properties that began with the prefix
"it.andynaz." and store them without the prefix.
props
-
NullPointerException
- if props is null
public static String getConfigParam(String propName)
null
if
the parameter does not existspublic static Properties getConfigParams()
public static void setConfigParam(String name, String value)
If the parameter already exists, its value is overwritten.
name
- parameter's namevalue
- parameter's value
NullPointerException
- if name
is null
public static void removeConfigParam(String name)
name
- parameter's namepublic static void list()
|
andyLib v0.9 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |