org.apache.logging.log4j.core.config.plugins.util
Class TypeConverters

java.lang.Object
  extended by org.apache.logging.log4j.core.config.plugins.util.TypeConverters

public final class TypeConverters
extends Object

Collection of basic TypeConverter implementations. May be used to register additional TypeConverters or find registered TypeConverters.


Nested Class Summary
static class TypeConverters.BigDecimalConverter
          Parses a String into a BigDecimal.
static class TypeConverters.BigIntegerConverter
          Parses a String into a BigInteger.
static class TypeConverters.BooleanConverter
          Converts a String into a Boolean.
static class TypeConverters.ByteArrayConverter
          Converts a String into a byte[].
static class TypeConverters.ByteConverter
          Converts a String into a Byte.
static class TypeConverters.CharacterConverter
          Converts a String into a Character.
static class TypeConverters.CharArrayConverter
          Converts a String into a char[].
static class TypeConverters.CharsetConverter
          Converts a String into a Charset.
static class TypeConverters.ClassConverter
          Converts a String into a Class.
static class TypeConverters.DoubleConverter
          Converts a String into a Double.
static class TypeConverters.EnumConverter<E extends Enum<E>>
          Converts a String into a Enum.
static class TypeConverters.FileConverter
          Converts a String into a File.
static class TypeConverters.FloatConverter
          Converts a String into a Float.
static class TypeConverters.IntegerConverter
          Converts a String into a Integer.
static class TypeConverters.LevelConverter
          Converts a String into a Log4j Level.
static class TypeConverters.LongConverter
          Converts a String into a Long.
static class TypeConverters.PatternConverter
          Converts a String into a Pattern.
static class TypeConverters.SecurityProviderConverter
          Converts a String into a Pattern.
static class TypeConverters.ShortConverter
          Converts a String into a Short.
static class TypeConverters.StringConverter
          Returns the given String, no conversion takes place.
static class TypeConverters.UriConverter
          Converts a String into a URI.
static class TypeConverters.UrlConverter
          Converts a String into a URL.
 
Method Summary
static Object convert(String s, Class<?> clazz, Object defaultValue)
          Converts a String to a given class if a TypeConverter is available for that class.
static TypeConverter<?> findTypeConverter(Class<?> clazz)
          Locates a TypeConverter for a specified class.
static void registerTypeConverter(Class<?> clazz, TypeConverter<?> converter)
          Registers a TypeConverter for a specified class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

convert

public static Object convert(String s,
                             Class<?> clazz,
                             Object defaultValue)
Converts a String to a given class if a TypeConverter is available for that class. Falls back to the provided default value if the conversion is unsuccessful. However, if the default value is also invalid, then null is returned (along with a nasty status log message).

Parameters:
s - the string to convert
clazz - the class to try to convert the string to
defaultValue - the fallback object to use if the conversion is unsuccessful
Returns:
the converted object which may be null if the string is invalid for the given type
Throws:
NullPointerException - if clazz is null
IllegalArgumentException - if no TypeConverter exists for the given class

findTypeConverter

public static TypeConverter<?> findTypeConverter(Class<?> clazz)
Locates a TypeConverter for a specified class.

Parameters:
clazz - the class to get a TypeConverter for
Returns:
the associated TypeConverter for that class or null if none could be found

registerTypeConverter

public static void registerTypeConverter(Class<?> clazz,
                                         TypeConverter<?> converter)
Registers a TypeConverter for a specified class. This will overwrite any existing TypeConverter that may be registered for the class.

Parameters:
clazz - the class to register the TypeConverter for
converter - the TypeConverter to register


Copyright © 1999-2014 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.