|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.x4juli.global.helper.OptionConverter
A convenience class to convert property values to specific types.
Logging API as a whole was originally done for Apache log4j. Juli is a port of main parts of that to complete the Java Logging APIs. All credits for initial idea, design, implementation, documentation belong to the log4j crew. This file was originally published by Ceki Gülcü, Simon Kitching, Anders Kristensen, Avy Sharell. Please use exclusively the appropriate mailing lists for questions, remarks and contribution.
| Field Summary | |
(package private) static java.lang.String |
DELIM_START
Constant for delimiter start. |
(package private) static int |
DELIM_START_LEN
Constant for delimiter start length. |
(package private) static char |
DELIM_STOP
Constant for delimiter stop. |
(package private) static int |
DELIM_STOP_LEN
Constant for delimiter stop length. |
| Constructor Summary | |
private |
OptionConverter()
No instanciation wanted. |
| Method Summary | |
static java.lang.String[] |
concatanateArrays(java.lang.String[] l,
java.lang.String[] r)
Concatanate two String arrays. |
static java.lang.String |
convertSpecialChars(java.lang.String s)
White- and Controlchar conversion. |
static java.lang.String[] |
extractDefaultReplacement(java.lang.String key)
Splits up a given String into in String[2] Array. |
static java.lang.String |
findAndSubst(java.lang.String key,
java.util.Properties props)
Find the value corresponding to key in props.
|
private static java.util.logging.Logger |
getLogger()
|
static java.lang.String |
getSystemProperty(java.lang.String key,
java.lang.String def)
Very similar to System.getProperty except that the
SecurityException is hidden. |
static java.lang.Object |
instantiateByClassName(java.lang.String className,
java.lang.Class superClass,
java.lang.Object defaultValue)
Instantiate an object given a class name. |
static java.lang.Object |
instantiateByKey(java.util.Properties props,
java.lang.String key,
java.lang.Class superClass,
java.lang.Object defaultValue)
Instantiate an object by given keys. |
static java.lang.String |
stripDuplicateBackslashes(java.lang.String src)
Replaces double backslashes. |
static java.lang.String |
substVars(java.lang.String val,
java.util.Properties props)
Perform variable substitution in string val from the
values of keys found the properties passed as parameter or in the system
propeties.
|
static boolean |
toBoolean(java.lang.String value,
boolean dEfault)
Converts a String to an boolean. |
static long |
toFileSize(java.lang.String value,
long dEfault)
Parsing a string with given KB, MB, or GB filesize. |
static int |
toInt(java.lang.String value,
int dEfault)
Converts a string to an int. |
static java.util.logging.Level |
toLevel(java.lang.String value,
java.util.logging.Level defaultValue)
Converts a standard or custom priority level to a Level object. |
static long |
toLong(java.lang.String value,
long dEfault)
Converts a String to a long. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
static final java.lang.String DELIM_START
static final char DELIM_STOP
static final int DELIM_START_LEN
static final int DELIM_STOP_LEN
| Constructor Detail |
private OptionConverter()
| Method Detail |
public static java.lang.String[] concatanateArrays(java.lang.String[] l,
java.lang.String[] r)
System.arraycopy.
l - first arrayr - second arry
public static java.lang.String convertSpecialChars(java.lang.String s)
s - the string to convert
public static java.lang.String getSystemProperty(java.lang.String key,
java.lang.String def)
System.getProperty except that the
SecurityException is hidden.
key - The key to search for.def - The default value to return.
public static java.lang.Object instantiateByKey(java.util.Properties props,
java.lang.String key,
java.lang.Class superClass,
java.lang.Object defaultValue)
props - to look in and replace.key - to search for.superClass - of the object.defaultValue - default Object, if instantion fails.
public static boolean toBoolean(java.lang.String value,
boolean dEfault)
If value is "true", then true is returned.
If value is "false", then true is returned.
Otherwise, default is returned.
Case of value is unimportant.
value - the valuedEfault - returned if parsing fails
public static int toInt(java.lang.String value,
int dEfault)
value - dEfault -
public static long toLong(java.lang.String value,
long dEfault)
value - dEfault -
public static long toFileSize(java.lang.String value,
long dEfault)
value - the string with the size (i.e. 9KB, 10MB, 1GB...)dEfault - the value returned if parsing fails
public static java.lang.String findAndSubst(java.lang.String key,
java.util.Properties props)
key in props.
Then perform variable substitution on the found value.
public static java.lang.Object instantiateByClassName(java.lang.String className,
java.lang.Class superClass,
java.lang.Object defaultValue)
className is a subclass of superClass. If
that test fails or the object could not be instantiated, then
defaultValue is returned.
className - The fully qualified class name of the object to
instantiate.superClass - The class to which the new object should belong.defaultValue - The object to return in case of non-fulfillment
public static java.lang.String substVars(java.lang.String val,
java.util.Properties props)
val from the
values of keys found the properties passed as parameter or in the system
propeties.
The variable substitution delimeters are ${ and }.
For example, if the properties parameter contains a property "key1" set as "value1", then the call
String s = OptionConverter.substituteVars("Value of key is ${key1}.");
will set the variable s to "Value of key is value1.".
If no value could be found for the specified key, then the system properties are searched, if the value could not be found there, then substitution defaults to the empty string.
For example, if system propeties contains no value for the key "inexistentKey", then the call
String s = OptionConverter.subsVars("Value of inexistentKey is [${inexistentKey}]");
will set s to "Value of inexistentKey is []".
Nevertheless, it is possible to specify a default substitution value using the ":-" operator. For example, the call
String s = OptionConverter.subsVars("Value of key is [${key2:-val2}]");
will set s to "Value of key is [val2]" even if the "key2"
property is unset.
An IllegalArgumentException is thrown if
val contains a start delimeter "${" which is not balanced
by a stop delimeter "}".
val - The string on which variable substitution is performed.
java.lang.IllegalArgumentException - if val is malformed.public static java.lang.String[] extractDefaultReplacement(java.lang.String key)
key - format must be FIRST:-SECOND
public static java.lang.String stripDuplicateBackslashes(java.lang.String src)
src - source string
public static java.util.logging.Level toLevel(java.lang.String value,
java.util.logging.Level defaultValue)
If value is of form "level#classname", then the specified
class' toLevel method is called to process the specified level string; if
no '#' character is present, then the default
Level class is used to process the level value.
As a special case, if the value parameter is equal to the
string "NULL", then the value null will be returned.
If any error occurs while converting the value to a level, the
defaultValue parameter, which may be null,
is returned.
Case of value is insignificant for the level level, but is
significant for the class name part, if present.
private static java.util.logging.Logger getLogger()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||