ma.glasnost.orika.metadata
Class ClassMapBuilder<A,B>

java.lang.Object
  extended by ma.glasnost.orika.metadata.ClassMapBuilder<A,B>
Type Parameters:
A -
B -
All Implemented Interfaces:
MappedTypePair<A,B>
Direct Known Subclasses:
CaseInsensitiveClassMapBuilder, ClassMapBuilderForMaps, ScoringClassMapBuilder

public class ClassMapBuilder<A,B>
extends Object
implements MappedTypePair<A,B>

ClassMapBuilder provides a fluent API which can be used to define a mapping from one class to another.


Nested Class Summary
static class ClassMapBuilder.Factory
           
 
Constructor Summary
protected ClassMapBuilder(Type<A> aType, Type<B> bType, MapperFactory mapperFactory, PropertyResolverStrategy propertyResolver, DefaultFieldMapper... defaults)
           
 
Method Summary
protected  void addFieldMap(FieldMap fieldMap)
           
 ClassMapBuilder<A,B> byDefault(DefaultFieldMapper... withDefaults)
          Configures this class-map builder to employ the default property mapping behavior to any properties that have not already been mapped or excluded; if any DefaultFieldMapper instances are passed, they will be used (instead of those configured on the builder) to attempt a property name match if a direct match is not found.
 ClassMapBuilder<A,B> byDefault(MappingHint[] mappingHints)
          Deprecated. use byDefault(DefaultFieldMapper...) instead
 ClassMapBuilder<A,B> byDefault(MappingHint hint0, MappingHint... mappingHints)
          Deprecated. use byDefault(DefaultFieldMapper...) instead
 ClassMapBuilder<A,B> constructorA(String... args)
          Declares a constructor to be used for the A type with the specified arguments.
 ClassMapBuilder<A,B> constructorB(String... args)
          Declares a constructor to be used for the B type with the specified arguments.
 ClassMapBuilder<A,B> customize(Mapper<A,B> customizedMapper)
          Set the custom mapper to use for this mapping.
 ClassMapBuilder<A,B> customize(MapperBase<A,B> legacyCustomizedMapper)
          Deprecated. use customize(Mapper) instead
protected  String describeClassMap()
           
 ClassMapBuilder<A,B> exclude(String fieldName)
          Exclude the specified field from mapping
 ClassMapBuilder<A,B> field(Property.Builder fieldA, Property.Builder fieldB)
           
 ClassMapBuilder<A,B> field(Property.Builder fieldA, String fieldNameB)
           
 ClassMapBuilder<A,B> field(Property fieldA, Property fieldB)
           
 ClassMapBuilder<A,B> field(Property fieldA, String fieldNameB)
           
 ClassMapBuilder<A,B> field(String fieldNameA, Property.Builder fieldB)
           
 ClassMapBuilder<A,B> field(String fieldNameA, Property fieldB)
           
 ClassMapBuilder<A,B> field(String fieldNameA, String fieldNameB)
          Map a field in both directions
 ClassMapBuilder<A,B> fieldAToB(String fieldNameA, String fieldNameB)
          Map a field in one direction only (from fieldNameA to fieldNameB)
 ClassMapBuilder<A,B> fieldBToA(String fieldNameB, String fieldNameA)
          Map a field in one direction only (from fieldNameB to fieldNameA)
 FieldMapBuilder<A,B> fieldMap(Property.Builder fieldA, Property.Builder fieldB, boolean byDefault)
           
 FieldMapBuilder<A,B> fieldMap(Property.Builder fieldA, String fieldNameB, boolean byDefault)
           
 FieldMapBuilder<A,B> fieldMap(Property fieldA, Property fieldB, boolean byDefault)
           
 FieldMapBuilder<A,B> fieldMap(Property fieldA, String fieldNameB, boolean byDefault)
           
 FieldMapBuilder<A,B> fieldMap(String a)
          Create a fieldMap for the particular field (same property name used in both types)
 FieldMapBuilder<A,B> fieldMap(String a, boolean byDefault)
          Create a fieldMap for the particular field (same property name used in both types)
 FieldMapBuilder<A,B> fieldMap(String fieldNameA, Property.Builder fieldB, boolean byDefault)
           
 FieldMapBuilder<A,B> fieldMap(String fieldNameA, Property fieldB, boolean byDefault)
           
 FieldMapBuilder<A,B> fieldMap(String fieldNameA, String fieldNameB)
          Create a fieldMap for the particular field mapping
 FieldMapBuilder<A,B> fieldMap(String fieldNameA, String fieldNameB, boolean byDefault)
          Create a fieldMap for the particular field mapping
 Type<A> getAType()
           
 Type<B> getBType()
           
protected  DefaultFieldMapper[] getDefaultFieldMappers()
           
protected  Set<FieldMap> getMappedFields()
           
protected  Set<String> getMappedPropertiesForTypeA()
           
protected  Set<String> getMappedPropertiesForTypeB()
           
protected  Set<String> getPropertiesForTypeA()
           
protected  Set<String> getPropertiesForTypeB()
           
protected  PropertyResolverStrategy getPropertyResolver()
           
protected  boolean isNestedPropertyExpression(String expression)
          Determines whether the provided string is a valid property expression
static
<A,B> ClassMapBuilder<A,B>
map(Class<A> aType, Class<B> bType)
          Deprecated. use MapperFactory.classMap(Class, Class) instead
static
<A,B> ClassMapBuilder<A,B>
map(Class<A> aType, Type<B> bType)
          Deprecated. use MapperFactory.classMap(Class, Type) instead
static
<A,B> ClassMapBuilder<A,B>
map(Type<A> aType, Class<B> bType)
          Deprecated. use MapperFactory.classMap(Type, Class) instead
static
<A,B> ClassMapBuilder<A,B>
map(Type<A> aType, Type<B> bType)
          Deprecated. use MapperFactory.classMap(Type, Type) instead
 ClassMapBuilder<A,B> mapNulls(boolean destinationsMappedOnNull)
           
 ClassMapBuilder<A,B> mapNullsInReverse(boolean sourcesMappedOnNull)
           
 void register()
          Registers the ClassMap defined by this builder with it's initiating MapperFactory
protected  Property resolveProperty(Type type, String expr)
          Resolves a property for the particular type, based on the provided property expression
protected  Property resolvePropertyForA(String expr)
          Resolves a property expression for this builder's 'A' type
protected  Property resolvePropertyForB(String expr)
          Resolves a property expression for this builder's 'B' type
 ClassMap<A,B> toClassMap()
          Produces a ClassMap instance based on the configurations defined on this ClassMapBuilder.
 String toString()
           
<X,Y> ClassMapBuilder<A,B>
use(Class<?> aParentClass, Class<?> bParentClass)
          Configure this ClassMapBuilder to use an existing mapping (for parent classes) defined from aParentClass to bParentClass.
<X,Y> ClassMapBuilder<A,B>
use(Type<?> aParentType, Type<?> bParentType)
          Configure this ClassMapBuilder to use an existing mapping (for parent classes) defined from aParentClass to bParentClass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassMapBuilder

protected ClassMapBuilder(Type<A> aType,
                          Type<B> bType,
                          MapperFactory mapperFactory,
                          PropertyResolverStrategy propertyResolver,
                          DefaultFieldMapper... defaults)
Parameters:
aType -
bType -
propertyResolver -
defaults -
Method Detail

field

public ClassMapBuilder<A,B> field(String fieldNameA,
                                  String fieldNameB)
Map a field in both directions

Parameters:
fieldNameA - property name in type A
fieldNameB - property name in type B
Returns:

fieldAToB

public ClassMapBuilder<A,B> fieldAToB(String fieldNameA,
                                      String fieldNameB)
Map a field in one direction only (from fieldNameA to fieldNameB)

Parameters:
fieldNameA - the (source) fieldName from type A
fieldNameB - the (destination) fieldName from type B
Returns:

fieldBToA

public ClassMapBuilder<A,B> fieldBToA(String fieldNameB,
                                      String fieldNameA)
Map a field in one direction only (from fieldNameB to fieldNameA)

Parameters:
fieldNameB - the (source) fieldName from type B
fieldNameA - the (destination) fieldName from type A
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(String a)
Create a fieldMap for the particular field (same property name used in both types)

Parameters:
a -
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(String a,
                                     boolean byDefault)
Create a fieldMap for the particular field (same property name used in both types)

Parameters:
a -
byDefault -
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(String fieldNameA,
                                     String fieldNameB)
Create a fieldMap for the particular field mapping

Parameters:
fieldNameA - the name of the field in type A
fieldNameB - the name of the field in type B
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(String fieldNameA,
                                     String fieldNameB,
                                     boolean byDefault)
Create a fieldMap for the particular field mapping

Parameters:
fieldNameA - the name of the field in type A
fieldNameB - the name of the field in type B
byDefault - whether the field mapping has been provided by default
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(Property fieldA,
                                     Property fieldB,
                                     boolean byDefault)
Parameters:
fieldA -
fieldB -
byDefault -
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(String fieldNameA,
                                     Property fieldB,
                                     boolean byDefault)
Parameters:
fieldA -
fieldB -
byDefault -
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(Property fieldA,
                                     String fieldNameB,
                                     boolean byDefault)
Parameters:
fieldA -
fieldNameB -
byDefault -
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(Property.Builder fieldA,
                                     Property.Builder fieldB,
                                     boolean byDefault)
Parameters:
fieldA -
fieldB -
byDefault -
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(String fieldNameA,
                                     Property.Builder fieldB,
                                     boolean byDefault)
Parameters:
fieldA -
fieldB -
byDefault -
Returns:

fieldMap

public FieldMapBuilder<A,B> fieldMap(Property.Builder fieldA,
                                     String fieldNameB,
                                     boolean byDefault)
Parameters:
fieldA -
fieldNameB -
byDefault -
Returns:

field

public ClassMapBuilder<A,B> field(Property fieldA,
                                  Property fieldB)
Parameters:
fieldA -
fieldB -
byDefault -
Returns:

field

public ClassMapBuilder<A,B> field(String fieldNameA,
                                  Property fieldB)
Parameters:
fieldA -
fieldB -
byDefault -
Returns:

field

public ClassMapBuilder<A,B> field(Property fieldA,
                                  String fieldNameB)
Parameters:
fieldA -
fieldNameB -
byDefault -
Returns:

field

public ClassMapBuilder<A,B> field(Property.Builder fieldA,
                                  Property.Builder fieldB)
Parameters:
fieldA -
fieldB -
byDefault -
Returns:

field

public ClassMapBuilder<A,B> field(String fieldNameA,
                                  Property.Builder fieldB)
Parameters:
fieldA -
fieldB -
byDefault -
Returns:

field

public ClassMapBuilder<A,B> field(Property.Builder fieldA,
                                  String fieldNameB)
Parameters:
fieldA -
fieldNameB -
byDefault -
Returns:

exclude

public ClassMapBuilder<A,B> exclude(String fieldName)
Exclude the specified field from mapping

Parameters:
fieldName - the name of the field/property to exclude
Returns:

customize

@Deprecated
public final ClassMapBuilder<A,B> customize(MapperBase<A,B> legacyCustomizedMapper)
Deprecated. use customize(Mapper) instead

Set the custom mapper to use for this mapping.

Parameters:
legacyCustomizedMapper -
Returns:

customize

public ClassMapBuilder<A,B> customize(Mapper<A,B> customizedMapper)
Set the custom mapper to use for this mapping.

Parameters:
customizedMapper -
Returns:

use

public <X,Y> ClassMapBuilder<A,B> use(Class<?> aParentClass,
                                      Class<?> bParentClass)
Configure this ClassMapBuilder to use an existing mapping (for parent classes) defined from aParentClass to bParentClass.

Parameters:
aParentClass - the source class of the parent mapping
bParentClass - the destination class of the parent mapping
Returns:
this ClassMapBuilder

use

public <X,Y> ClassMapBuilder<A,B> use(Type<?> aParentType,
                                      Type<?> bParentType)
Configure this ClassMapBuilder to use an existing mapping (for parent classes) defined from aParentClass to bParentClass.

Parameters:
aParentType - the source type of the parent mapping
bParentType - the destination type of the parent mapping
Returns:
this ClassMapBuilder

byDefault

public ClassMapBuilder<A,B> byDefault(DefaultFieldMapper... withDefaults)
Configures this class-map builder to employ the default property mapping behavior to any properties that have not already been mapped or excluded; if any DefaultFieldMapper instances are passed, they will be used (instead of those configured on the builder) to attempt a property name match if a direct match is not found.

Parameters:
withDefaults - zero or more DefaultFieldMapper instances to apply during the default mapping; if none are supplied, the configured DefaultFieldMappers for the builder (if any) should be used.
Returns:
this ClassMapBuilder instance

byDefault

@Deprecated
public final ClassMapBuilder<A,B> byDefault(MappingHint hint0,
                                                       MappingHint... mappingHints)
Deprecated. use byDefault(DefaultFieldMapper...) instead

Parameters:
hint0 - first hint
mappingHints - remaining hints
Returns:

byDefault

@Deprecated
public final ClassMapBuilder<A,B> byDefault(MappingHint[] mappingHints)
Deprecated. use byDefault(DefaultFieldMapper...) instead

Parameters:
mappingHints -
Returns:

toClassMap

public ClassMap<A,B> toClassMap()
Produces a ClassMap instance based on the configurations defined on this ClassMapBuilder. A ClassMap is used by Orika as a runtime descriptor for the details of a mapping between one type and another.

Returns:
a ClassMap as configured by this ClassMapBuilder

mapNulls

public ClassMapBuilder<A,B> mapNulls(boolean destinationsMappedOnNull)
Parameters:
destinationsMappedOnNull - true|false to indicate whether the destination properties of this class map's fields should be set to null (when mapping in the forward direction) if the source property's value is null
Returns:
this FieldMapBuilder

mapNullsInReverse

public ClassMapBuilder<A,B> mapNullsInReverse(boolean sourcesMappedOnNull)
Parameters:
sourcesMappedOnNull - true|false to indicate whether the source properties of this class map's fields should be set to null (when mapping in the reverse direction) if the destination property's value is null
Returns:
this FieldMapBuilder

register

public void register()
Registers the ClassMap defined by this builder with it's initiating MapperFactory


describeClassMap

protected String describeClassMap()
Returns:
a pseudo-code description of the class map that is created by this builder

map

public static final <A,B> ClassMapBuilder<A,B> map(Class<A> aType,
                                                   Class<B> bType)
Deprecated. use MapperFactory.classMap(Class, Class) instead

Creates a new ClassMapBuilder configuration for mapping between aType and bType.

Parameters:
aType -
bType -
Returns:

map

public static final <A,B> ClassMapBuilder<A,B> map(Type<A> aType,
                                                   Type<B> bType)
Deprecated. use MapperFactory.classMap(Type, Type) instead

Parameters:
aType -
bType -
Returns:

map

public static final <A,B> ClassMapBuilder<A,B> map(Class<A> aType,
                                                   Type<B> bType)
Deprecated. use MapperFactory.classMap(Class, Type) instead

Parameters:
aType -
bType -
Returns:

map

public static final <A,B> ClassMapBuilder<A,B> map(Type<A> aType,
                                                   Class<B> bType)
Deprecated. use MapperFactory.classMap(Type, Class) instead

Parameters:
aType -
bType -
Returns:

isNestedPropertyExpression

protected boolean isNestedPropertyExpression(String expression)
Determines whether the provided string is a valid property expression

Parameters:
expression - the expression to evaluate
Returns:

resolveProperty

protected Property resolveProperty(Type type,
                                   String expr)
Resolves a property for the particular type, based on the provided property expression

Parameters:
type - the type to resolve
expr - the property expression to resolve
Returns:
the Property referenced by the provided expression

resolvePropertyForA

protected Property resolvePropertyForA(String expr)
Resolves a property expression for this builder's 'A' type

Parameters:
expr - the property expression
Returns:
the Property referenced by the provided expression

resolvePropertyForB

protected Property resolvePropertyForB(String expr)
Resolves a property expression for this builder's 'B' type

Parameters:
expr - the property expression
Returns:
the Property referenced by the provided expression

getAType

public Type<A> getAType()
Specified by:
getAType in interface MappedTypePair<A,B>
Returns:
the 'A' type for this builder

getBType

public Type<B> getBType()
Specified by:
getBType in interface MappedTypePair<A,B>
Returns:
the 'B' type for this builder

addFieldMap

protected void addFieldMap(FieldMap fieldMap)

getMappedPropertiesForTypeA

protected Set<String> getMappedPropertiesForTypeA()
Returns:
the mapped properties for type A

getMappedPropertiesForTypeB

protected Set<String> getMappedPropertiesForTypeB()
Returns:
the mapped properties for type B

getMappedFields

protected Set<FieldMap> getMappedFields()
Returns:
the mapped fields for this builder

getPropertiesForTypeA

protected Set<String> getPropertiesForTypeA()
Returns:
the known properties for type A

getPropertiesForTypeB

protected Set<String> getPropertiesForTypeB()
Returns:
the known properties for type B

getDefaultFieldMappers

protected DefaultFieldMapper[] getDefaultFieldMappers()
Returns:
the default field mappers (if any) configured for this builder

getPropertyResolver

protected PropertyResolverStrategy getPropertyResolver()
Returns:
the property resolver used by this builder

constructorA

public ClassMapBuilder<A,B> constructorA(String... args)
Declares a constructor to be used for the A type with the specified arguments.

Parameters:
args - the arguments identifying the constructor to be used
Returns:
this ClassMapBuilder

constructorB

public ClassMapBuilder<A,B> constructorB(String... args)
Declares a constructor to be used for the B type with the specified arguments.

Parameters:
args - the arguments identifying the constructor to be used
Returns:
this ClassMapBuilder

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Glasnost. All Rights Reserved.