com.hammurapi.convert
Class ReflectionConverter<S,T>
java.lang.Object
com.hammurapi.convert.ReflectionConverter<S,T>
- All Implemented Interfaces:
- AtomicConverter<S,T>
public class ReflectionConverter<S,T>
- extends Object
- implements AtomicConverter<S,T>
Converts one type to another using accessor/constructor combination.
- Author:
- Pavel
ReflectionConverter
public ReflectionConverter(Method accessor,
Constructor<? extends T> constructor)
- Parameters:
accessor - Source object method to invoke to get target type or
constructor parameter for the target type. If it is null, then source itself
is passed to constructor. One of parameters may be null, but not both.constructor - Target class constructor which takes one parameter, either
source type or return type of source type accessor.
convert
public T convert(S source,
Converter master,
Context context,
ClassLoader classLoader)
- Description copied from interface:
AtomicConverter
- Converts object to target type.
- Specified by:
convert in interface AtomicConverter<S,T>
- Parameters:
source - Source object.master - Master converter to delegate conversion
of object parts.
- Returns:
- Converted object.
getSourceType
public Class<S> getSourceType()
- Specified by:
getSourceType in interface AtomicConverter<S,T>
- Returns:
- Type which converter converts from.
getTargetType
public Class<? extends T> getTargetType()
- Specified by:
getTargetType in interface AtomicConverter<S,T>
- Returns:
- Type which converter converts to.
discoverConstructorConverters
public static <T> Collection<ReflectionConverter<?,T>> discoverConstructorConverters(Class<T> target)
- Discovers constructor conversions.
- Parameters:
target - Target type
- Returns:
- Collection of discovered converters.
toString
public String toString()
- Overrides:
toString in class Object