com.hammurapi.convert
Class ConvertingService

java.lang.Object
  extended by com.hammurapi.convert.ConvertingService

public class ConvertingService
extends Object


Field Summary
static Converter CONVERTER
          Converter which delegates to convert() method.
 
Constructor Summary
ConvertingService()
           
 
Method Summary
static
<S,T> T
convert(S source, Class<T> targetType)
          Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.
static
<S,T> T
convert(S source, Class<T> targetType, ClassLoader classLoader)
          Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.
static
<S,T> T
convert(S source, Class<T> targetType, Context context)
          Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.
static
<S,T> T
convert(S source, Class<T> targetType, Context context, ClassLoader classLoader)
          Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.
static
<S,T> ConverterClosure<S,T>
getConverter(Class<S> sourceType, Class<T> targetType)
          Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.
static
<S,T> ConverterClosure<S,T>
getConverter(Class<S> sourceType, Class<T> targetType, ClassLoader classLoader)
          Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.
static
<S,T> ConverterClosure<S,T>
getConverter(Class<S> sourceType, Class<T> targetType, Context context)
          Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.
static
<S,T> ConverterClosure<S,T>
getConverter(Class<S> sourceType, Class<T> targetType, Context context, ClassLoader classLoader)
          Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERTER

public static final Converter CONVERTER
Converter which delegates to convert() method.

Constructor Detail

ConvertingService

public ConvertingService()
Method Detail

convert

public static <S,T> T convert(S source,
                              Class<T> targetType)
                 throws ConversionException
Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface. Invocation of this method is equivalent to invocation of convert(source, targetType, false)

Parameters:
source - Source object.
targetType - Target type.
Returns:
Source object converted to target type or null if no converter is available for source/targetType combination
Throws:
ConversionException

convert

public static <S,T> T convert(S source,
                              Class<T> targetType,
                              Context context)
                 throws ConversionException
Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface. Invocation of this method is equivalent to invocation of convert(source, targetType, false)

Parameters:
source - Source object.
targetType - Target type.
context - Conversion context.
Returns:
Source object converted to target type or null if no converter is available for source/targetType combination
Throws:
ConversionException

convert

public static <S,T> T convert(S source,
                              Class<T> targetType,
                              ClassLoader classLoader)
                 throws ConversionException
Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface. Invocation of this method is equivalent to invocation of convert(source, targetType, false)

Parameters:
source - Source object.
targetType - Target type.
classLoader - Class loader, source of converters.
Returns:
Source object converted to target type or null if no converter is available for source/targetType combination
Throws:
ConversionException

convert

public static <S,T> T convert(S source,
                              Class<T> targetType,
                              Context context,
                              ClassLoader classLoader)
                 throws ConversionException
Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.

Parameters:
source - Source object.
targetType - Target type.
context - Conversion context.
classLoader - Class loader.
Returns:
Source object converted to target type or null if no converter is available for source/targetType combination
Throws:
ConversionException

getConverter

public static <S,T> ConverterClosure<S,T> getConverter(Class<S> sourceType,
                                                       Class<T> targetType)
Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.

Parameters:
sourceType - Source type.
targetType - Target type.
Returns:
Converter from source type to target type, or null if such converter is not available.
Throws:
ConversionException

getConverter

public static <S,T> ConverterClosure<S,T> getConverter(Class<S> sourceType,
                                                       Class<T> targetType,
                                                       ClassLoader classLoader)
Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.

Parameters:
sourceType - Source type.
targetType - Target type.
classLoader - Class loader to retrieve converters from.
Returns:
Converter from source type to target type, or null if such converter is not available.
Throws:
ConversionException

getConverter

public static <S,T> ConverterClosure<S,T> getConverter(Class<S> sourceType,
                                                       Class<T> targetType,
                                                       Context context)
Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.

Parameters:
sourceType - Source type.
targetType - Target type.
context - Conversion context.
Returns:
Converter from source type to target type, or null if such converter is not available.
Throws:
ConversionException

getConverter

public static <S,T> ConverterClosure<S,T> getConverter(Class<S> sourceType,
                                                       Class<T> targetType,
                                                       Context context,
                                                       ClassLoader classLoader)
Converts source to target type using Java 6 service loading for AtomicConverterBundle, AtomicConverter, and Converter services If no converter is found, this method performs converter discovery through constructors if target type is a class and through duck conversion if target type is an interface.

Parameters:
sourceType - Source type.
targetType - Target type.
context - Conversion context.
classLoader - Class loader to retrieve converters from.
Returns:
Converter from source type to target type, or null if such converter is not available.
Throws:
ConversionException