Logback API
Version 0.9.8

ch.qos.logback.core.util
Class OptionHelper

java.lang.Object
  extended by ch.qos.logback.core.util.OptionHelper

public class OptionHelper
extends Object

Author:
Ceki Gulcu

Constructor Summary
OptionHelper()
           
 
Method Summary
static String[] extractDefaultReplacement(String key)
           
static String getSystemProperty(String key, String def)
          Very similar to System.getProperty except that the SecurityException is hidden.
static Object instantiateByClassName(String className, Class superClass, ClassLoader classLoader)
           
static Object instantiateByClassName(String className, Class superClass, Context context)
           
static boolean isEmpty(String val)
           
static String substVars(String val, Map<String,String> primaryMap, Map<String,String> secondaryMap)
          Perform variable substitution in string val from the values of keys found the primary map passed as first parameter, then in the secondary map, and last in the system properties.
static boolean toBoolean(String value, boolean dEfault)
          If value is "true", then true is returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptionHelper

public OptionHelper()
Method Detail

instantiateByClassName

public static Object instantiateByClassName(String className,
                                            Class superClass,
                                            Context context)
                                     throws IncompatibleClassException,
                                            DynamicClassLoadingException
Throws:
IncompatibleClassException
DynamicClassLoadingException

instantiateByClassName

public static Object instantiateByClassName(String className,
                                            Class superClass,
                                            ClassLoader classLoader)
                                     throws IncompatibleClassException,
                                            DynamicClassLoadingException
Throws:
IncompatibleClassException
DynamicClassLoadingException

substVars

public static String substVars(String val,
                               Map<String,String> primaryMap,
                               Map<String,String> secondaryMap)
Perform variable substitution in string val from the values of keys found the primary map passed as first parameter, then in the secondary map, and last in the system properties.

The variable substitution delimeters are ${ and }.

For example, if the primary map parameter contains a property "key1" set as "value1", then the call

 String s = OptionConverter.substituteVars("Value of key is ${key1}.", priMap,
     null);
 
will set the variable s to "Value of key is value1.".

If no value could be found for the specified key, then the secondary map is searches, and if that fails, the system properties are searched, if that fails, then substitution defaults to the empty string.

For example, if system properties contains no value for the key "inexistentKey", then the call

 String s = OptionConverter.subsVars(
     "Value of inexistentKey is [${inexistentKey}]", priMap, null);
 
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 "}".

Parameters:
val - The string on which variable substitution is performed.
Throws:
IllegalArgumentException - if val is malformed.

getSystemProperty

public static String getSystemProperty(String key,
                                       String def)
Very similar to System.getProperty except that the SecurityException 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.

extractDefaultReplacement

public static String[] extractDefaultReplacement(String key)

toBoolean

public static boolean toBoolean(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.


isEmpty

public static boolean isEmpty(String val)

Logback API
Version 0.9.8

Copyright © 2005-2008 QOS.ch. All Rights Reserved.