org.apache.commons.convert
Class Converters

java.lang.Object
  extended by org.apache.commons.convert.Converters

public class Converters
extends Object

A Converter factory and utility class.

The factory loads Converter instances via the Java service provider registry. Applications can extend the converter framework by:

To convert an object, call the static getConverter(Class, Class) method to get a Converter instance, then call the converter's Converter.convert(Object) method.


Nested Class Summary
protected static class Converters.PassThruConverter<S,T>
          Pass-through converter used when the source and target java object types are the same.
protected static class Converters.PassThruConverterCreator
           
 
Field Summary
protected static ConcurrentHashMap<String,Converter<?,?>> converterMap
           
protected static Set<ConverterCreator> creators
           
protected static String DELIMITER
           
protected static Set<String> noConversions
           
 
Method Summary
static
<S,T> Converter<S,T>
getConverter(Class<S> sourceClass, Class<T> targetClass)
          Returns an appropriate Converter instance for sourceClass and targetClass.
static void loadContainedConverters(Class<?> containerClass)
          Load all classes that implement Converter and are contained in containerClass.
static
<S,T> void
registerConverter(Converter<S,T> converter)
          Registers a Converter instance to be used by the getConverter(Class, Class) method.
static
<S,T> void
registerConverter(Converter<S,T> converter, Class<?> sourceClass, Class<?> targetClass)
          Registers a Converter instance to be used by the getConverter(Class, Class) method.
static
<S,T> void
registerCreator(ConverterCreator creator)
          Registers a ConverterCreator instance to be used by the getConverter(Class, Class) method, when a converter can't be found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DELIMITER

protected static final String DELIMITER
See Also:
Constant Field Values

converterMap

protected static final ConcurrentHashMap<String,Converter<?,?>> converterMap

creators

protected static final Set<ConverterCreator> creators

noConversions

protected static final Set<String> noConversions
Method Detail

getConverter

public static <S,T> Converter<S,T> getConverter(Class<S> sourceClass,
                                                Class<T> targetClass)
                                   throws ClassNotFoundException
Returns an appropriate Converter instance for sourceClass and targetClass. If no matching Converter is found, the method throws ClassNotFoundException.

This method is intended to be used when the source or target Object types are unknown at compile time. If the source and target Object types are known at compile time, then the appropriate converter instance should be used.

Parameters:
sourceClass - The object class to convert from
targetClass - The object class to convert to
Returns:
A matching Converter instance
Throws:
ClassNotFoundException

loadContainedConverters

public static void loadContainedConverters(Class<?> containerClass)
Load all classes that implement Converter and are contained in containerClass.

Parameters:
containerClass - A class that contains Converter implementations

registerCreator

public static <S,T> void registerCreator(ConverterCreator creator)
Registers a ConverterCreator instance to be used by the getConverter(Class, Class) method, when a converter can't be found.

Type Parameters:
S - The source object type
T - The target object type
Parameters:
creator - The ConverterCreator instance to register

registerConverter

public static <S,T> void registerConverter(Converter<S,T> converter)
Registers a Converter instance to be used by the getConverter(Class, Class) method.

Type Parameters:
S - The source object type
T - The target object type
Parameters:
converter - The Converter instance to register

registerConverter

public static <S,T> void registerConverter(Converter<S,T> converter,
                                           Class<?> sourceClass,
                                           Class<?> targetClass)
Registers a Converter instance to be used by the getConverter(Class, Class) method.

Type Parameters:
S - The source object type
T - The target object type
Parameters:
converter -
sourceClass -
targetClass -


Copyright © 2003-2013 The Apache Software Foundation. All Rights Reserved.