|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.commons.convert.Converters
public class Converters
A Converter factory and utility class.
The factory loads Converter instances
via the Java service provider registry. Applications can extend the
converter framework by:
Converter classConverterLoader class that
registers those classesMETA-INF/services/org.apache.commons.convert.ConverterLoader
file that contains the ConverterLoader class name(s)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
|
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
|
registerConverter(Converter<S,T> converter)
Registers a Converter instance to be used by the
getConverter(Class, Class)
method. |
|
static
|
registerConverter(Converter<S,T> converter,
Class<?> sourceClass,
Class<?> targetClass)
Registers a Converter instance to be used by the
getConverter(Class, Class)
method. |
|
static
|
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 |
|---|
protected static final String DELIMITER
protected static final ConcurrentHashMap<String,Converter<?,?>> converterMap
protected static final Set<ConverterCreator> creators
protected static final Set<String> noConversions
| Method Detail |
|---|
public static <S,T> Converter<S,T> getConverter(Class<S> sourceClass,
Class<T> targetClass)
throws ClassNotFoundException
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.
sourceClass - The object class to convert fromtargetClass - The object class to convert to
Converter instance
ClassNotFoundExceptionpublic static void loadContainedConverters(Class<?> containerClass)
Converter and are
contained in containerClass.
containerClass - A class that contains Converter
implementationspublic static <S,T> void registerCreator(ConverterCreator creator)
ConverterCreator instance to be used by the
getConverter(Class, Class)
method, when a converter can't be found.
S - The source object typeT - The target object typecreator - The ConverterCreator instance to registerpublic static <S,T> void registerConverter(Converter<S,T> converter)
Converter instance to be used by the
getConverter(Class, Class)
method.
S - The source object typeT - The target object typeconverter - The Converter instance to register
public static <S,T> void registerConverter(Converter<S,T> converter,
Class<?> sourceClass,
Class<?> targetClass)
Converter instance to be used by the
getConverter(Class, Class)
method.
S - The source object typeT - The target object typeconverter - sourceClass - targetClass -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||