public class DefaultMapperFactory extends Object implements MapperFactory, StateReporter.Reportable
| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultMapperFactory.Builder
Use this builder to generate instances of DefaultMapperFactory with the
desired customizations.
For example, an instance with no customizations could be generated with the following code: |
static class |
DefaultMapperFactory.MapperFactoryBuilder<F extends DefaultMapperFactory,B extends DefaultMapperFactory.MapperFactoryBuilder<F,B>>
MapperFactoryBuilder provides an extensible Builder definition usable for
providing your own Builder class for subclasses of DefaultMapperFactory.
See the defined DefaultMapperFactory.Builder below for example of how to subclass. |
| Modifier | Constructor and Description |
|---|---|
protected |
DefaultMapperFactory(DefaultMapperFactory.MapperFactoryBuilder<?,?> builder)
Constructs a new instance of DefaultMapperFactory
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addClassMapBuilderFactory(ClassMapBuilderFactory factory)
Add factory to the factories chain
|
void |
build()
Builds this MapperFactory.
|
protected MapperFacade |
buildMapperFacade(MappingContextFactory contextFactory,
UnenhanceStrategy unenhanceStrategy)
Builds the MapperFacade for this factory.
|
protected UnenhanceStrategy |
buildUnenhanceStrategy(UnenhanceStrategy unenhanceStrategy,
SuperTypeResolverStrategy superTypeStrategy)
Generates the UnenhanceStrategy to be used for this MapperFactory,
applying the passed delegateStrategy if not null.
This allows the MapperFactory a chance to fill in the unenhance strategy with references to other parts of the factory (registered mappers, converters, object factories) which may be important in the "unenhancing" process. |
<A,B> ClassMapBuilder<A,B> |
classMap(Class<A> aType,
Class<B> bType)
Constructs a new ClassMapBuilder instance initialized with the provided
types which can be used to configure/customize the mapping between the
two types.
The returned ClassMapBuilder instance, after being fully configured, should finally be registered with the factory using the registerClassMap method. |
<A,B> ClassMapBuilder<A,B> |
classMap(Class<A> aType,
Type<B> bType)
Constructs a new ClassMapBuilder instance initialized with the provided
types which can be used to configure/customize the mapping between the
two types.
The returned ClassMapBuilder instance, after being fully configured, should finally be registered with the factory using the registerClassMap method. |
<A,B> ClassMapBuilder<A,B> |
classMap(Type<A> aType,
Class<B> bType)
Constructs a new ClassMapBuilder instance initialized with the provided
types which can be used to configure/customize the mapping between the
two types.
The returned ClassMapBuilder instance, after being fully configured, should finally be registered with the factory using the registerClassMap method. |
<A,B> ClassMapBuilder<A,B> |
classMap(Type<A> aType,
Type<B> bType)
Constructs a new ClassMapBuilder instance initialized with the provided
types which can be used to configure/customize the mapping between the
two types.
The returned ClassMapBuilder instance, after being fully configured, should finally be registered with the factory using the registerClassMap method. |
boolean |
existsRegisteredMapper(Type<?> sourceType,
Type<?> destinationType,
boolean includeAutoGeneratedMappers)
Tests for the existence of a registered mapper which corresponds to the
supplied mapperKey
|
<A,B> ClassMap<A,B> |
getClassMap(MapperKey mapperKey)
Gets the ClassMap instance (if any) which has been associated with the
types represented by the given MapperKey instance.
|
protected ClassMapBuilderFactory |
getClassMapBuilderFactory() |
ConverterFactory |
getConverterFactory()
Get an instance of the ConverterFactory associated with this
MapperFactory; it may be used to register Converter instances to be used
during mapping.
|
MapperFacade |
getMapperFacade() |
<A,B> BoundMapperFacade<A,B> |
getMapperFacade(Class<A> aType,
Class<B> bType)
Returns a BoundMapperFacade for the specified source and destination
types; this mapper is bidirectional by default, and provides signatures for
mapping in place, or with instantiation, as needed.
|
<A,B> BoundMapperFacade<A,B> |
getMapperFacade(Class<A> aType,
Class<B> bType,
boolean containsCycles)
Returns a BoundMapperFacade for the specified source and destination
types; this mapper is bidirectional by default, and provides signatures for
mapping in place, or with instantiation, as needed.
In the case that false is provided for the 'containsCycles' parameter,
an optimized mapper instance will be provided. |
<S,D> BoundMapperFacade<S,D> |
getMapperFacade(Type<S> sourceType,
Type<D> destinationType)
Returns a BoundMapperFacade for the specified source and destination
types; this mapper is bidirectional by default, and provides signatures for
mapping in place, or with instantiation, as needed.
|
<S,D> BoundMapperFacade<S,D> |
getMapperFacade(Type<S> sourceType,
Type<D> destinationType,
boolean containsCycles)
Returns a BoundMapperFacade for the specified source and destination
types; this mapper is bidirectional by default, and provides signatures for
mapping in place, or with instantiation, as needed.
In the case that false is provided for the 'containsCycles' parameter,
an optimized mapper instance will be provided. |
protected <A,B> Mapper<A,B> |
getRegisteredMapper(MapperKey mapperKey) |
UnenhanceStrategy |
getUserUnenhanceStrategy()
Returns the
UnenhanceStrategy associated with this MapperFactory,
provided when this MapperFactory was constructed. |
<S,D> Type<? extends D> |
lookupConcreteDestinationType(Type<S> sourceType,
Type<D> destinationType,
MappingContext context) |
protected <T,S> ObjectFactory<T> |
lookupExistingObjectFactory(Type<T> destinationType,
Type<S> sourceType,
MappingContext context) |
Set<Type<? extends Object>> |
lookupMappedClasses(Type<?> type)
Get the set of classes which have been mapped for the specified type.
|
<A,B> Mapper<A,B> |
lookupMapper(MapperKey mapperKey)
Get the Mapper (if any) which has been associated with the given
MapperKey.
|
Mapper<Object,Object> |
lookupMapper(MapperKey mapperKey,
MappingContext context)
Searches for a Mapper which is capable of mapping the classes identified
by the provided MapperKey instance
|
<T> ObjectFactory<T> |
lookupObjectFactory(Type<T> targetType)
Return the object factory (if any) which has been registered for the
given type.
|
<T,S> ObjectFactory<T> |
lookupObjectFactory(Type<T> targetType,
Type<S> sourceType)
Return the object factory (if any) which has been registered for the
given type.
|
<T,S> ObjectFactory<T> |
lookupObjectFactory(Type<T> destinationType,
Type<S> sourceType,
MappingContext context)
Return the object factory (if any) which has been registered for the
given type.
|
Set<ClassMap<Object,Object>> |
lookupUsedClassMap(MapperKey mapperKey)
Lookup the class map hierarchy used for the mapping defined by the
specified MapperKey, if any exists
|
protected <S,D> void |
register(Type<S> sourceType,
Type<D> destinationType,
boolean isAutoGenerated)
Registers that a mapping exists from the specified source type to the
specified destination type
|
<A,B> void |
registerClassMap(ClassMap<A,B> classMap)
Registers the given ClassMap instance with the factory; it will be used
to configure an appropriate mapping.
|
<A,B> void |
registerClassMap(ClassMapBuilder<A,B> builder)
Registers the ClassMap configured by the specified ClassMapBuilder; it
will be used to configure an appropriate mapping.
|
void |
registerConcreteType(Class<?> abstractType,
Class<?> concreteType)
Register a concrete type to use when a need arises to generate a new
instance of a given abstract type (abstract class or interface)
|
void |
registerConcreteType(Type<?> abstractType,
Type<?> concreteType)
Register a concrete type to use when a need arises to generate a new
instance of a given abstract type (abstract class or interface)
|
void |
registerDefaultFieldMapper(DefaultFieldMapper... mappers)
Register one or more DefaultFieldMapper instances to be used by this
MapperFactory; these instances will be used whenever automatically
generating a Mapper for a given pair of types.
|
void |
registerFilter(Filter<?,?> filter)
Registers a filter to be applied in the mapping process; such filters may
be used to alter source and destination values of the fields as they
are processed by mappers.
|
<A,B> void |
registerMapper(Mapper<A,B> mapper)
Registers the specified custom mapper with the factory; it will be used
for mapping between it's configured types.
|
void |
registerMappingHint(MappingHint... hints)
Deprecated.
|
<D> void |
registerObjectFactory(ObjectFactory<D> objectFactory,
Type<D> destinationType)
Register the given ObjectFactory with the MapperFactory; it will be used
when constructing new instances of the specified targetType.
|
<D,S> void |
registerObjectFactory(ObjectFactory<D> objectFactory,
Type<D> destinationType,
Type<S> sourceType)
Register the given ObjectFactory with the MapperFactory; it will be used
when constructing new instances of the specified targetType when it is
being mapped from the specified source type.
|
<T> void |
registerObjectFactory(ObjectFactory<T> objectFactory,
Class<T> targetClass)
Register the given ObjectFactory with the MapperFactory; it will be used
when constructing new instances of the specified targetType.
|
void |
reportCurrentState(StringBuilder out)
Writes details of the current state of this object to the provided
StringBuilder.
|
protected Type<?> |
resolveConcreteType(Type<?> type,
Type<?> originalType) |
protected final MapperFacade mapperFacade
protected final MapperGenerator mapperGenerator
protected final ObjectFactoryGenerator objectFactoryGenerator
protected final ConcurrentHashMap<MapperKey,ClassMap<Object,Object>> classMapRegistry
protected final SortedCollection<Mapper<Object,Object>> mappersRegistry
protected final SortedCollection<Filter<Object,Object>> filtersRegistry
protected final MappingContextFactory contextFactory
protected final MappingContextFactory nonCyclicContextFactory
protected final ConcurrentHashMap<Type<? extends Object>,ConcurrentHashMap<Type<? extends Object>,ObjectFactory<? extends Object>>> objectFactoryRegistry
protected final ConcurrentHashMap<Type<?>,Set<Type<?>>> explicitAToBRegistry
protected final ConcurrentHashMap<Type<?>,Set<Type<?>>> dynamicAToBRegistry
protected final List<DefaultFieldMapper> defaultFieldMappers
protected final UnenhanceStrategy unenhanceStrategy
protected final UnenhanceStrategy userUnenahanceStrategy
protected final ConverterFactory converterFactory
protected final CompilerStrategy compilerStrategy
protected final PropertyResolverStrategy propertyResolverStrategy
protected boolean alwaysCreateMultipleMapperWrapper
protected final ClassMapBuilderFactory classMapBuilderFactory
protected ClassMapBuilderFactory chainClassMapBuilderFactory
protected final Map<MapperKey,Set<ClassMap<Object,Object>>> usedMapperMetadataRegistry
protected final boolean useAutoMapping
protected final boolean useBuiltinConverters
protected final boolean favorExtension
protected volatile boolean isBuilt
protected volatile boolean isBuilding
protected final ExceptionUtility exceptionUtil
protected DefaultMapperFactory(DefaultMapperFactory.MapperFactoryBuilder<?,?> builder)
builder - protected void addClassMapBuilderFactory(ClassMapBuilderFactory factory)
factory - protected UnenhanceStrategy buildUnenhanceStrategy(UnenhanceStrategy unenhanceStrategy, SuperTypeResolverStrategy superTypeStrategy)
unenhanceStrategy - superTypeStrategy - true if the passed UnenhanceStrategy should take full
responsibility for un-enhancement; false if the default
behavior should be applied as a fail-safe after consulting the
passed strategy.protected MapperFacade buildMapperFacade(MappingContextFactory contextFactory, UnenhanceStrategy unenhanceStrategy)
contextFactory - unenhanceStrategy - public <A,B> Mapper<A,B> lookupMapper(MapperKey mapperKey)
MapperFactorylookupMapper in interface MapperFactorymapperKey - the MapperKey for which to look up an associated MappermapperKey;public Mapper<Object,Object> lookupMapper(MapperKey mapperKey, MappingContext context)
lookupMapper in interface MapperFactorymapperKey - context - public boolean existsRegisteredMapper(Type<?> sourceType, Type<?> destinationType, boolean includeAutoGeneratedMappers)
MapperFactoryexistsRegisteredMapper in interface MapperFactorysourceType - the source typedestinationType - the destination typeincludeAutoGeneratedMappers - specifies whether an auto-generated mapper for the given
source and destination type should be consideredprotected <A,B> Mapper<A,B> getRegisteredMapper(MapperKey mapperKey)
mapperKey - public MapperFacade getMapperFacade()
getMapperFacade in interface MapperFactorypublic <D> void registerObjectFactory(ObjectFactory<D> objectFactory, Type<D> destinationType)
MapperFactoryregisterObjectFactory in interface MapperFactoryobjectFactory - the object factory to registerdestinationType - the type which is generated by the given object factorypublic <D,S> void registerObjectFactory(ObjectFactory<D> objectFactory, Type<D> destinationType, Type<S> sourceType)
MapperFactoryregisterObjectFactory in interface MapperFactoryobjectFactory - the object factory to registerdestinationType - the type which is generated by the given object factorysourceType - the source type from which the destination type is mapped@Deprecated public void registerMappingHint(MappingHint... hints)
registerMappingHint in interface MapperFactorypublic void registerDefaultFieldMapper(DefaultFieldMapper... mappers)
MapperFactoryregisterDefaultFieldMapper in interface MapperFactorymappers - one or more DefaultFieldMapper instances to registerpublic void registerConcreteType(Type<?> abstractType, Type<?> concreteType)
MapperFactoryregisterConcreteType in interface MapperFactoryabstractType - the type of the abstract class or interfaceconcreteType - the concrete type to instantiatepublic void registerConcreteType(Class<?> abstractType, Class<?> concreteType)
MapperFactoryregisterConcreteType in interface MapperFactoryabstractType - the abstract class or interfaceconcreteType - the concrete class to instantiatepublic <T> ObjectFactory<T> lookupObjectFactory(Type<T> targetType)
MapperFactorylookupObjectFactory in interface MapperFactorytargetType - the type for which to lookup a registered ObjectFactory.null if no ObjectFactory has been registered for the
given type.public <T,S> ObjectFactory<T> lookupObjectFactory(Type<T> targetType, Type<S> sourceType)
MapperFactorylookupObjectFactory in interface MapperFactorytargetType - the type for which to lookup a registered ObjectFactory.sourceType - the source type from which the target is mappednull if no ObjectFactory has been registered for the
given type.protected <T,S> ObjectFactory<T> lookupExistingObjectFactory(Type<T> destinationType, Type<S> sourceType, MappingContext context)
destinationType - sourceType - context - public <T,S> ObjectFactory<T> lookupObjectFactory(Type<T> destinationType, Type<S> sourceType, MappingContext context)
MapperFactorylookupObjectFactory in interface MapperFactorydestinationType - sourceType - context - public <S,D> Type<? extends D> lookupConcreteDestinationType(Type<S> sourceType, Type<D> destinationType, MappingContext context)
lookupConcreteDestinationType in interface MapperFactoryprotected Type<?> resolveConcreteType(Type<?> type, Type<?> originalType)
type - originalType - public <A,B> void registerClassMap(ClassMap<A,B> classMap)
MapperFactoryregisterClassMap in interface MapperFactoryclassMap - the ClassMap instance to registerpublic <A,B> void registerClassMap(ClassMapBuilder<A,B> builder)
MapperFactoryregisterClassMap in interface MapperFactorybuilder - the ClassMapBuilder to registerpublic void build()
MapperFactorybuild in interface MapperFactorypublic Set<ClassMap<Object,Object>> lookupUsedClassMap(MapperKey mapperKey)
MapperFactorylookupUsedClassMap in interface MapperFactorymapperKey - the mapper key defining the mapping to resolveprotected <S,D> void register(Type<S> sourceType, Type<D> destinationType, boolean isAutoGenerated)
sourceType - destinationType - public <A,B> ClassMap<A,B> getClassMap(MapperKey mapperKey)
MapperFactorygetClassMap in interface MapperFactorymapperKey - the MapperKey which should be used to look up an associated
ClassMapnull if no instance has been associated with this
MapperKey instance.public Set<Type<? extends Object>> lookupMappedClasses(Type<?> type)
MapperFactorylookupMappedClasses in interface MapperFactorytype - the type for which to look up mapped typespublic ConverterFactory getConverterFactory()
MapperFactorygetConverterFactory in interface MapperFactorypublic <T> void registerObjectFactory(ObjectFactory<T> objectFactory, Class<T> targetClass)
MapperFactoryregisterObjectFactory in interface MapperFactoryobjectFactory - the object factory to registertargetClass - the type which is generated by the given object factoryprotected ClassMapBuilderFactory getClassMapBuilderFactory()
public <A,B> ClassMapBuilder<A,B> classMap(Type<A> aType, Type<B> bType)
MapperFactoryregisterClassMap method.classMap in interface MapperFactoryaType - the Type instance representing the "A" side of the mappingbType - the Type instance representing the "B" side of the mappingpublic <A,B> ClassMapBuilder<A,B> classMap(Class<A> aType, Type<B> bType)
MapperFactoryregisterClassMap method.classMap in interface MapperFactoryaType - the Class instance representing the "A" side of the mappingbType - the Type instance representing the "B" side of the mappingpublic <A,B> ClassMapBuilder<A,B> classMap(Type<A> aType, Class<B> bType)
MapperFactoryregisterClassMap method.classMap in interface MapperFactoryaType - the Type instance representing the "A" side of the mappingbType - the Class instance representing the "B" side of the mappingpublic <A,B> ClassMapBuilder<A,B> classMap(Class<A> aType, Class<B> bType)
MapperFactoryregisterClassMap method.classMap in interface MapperFactoryaType - the Class instance representing the "A" side of the mappingbType - the Class instance representing the "B" side of the mappingpublic <A,B> void registerMapper(Mapper<A,B> mapper)
MapperFactoryregisterMapper in interface MapperFactorymapper - the mapper to registerpublic <S,D> BoundMapperFacade<S,D> getMapperFacade(Type<S> sourceType, Type<D> destinationType)
MapperFactorygetMapperFacade in interface MapperFactorysourceType - the 'A' type for the returned DedicatedMapperFacadedestinationType - the 'B' type for the returned DedicatedMapperFacadepublic <S,D> BoundMapperFacade<S,D> getMapperFacade(Type<S> sourceType, Type<D> destinationType, boolean containsCycles)
MapperFactoryfalse is provided for the 'containsCycles' parameter,
an optimized mapper instance will be provided.getMapperFacade in interface MapperFactorysourceType - the 'A' type for the returned DedicatedMapperFacadedestinationType - the 'B' type for the returned DedicatedMapperFacadecontainsCycles - true if the object graph for the source and destination types
may contain cycles in it's graphpublic <A,B> BoundMapperFacade<A,B> getMapperFacade(Class<A> aType, Class<B> bType)
MapperFactorygetMapperFacade in interface MapperFactoryaType - the 'A' type for the returned DedicatedMapperFacadebType - the 'B' type for the returned DedicatedMapperFacadepublic <A,B> BoundMapperFacade<A,B> getMapperFacade(Class<A> aType, Class<B> bType, boolean containsCycles)
MapperFactoryfalse is provided for the 'containsCycles' parameter,
an optimized mapper instance will be provided.getMapperFacade in interface MapperFactoryaType - the 'A' type for the returned DedicatedMapperFacadebType - the 'B' type for the returned DedicatedMapperFacadecontainsCycles - true if the object graph for the source and destination types
may contain cycles in it's graphpublic UnenhanceStrategy getUserUnenhanceStrategy()
MapperFactoryUnenhanceStrategy associated with this MapperFactory,
provided when this MapperFactory was constructed.getUserUnenhanceStrategy in interface MapperFactoryUnenhanceStrategy associated with this MapperFactory.public void registerFilter(Filter<?,?> filter)
MapperFactoryregisterFilter in interface MapperFactoryfilter - the filter to be registeredpublic void reportCurrentState(StringBuilder out)
StateReporter.ReportablereportCurrentState in interface StateReporter.ReportableCopyright © 2019 Glasnost. All rights reserved.