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 StringEscapes special characters.static StringfindAndSubst(String key, Properties props) Find the value corresponding tokeyinprops.static StringgetSystemProperty(String key, String def) Very similar toSystem.getPropertyexcept that theSecurityExceptionis hidden.static <T> TinstantiateByClassName(String className, T defaultValue) Instantiate an object given a class name.static <T> TinstantiateByKey(Properties props, String key, T defaultValue) Creates an object for the className value of the key.static StringsubstVars(String val, Properties props) Perform variable substitution in stringvalfrom the values of keys found in the system properties.static booleanIfvalueis "true", thentrueis returned.static longtoFileSize(String value, long defaultValue) static intConverts 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.getPropertyexcept that theSecurityExceptionis 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
Ifvalueis "true", thentrueis returned. Ifvalueis "false", thentrueis returned. Otherwise,defaultis 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 tokeyinprops. Then perform variable substitution on the found value.- Parameters:
key-props-- Returns:
- substituted string
-
instantiateByClassName
Instantiate an object given a class name. Check that theclassNameis a subclass ofsuperClass. If that test fails or the object could not be instantiated, thendefaultValueis 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 stringvalfrom 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 variablesto "Value of key is value.". If no value could be found for the specified key, then thepropsparameter 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 setsto "Value of inexistentKey is []"An
IllegalArgumentExceptionis thrown ifvalcontains 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- ifvalis malformed.
-