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

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

public final class TypeConverters
extends Object

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

Since:
2.1 Moved to the convert package.

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.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 Provider.
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.
 
Field Summary
static String CATEGORY
          The Plugin Category to use for TypeConverter plugins.
 
Constructor Summary
TypeConverters()
           
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CATEGORY

public static final String CATEGORY
The Plugin Category to use for TypeConverter plugins.

Since:
2.1
See Also:
Constant Field Values
Constructor Detail

TypeConverters

public TypeConverters()
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


Copyright © 1999-2015 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.