org.axonframework.serializer
Class ChainingConverterFactory

java.lang.Object
  extended by org.axonframework.serializer.ChainingConverterFactory
All Implemented Interfaces:
ConverterFactory

public class ChainingConverterFactory
extends Object
implements ConverterFactory

ConverterFactory implementation that will combine converters to form chains of converters to be able to convert from one type to another, for which there is no suitable single converter.

This implementation will also autodetect ContentTypeConverter implementations by scanning /META-INF/services/org.axonframework.serializer.ContentTypeConverter files on the classpath. These files must contain the fully qualified class names of the implementations to use.

Since:
2.0
Author:
Allard Buijze

Constructor Summary
ChainingConverterFactory()
          Initialize a new ChainingConverterFactory.
 
Method Summary
<S,T> ContentTypeConverter<S,T>
getConverter(Class<S> sourceContentType, Class<T> targetContentType)
          Returns a converter that is capable of converting IntermediateRepresentation object containing the given sourceContentType to the given targetContentType.
<S,T> boolean
hasConverter(Class<S> sourceContentType, Class<T> targetContentType)
          Indicates whether this factory contains a converter capable of converting the given sourceContentType into the targetContentType.
 void registerConverter(Class<? extends ContentTypeConverter> converterType)
          Registers a convert of the given converterType with this factory, only if initialization of such a converter is possible.
 void registerConverter(ContentTypeConverter converter)
          Registers the given converter with this factory.
 void setAdditionalConverters(List<ContentTypeConverter> additionalConverters)
          Setter for dependency injection frameworks that require property methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChainingConverterFactory

public ChainingConverterFactory()
Initialize a new ChainingConverterFactory. Will autodetect all converters mentioned in /META-INF/services/org.axonframework.serializer.ContentTypeConverter files on the class path.

Instances of ChainingConverterFactory are safe for use in a multi-threaded environment, with exception of the registerConverter(ContentTypeConverter) method.

Method Detail

hasConverter

public <S,T> boolean hasConverter(Class<S> sourceContentType,
                                  Class<T> targetContentType)
Description copied from interface: ConverterFactory
Indicates whether this factory contains a converter capable of converting the given sourceContentType into the targetContentType.

Specified by:
hasConverter in interface ConverterFactory
Type Parameters:
S - The type of source data for which a converter must be available
T - The type of target data for which a converter must be available
Parameters:
sourceContentType - The type of source data for which a converter must be available
targetContentType - The type of target data for which a converter must be available
Returns:
true if a converter is available, otherwise false.

getConverter

public <S,T> ContentTypeConverter<S,T> getConverter(Class<S> sourceContentType,
                                                    Class<T> targetContentType)
Description copied from interface: ConverterFactory
Returns a converter that is capable of converting IntermediateRepresentation object containing the given sourceContentType to the given targetContentType.

Specified by:
getConverter in interface ConverterFactory
Type Parameters:
S - The source content type
T - The target content type
Parameters:
sourceContentType - The type of data the converter accepts as input
targetContentType - The type of data the converter produces
Returns:
a converter capable of converting from the given sourceContentType to targetContentType

registerConverter

public void registerConverter(ContentTypeConverter converter)
Registers the given converter with this factory. The converter which is registered last will be inspected first when finding a suitable converter for a given input and output type.

An alternative to explicit converter registration (but without the ordering guarantees) is to create a file called org.axonframework.serializer.ContentTypeConverter in /META-INF/services/ on the class path which contains the fully qualified class names of the converters, separated by newlines. These implementations must have a public no-arg constructor.

Parameters:
converter - the converter to register.

registerConverter

public void registerConverter(Class<? extends ContentTypeConverter> converterType)
Registers a convert of the given converterType with this factory, only if initialization of such a converter is possible. Both the expected source type and target type classes are checked for availability on the class path. In contrast to registerConverter(ContentTypeConverter), this method allows potentially unsafe (in terms of class dependencies) converters to be registered.

The converter which is registered last will be inspected first when finding a suitable converter for a given input and output type.

An alternative to explicit converter registration (but without the ordering guarantees) is to create a file called org.axonframework.serializer.ContentTypeConverter in /META-INF/services/ on the class path which contains the fully qualified class names of the converters, separated by newlines. These implementations must have a public no-arg constructor.

Parameters:
converterType - the type of converter to register.

setAdditionalConverters

public void setAdditionalConverters(List<ContentTypeConverter> additionalConverters)
Setter for dependency injection frameworks that require property methods. This method is the same as calling registerConverter(ContentTypeConverter) for each converter in the given list of additionalConverters.

Parameters:
additionalConverters - The converters to register with this factory


Copyright © 2010-2016. All Rights Reserved.