org.axonframework.serializer
Class ChainedConverter<S,T>

java.lang.Object
  extended by org.axonframework.serializer.ChainedConverter<S,T>
Type Parameters:
S - The source type of the converter
T - The target type of the converter
All Implemented Interfaces:
ContentTypeConverter<S,T>

public class ChainedConverter<S,T>
extends Object
implements ContentTypeConverter<S,T>

A converter that delegates to a chain of other ContentTypeConverters to convert from a source to a target for which there is not necessarily a single converter available.

Since:
2.0
Author:
Allard Buijze

Constructor Summary
ChainedConverter(List<ContentTypeConverter> delegates)
          Creates a new instance that uses the given delegates to form a chain of converters.
 
Method Summary
static
<S,T> ChainedConverter<S,T>
calculateChain(Class<S> sourceType, Class<T> targetType, Collection<ContentTypeConverter<?,?>> candidates)
          Returns a converter that can convert an IntermediateRepresentation from the given sourceType to the given targetType using a chain formed with given candidates.
static
<S,T> boolean
canConvert(Class<S> sourceContentType, Class<T> targetContentType, List<ContentTypeConverter<?,?>> converters)
          Indicates whether this converter is capable of converting the given sourceContentType into targetContentType, using the given converters.
 T convert(S original)
          Converts the given object into another.
 SerializedObject<T> convert(SerializedObject<S> original)
          Converts the data format of the given original IntermediateRepresentation to the target data type.
 Class<S> expectedSourceType()
          The expected type of input data.
 Class<T> targetType()
          The returned type of IntermediateRepresentation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChainedConverter

public ChainedConverter(List<ContentTypeConverter> delegates)
Creates a new instance that uses the given delegates to form a chain of converters. Note that the delegates must for a Continuous chain, meaning that each item must produce an IntermediateRepresentation of a type that can be consumed by the next delegate.

To automatically calculate a route between converters, see calculateChain(source, target, candidates)

Parameters:
delegates - the chain of delegates to perform the conversion
Method Detail

calculateChain

public static <S,T> ChainedConverter<S,T> calculateChain(Class<S> sourceType,
                                                         Class<T> targetType,
                                                         Collection<ContentTypeConverter<?,?>> candidates)
Returns a converter that can convert an IntermediateRepresentation from the given sourceType to the given targetType using a chain formed with given candidates. The returned converter uses some (or all) of the given candidates as delegates.

Type Parameters:
S - The source type of the converter
T - The target type of the converter
Parameters:
sourceType - The source type of the converter
targetType - The target type of the converter
candidates - The candidates to form a chain with
Returns:
A converter for the given source and target types
Throws:
CannotConvertBetweenTypesException - if no converter can be created using given candidates

canConvert

public static <S,T> boolean canConvert(Class<S> sourceContentType,
                                       Class<T> targetContentType,
                                       List<ContentTypeConverter<?,?>> converters)
Indicates whether this converter is capable of converting the given sourceContentType into targetContentType, using the given converters. When true, it may use any number of the given converters to form a chain.

Type Parameters:
S - The content type of the source object
T - The content type of the target object
Parameters:
sourceContentType - The content type of the source object
targetContentType - The content type of the target object
converters - The converters eligible for use
Returns:
true if this Converter can convert between the given types, using the given converters. Otherwise false.

convert

public SerializedObject<T> convert(SerializedObject<S> original)
Description copied from interface: ContentTypeConverter
Converts the data format of the given original IntermediateRepresentation to the target data type.

Specified by:
convert in interface ContentTypeConverter<S,T>
Parameters:
original - The source to convert
Returns:
the converted representation

convert

public T convert(S original)
Description copied from interface: ContentTypeConverter
Converts the given object into another. Typically, these values are contained by a SerializedObject instance.

Specified by:
convert in interface ContentTypeConverter<S,T>
Parameters:
original - the value to convert
Returns:
the converted value

expectedSourceType

public Class<S> expectedSourceType()
Description copied from interface: ContentTypeConverter
The expected type of input data.

Specified by:
expectedSourceType in interface ContentTypeConverter<S,T>
Returns:
the expected data format in IntermediateRepresentation

targetType

public Class<T> targetType()
Description copied from interface: ContentTypeConverter
The returned type of IntermediateRepresentation

Specified by:
targetType in interface ContentTypeConverter<S,T>
Returns:
the output data format in IntermediateRepresentation


Copyright © 2010-2016. All Rights Reserved.