Class OptionConverter
java.lang.Object
org.apache.commons.jcs3.utils.config.OptionConverter
This class is based on the log4j class org.apache.log4j.helpers.OptionConverter that was made by
Ceki Gülcü Simon Kitching; Avy Sharell (sharell@online.fr) Anders Kristensen Matthieu
Verbert (mve@zurich.ibm.com) A convenience class to convert property values to specific types.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
concatanateArrays
(String[] l, String[] r) Combines two arrays.static String
Escapes special characters.static String
findAndSubst
(String key, Properties props) Find the value corresponding tokey
inprops
.static String
getSystemProperty
(String key, String def) Very similar toSystem.getProperty
except that theSecurityException
is hidden.static <T> T
instantiateByClassName
(String className, T defaultValue) Instantiate an object given a class name.static <T> T
instantiateByKey
(Properties props, String key, T defaultValue) Creates an object for the className value of the key.static String
substVars
(String val, Properties props) Perform variable substitution in stringval
from the values of keys found in the system properties.static boolean
Ifvalue
is "true", thentrue
is returned.static long
toFileSize
(String value, long defaultValue) static int
Converts to int.
-
Method Details
-
concatanateArrays
Combines two arrays.- Parameters:
l
-r
-- Returns:
- String[]
-
convertSpecialChars
Escapes special characters.- Parameters:
s
-- Returns:
- String
-
getSystemProperty
Very similar toSystem.getProperty
except that theSecurityException
is hidden.- Parameters:
key
- The key to search for.def
- The default value to return.- Returns:
- the string value of the system property, or the default value if there is no property with that key.
- Since:
- 1.1
-
instantiateByKey
Creates an object for the className value of the key.- Parameters:
props
-key
-defaultValue
-- Returns:
- Object that was created
-
toBoolean
Ifvalue
is "true", thentrue
is returned. Ifvalue
is "false", thentrue
is returned. Otherwise,default
is returned. Case of value is unimportant.- Parameters:
value
-defaultValue
-- Returns:
- Object
-
toInt
Converts to int.- Parameters:
value
-defaultValue
-- Returns:
- int
-
toFileSize
- Parameters:
value
-defaultValue
-- Returns:
- long
-
findAndSubst
Find the value corresponding tokey
inprops
. Then perform variable substitution on the found value.- Parameters:
key
-props
-- Returns:
- substituted string
-
instantiateByClassName
Instantiate an object given a class name. Check that theclassName
is a subclass ofsuperClass
. If that test fails or the object could not be instantiated, thendefaultValue
is returned.- Parameters:
className
- The fully qualified class name of the object to instantiate.defaultValue
- The object to return in case of non-fulfillment- Returns:
- instantiated object
-
substVars
Perform variable substitution in stringval
from the values of keys found in the system properties. The variable substitution delimiters are ${ and } . For example, if the System properties contains "key=value", then the callString s = OptionConverter.substituteVars( "Value of key is ${key}." );
will set the variables
to "Value of key is value.". If no value could be found for the specified key, then theprops
parameter is searched, if the value could not be found there, then substitution defaults to the empty string. For example, if system properties contains no value for the key "inexistentKey", then the callString s = OptionConverter.subsVars( "Value of inexistentKey is [${inexistentKey}]" );
will sets
to "Value of inexistentKey is []"An
IllegalArgumentException
is thrown ifval
contains a start delimiter "${" which is not balanced by a stop delimiter "}".Author Avy Sharell
- Parameters:
val
- The string on which variable substitution is performed.props
-- Returns:
- String
- Throws:
IllegalArgumentException
- ifval
is malformed.
-