public class ConfigMgr extends Object
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.
Modifier and Type | Field and Description |
---|---|
private static Properties |
p |
private static String |
prefix |
Constructor and Description |
---|
ConfigMgr() |
Modifier and Type | Method and Description |
---|---|
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.
|
private static String prefix
private static Properties p
public static void init()
System.getProperties()
.
This method consider only the properties beganning with the prefix "it.andynaz.
" and stores 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 valueNullPointerException
- if name
is null
public static void removeConfigParam(String name)
name
- parameter's namepublic static void list()
© 2013 andynaz - http://andynaz.altervista.org