|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javatools.administrative.NonsharedParameters
public class NonsharedParameters
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This is a nonshared, i.e. instantiable variation of the Parameters class. It allows to have different parameter settings handled simultaneously, i.e. each component (or each component instance) using NonsharedParameters can maintain its own parameters. This allows, for instance, that two components running at the same time work on different databases, both obtained through their own NonsharedParameters instance. While the old 'Parameters' class is more convenient to use (less objects passed around), this version makes it easier to integrate your components with other components that also use the Parameters/NonsharedParameters to load (and maintain) their settings. Therefore please consider using the NonsharedParameters instead of the Parameters, if your code may ever be used in parallel with another project that might use one of the Parameters classes. Provides an interface for an ini-File. The ini-File may contain parameters of the form
parameterName = value ...It may also contain comments or section headers (i.e. anything that does not match the above pattern). Parameter names are not case sensitive. Initial and terminal spaces are trimmed for both parameter names and values. Boolean parameters accept multiple ways of expressing "true" (namely "on", "true", "yes" and "active"). You may also use ${param} constructs to refer to parameters set earlier, these references are replaced at the time the file is read by the current value of 'param' (null if it does not have a value!) Alternatively you can use $[param] references, they will be replaced by the current value of 'param' at runtime. Thus, param could be set/overriden after the actual reference appears, i.e. always reflects current settings. This class does function as an object. Example:
// Read data from my.ini NonsharedParameters params = new NonsharedParameters("my.ini"); // Abort with error message if the following parameters are not specified params.ensureParameters( "firstPar - some help text for the first parameter", "secondPar - some help text for the secondparameter" ); // Retrieve the value of a parameter String p=params.get("firstPar");You can load parameters from multiple files. These will overlay. You can reference a .ini file in another .ini file using the 'include' parameter, included files will be loaded at the point of the 'include' statements, parameter settings following the include statement can overwrite parameter settings of this included ini file. Example: Content of main.ini:
//load database configuration include = db_myserver.ini // overwrite or add parameters databasePort = 5555 myOtherParameter = 4Content of db_myserver.ini:
databaseSystem = postgres databaseDatabase = example databaseUser = albert databaseHost = localhost databasePort = 5432If main.ini is loaded, the 'databasePort' parameter will have value '5555' in the resulting NonsharedParameters instance. Include is recursive, make sure you do not generate a cycle!
Nested Class Summary | |
---|---|
static class |
NonsharedParameters.ParameterFileException
Reading or writing the parameters ini file failed for some reason In some cases the enclosing program might resolve the issue by providing another file |
static class |
NonsharedParameters.UndefinedParameterException
Thrown for an undefined Parameter |
Field Summary | |
---|---|
java.lang.String |
basePath
Holds the path that should be assumed to be the base path to the current directory for all local path values |
java.io.File |
iniFile
Holds the filename of the ini-file |
static java.util.regex.Pattern |
INIPATTERN
Holds the pattern used for ini-file-entries |
static FinalSet<java.lang.String> |
no
Holds words that count as "no" for boolean parameters |
static java.util.regex.Pattern |
READTIMEVARIABLEPATTERN
|
static java.util.regex.Pattern |
RUNTIMVARIABLEPATTERN
|
java.util.Map<java.lang.String,java.lang.String> |
values
Contains the values for the parameters |
Constructor Summary | |
---|---|
NonsharedParameters()
Constructors |
|
NonsharedParameters(java.io.File iniFile)
|
|
NonsharedParameters(java.io.File iniFile,
java.lang.String localPath)
|
|
NonsharedParameters(NonsharedParameters other)
|
|
NonsharedParameters(java.lang.String iniFile)
|
|
NonsharedParameters(java.lang.String iniFile,
java.lang.String localPath)
|
Method Summary | |
---|---|
void |
add(java.lang.String key,
java.lang.String value)
Adds a value to the map and to the ini file, if not yet there |
NonsharedParameters |
clone()
Cloning implementation |
void |
ensureParameters(java.lang.String... p)
Reports an error message and aborts if the parameters are undefined. |
java.lang.String |
get(java.lang.String s)
Returns a value for a parameter |
java.lang.String |
get(java.lang.String s,
java.lang.String defaultValue)
Returns a value for a parameter, returning a default value by default |
boolean |
getBoolean(java.lang.String s)
Returns a value for a boolean parameter |
boolean |
getBoolean(java.lang.String s,
boolean defaultValue)
Returns a value for a boolean parameter, returning a default value by default |
boolean |
getBooleanArgument(java.lang.String[] args,
java.lang.String... argnames)
Parses the arguments of the main method and tells whether a parameter is on or off |
java.lang.Boolean |
getBooleanObject(java.lang.String s)
Returns a value for a boolean parameter |
java.lang.Boolean |
getBooleanObject(java.lang.String s,
java.lang.Boolean defaultValue)
Returns a value for a boolean parameter, returning a default value by default |
Database |
getDatabase()
Returns the database defined in this ini-file |
double |
getDouble(java.lang.String s)
Returns a value for an integer parameter |
java.lang.Double |
getDouble(java.lang.String s,
java.lang.Double defaultValue)
Returns a value for an integer parameter returning the default value if undefined |
java.io.File |
getFile(java.lang.String s)
Returns a value for a file or folder parameter; same as getPath but returns an actual File instance |
java.io.File |
getFile(java.lang.String s,
java.io.File defaultValue)
Returns a value for a file or folder parameter, returning the default value if undefined; same as getPath but returns an actual File instance |
float |
getFloat(java.lang.String s)
Returns a value for an integer parameter |
float |
getFloat(java.lang.String s,
float defaultValue)
Returns a value for an integer parameter returning the default value if undefined |
java.lang.Float |
getFloatObject(java.lang.String s)
Returns a value for an integer parameter |
java.lang.Float |
getFloatObject(java.lang.String s,
java.lang.Float defaultValue)
Returns a value for an integer parameter returning the default value if undefined |
int |
getInt(java.lang.String s)
Returns a value for an integer parameter |
int |
getInt(java.lang.String s,
int defaultValue)
Returns a value for an integer parameter returning the default value if undefined |
java.lang.Integer |
getInteger(java.lang.String s)
Returns a value for an integer parameter as Integer object |
java.lang.Integer |
getInteger(java.lang.String s,
java.lang.Integer defaultValue)
Returns a value for an integer parameter returning the default value if undefined |
java.util.List<java.lang.String> |
getList(java.lang.String s)
Returns a value for a list parameter |
java.util.Map<java.lang.String,java.lang.String> |
getMap(java.lang.String s)
Returns a value for a map parameter |
java.lang.String |
getMapEntry(java.lang.String s,
java.lang.String key)
Returns a value for a map parameter |
java.lang.String |
getOrRequest(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
java.lang.String |
getOrRequestAndAdd(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
boolean |
getOrRequestAndAddBoolean(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
boolean |
getOrRequestBoolean(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
java.io.File |
getOrRequestFileParameter(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
int |
getOrRequestInteger(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
java.lang.String |
getPath(java.lang.String s)
Returns a value for a file or folder parameter; same as getFile but returns the path as String also adjusts local paths such that a global path is returned (if a base path is set) |
java.lang.String |
getPath(java.lang.String s,
java.lang.String defaultValue)
Returns a value for a file or folder parameter, returning the default value if undefined; same as getFile but returns the path as String |
java.sql.Timestamp |
getTimestamp(java.lang.String s)
Returns a value for a date parameter; |
java.sql.Timestamp |
getTimestamp(java.lang.String s,
java.sql.Timestamp defaultValue)
Returns a value for a date parameter, returning the default value if undefined; |
java.net.URI |
getURI(java.lang.String s)
Returns a URI built from a given parameter's value |
java.net.URI |
getURI(java.lang.String s,
java.net.URI defaultValue)
Returns a URI built from a given parameter's value, but returns a given default value if the parameter is undefined |
java.net.URL |
getURL(java.lang.String s)
Returns a URL built from a given parameter's value |
java.net.URL |
getURL(java.lang.String s,
java.net.URL defaultValue)
Returns a URL built from a given parameter's value, but returns a given default value if the parameter is undefined |
void |
init(java.io.File f)
Initializes the parameters from a file |
void |
init(java.io.File f,
boolean mainIni)
|
void |
init(java.lang.String filename)
Initializes the parameters from a file |
void |
init(java.lang.String file,
boolean mainIni)
|
void |
init(java.lang.String filename,
java.io.File... folders)
Seeks the file in all given folders |
void |
initiateAllClassAttributes(java.lang.Object object)
Checks for all full-upper-case class attributes whether there is a matching parameter and sets its value to the parameter value. |
void |
initiateClassAttributes(java.lang.Object object)
Checks for all full-upper-case class attributes whether there is a matching parameter and sets its value to the parameter value. |
void |
initiateClassAttributes(java.lang.String className,
java.lang.Object object)
Checks for all full-upper-case class attributes whether there is a matching parameter and sets its value to the parameter value. |
boolean |
isDefined(java.lang.String s)
Tells whether a parameter is defined |
static void |
main(java.lang.String[] args)
Test routine |
java.lang.Object |
matchObjectAttribut(java.lang.reflect.Field field)
Deprecated. |
java.util.Set<java.lang.String> |
parameters()
Returns all defined parameters |
java.lang.String |
remove(java.lang.String parameter)
Removes a value from the mapping (NOT: from the file) |
void |
reset()
Deletes all current values |
void |
saveAs(java.lang.String file)
Stores the parameters in a given file |
void |
set(java.lang.String param,
java.lang.String value)
sets a value for a parameter |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public java.io.File iniFile
public java.lang.String basePath
public java.util.Map<java.lang.String,java.lang.String> values
public static java.util.regex.Pattern INIPATTERN
public static java.util.regex.Pattern READTIMEVARIABLEPATTERN
public static java.util.regex.Pattern RUNTIMVARIABLEPATTERN
public static FinalSet<java.lang.String> no
Constructor Detail |
---|
public NonsharedParameters()
public NonsharedParameters(java.io.File iniFile) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public NonsharedParameters(java.lang.String iniFile) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public NonsharedParameters(java.io.File iniFile, java.lang.String localPath) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public NonsharedParameters(java.lang.String iniFile, java.lang.String localPath) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public NonsharedParameters(NonsharedParameters other)
Method Detail |
---|
public NonsharedParameters clone()
clone
in class java.lang.Object
public java.sql.Timestamp getTimestamp(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.sql.Timestamp getTimestamp(java.lang.String s, java.sql.Timestamp defaultValue) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.String getPath(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.String getPath(java.lang.String s, java.lang.String defaultValue) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.io.File getFile(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.io.File getFile(java.lang.String s, java.io.File defaultValue) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.net.URI getURI(java.lang.String s) throws NonsharedParameters.UndefinedParameterException, java.net.URISyntaxException
java.net.URISyntaxException
NonsharedParameters.UndefinedParameterException
public java.net.URI getURI(java.lang.String s, java.net.URI defaultValue) throws NonsharedParameters.UndefinedParameterException, java.net.URISyntaxException
java.net.URISyntaxException
NonsharedParameters.UndefinedParameterException
public java.net.URL getURL(java.lang.String s) throws NonsharedParameters.UndefinedParameterException, java.net.MalformedURLException
java.net.MalformedURLException
NonsharedParameters.UndefinedParameterException
public java.net.URL getURL(java.lang.String s, java.net.URL defaultValue) throws NonsharedParameters.UndefinedParameterException, java.net.MalformedURLException
java.net.MalformedURLException
java.net.URISyntaxException
NonsharedParameters.UndefinedParameterException
public java.lang.Integer getInteger(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.Integer getInteger(java.lang.String s, java.lang.Integer defaultValue) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public int getInt(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public int getInt(java.lang.String s, int defaultValue) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.Float getFloatObject(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.Float getFloatObject(java.lang.String s, java.lang.Float defaultValue) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public float getFloat(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public float getFloat(java.lang.String s, float defaultValue) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public double getDouble(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.Double getDouble(java.lang.String s, java.lang.Double defaultValue) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.Boolean getBooleanObject(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.Boolean getBooleanObject(java.lang.String s, java.lang.Boolean defaultValue)
public boolean getBoolean(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public boolean getBoolean(java.lang.String s, boolean defaultValue)
public java.util.List<java.lang.String> getList(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.util.Map<java.lang.String,java.lang.String> getMap(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.String getMapEntry(java.lang.String s, java.lang.String key) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.String get(java.lang.String s) throws NonsharedParameters.UndefinedParameterException
NonsharedParameters.UndefinedParameterException
public java.lang.String get(java.lang.String s, java.lang.String defaultValue)
public java.lang.String getOrRequest(java.lang.String s, java.lang.String description)
public java.lang.String getOrRequestAndAdd(java.lang.String s, java.lang.String description) throws java.io.IOException
java.io.IOException
public boolean getOrRequestAndAddBoolean(java.lang.String s, java.lang.String description) throws java.io.IOException
java.io.IOException
public java.io.File getOrRequestFileParameter(java.lang.String s, java.lang.String description)
public boolean getOrRequestBoolean(java.lang.String s, java.lang.String description)
public int getOrRequestInteger(java.lang.String s, java.lang.String description)
public void add(java.lang.String key, java.lang.String value) throws java.io.IOException
java.io.IOException
public java.lang.String remove(java.lang.String parameter)
public void set(java.lang.String param, java.lang.String value)
public void init(java.io.File f) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public void init(java.io.File f, boolean mainIni) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public void init(java.lang.String filename, java.io.File... folders) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public void init(java.lang.String filename) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public void init(java.lang.String file, boolean mainIni) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public boolean isDefined(java.lang.String s)
public void ensureParameters(java.lang.String... p)
public boolean getBooleanArgument(java.lang.String[] args, java.lang.String... argnames)
public void reset()
public Database getDatabase() throws java.sql.SQLException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException
java.sql.SQLException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
@Deprecated public java.lang.Object matchObjectAttribut(java.lang.reflect.Field field) throws java.lang.IllegalAccessException
field
- the attribute against which to match the parameters
java.lang.IllegalAccessException
public void initiateClassAttributes(java.lang.String className, java.lang.Object object)
classname
- name of the class for which to checkobject
- object, which needs to be an instance of the given classpublic void initiateAllClassAttributes(java.lang.Object object)
classname
- name of the class for which to checkobject
- object, which needs to be an instance of the given classpublic void initiateClassAttributes(java.lang.Object object)
classname
- name of the class for which to checkobject
- object, which needs to be an instance of the given classpublic java.util.Set<java.lang.String> parameters()
public void saveAs(java.lang.String file) throws NonsharedParameters.ParameterFileException
NonsharedParameters.ParameterFileException
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |