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 Properties getSystemProperties()
          Very similar to System.getProperties() except that the SecurityException is absorbed.
static String getSystemProperty(String key)
          Very similar to System.getProperty except that the SecurityException is absorbed.
static String getSystemProperty(String key, String def)
          Very similar to System.getProperty except that the SecurityException is absorbed.
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, PropertyContainer pc)
          Perform variable substitution in string val from the values of keys found in context property map, and if that fails, then 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,
                               PropertyContainer pc)
Perform variable substitution in string val from the values of keys found in context property map, and if that fails, then in the system properties.

The variable substitution delimeters are ${ and }.

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

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

If no value could be found for the specified key in the context map, then the system properties are searched, if that fails, then substitution defaults to appending "_IS_UNDEFINED" to the key name.

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

 String s = OptionConverter.subsVars(
     "Value of inexistentKey is [${inexistentKey}]", context);
will set s to "Value of inexistentKey is [inexistentKey_IS_UNDEFINED]".

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}]", context);
will set s to "Value of key is [val2]" even if the "key2" property is not set.

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 absorbed.

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.

getSystemProperty

public static String getSystemProperty(String key)
Very similar to System.getProperty except that the SecurityException is absorbed.

Parameters:
key - The key to search for.
Returns:
the string value of the system property.

getSystemProperties

public static Properties getSystemProperties()
Very similar to System.getProperties() except that the SecurityException is absorbed.

Returns:
the system properties

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)


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