The environment class mimics the environment variables available in any shell using a hash map of keys/values, the key being the variables names, excepted here they are called parameters.
In addition, this class provides facilities to:
As in any shell, most of the time, the environment is global and accessible from any part of the system. Here a singleton instance of this class is created and accessible from anywhere in the JVM using the {@link #getGlobalEnvironment()} method (indeed the singleton instance iscreated at its first access). However, it is still possible to create a private instance of this class for use in a specific part of a program.
To read a file of parameters, simply call the {@link #readParameterFile(String)} method. In the same way, to write a set ofparameters to a file, call the {@link #writeParameterFile(String)} method.The format of the parameter file is given in the description of these methods.
To read parameters from he command line, call the {@link #readCommandLine(String[])} or{@link #readCommandLine(String[],Collection)} methods. These methods expecta format for the command line that is described in there respective documentations.
It is also possible to setup automatically the fields of an arbitrary object, provided these fields have name that match parameters in this environment. To do this call the {@link #initializeFieldsOf(Object)} method passing theobject to initialise as argument. The object to setup must provide methods of the form "setThing(Type)" where "Thing" or "thing" is the name of the field to set and "Type" is one of "int", "long", "float", "double", "String" and "boolean". For the boolean type, the accepted values meaning true are "true", "on", "1", and "yes", all other value are considered as false.
TODO: how (or when) does the default configuration file is read? TODO: how to handle parameters that cannot be setup in the {@link #initializeFieldsOf(Object)}? @author Frédéric Guinand @author Yoann Pigné @author Antoine Dutot @version 1.0 (jdk 1.5)
|
|
|
|
|
|