Class TLcdDataModelMapping
TLcdTransformer
. Instances of this class are used to map one or more source data models to one or more target data models.
Typical usage is as follows:
TLcdDataModelMapping mapping = new TLcdDataModelMapping(sourceDataModel, targetDataModel);
// optionally, add or change the mapping between two types
mapping.mapType(...);
// create and configure the transformer
TLcdTransformer toTargetModelTransformer = new TLcdTransformer();
mapping.configure(toTargetModelTransformer);
// the transformer is ready to be used
ILcdDataObject dataObjectFromTargetModel = toTargetModelTransformer.transform(dataObjectFromSourceModel);
- Since:
- 11.0
- See Also:
-
Constructor Summary
ConstructorDescriptionConstructs a new instance.TLcdDataModelMapping
(TLcdDataModel aSourceModel, TLcdDataModel aTargetModel) Constructs a new instance that automatically maps the given source model to the given target model (see alsomapDataModel(TLcdDataModel, TLcdDataModel...)
).TLcdDataModelMapping
(TLcdDataModel aSourceModel, TLcdDataModel aTargetModel, boolean aTransformEmptyProperties) Constructs a new instance that automatically maps the given source model to the given target model (see alsomapDataModel(TLcdDataModel, TLcdDataModel...)
). -
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(TLcdTransformer aTransformerSFCT) Registers transformations for the configured mappings and for all types in themapped
source data models (if it is not explicitly ignored and if a target type could be found).Returns the inverse of this mapping.void
ignore
(TLcdDataProperty aProperty) Marks the given property that it should not be automatically mapped, even if its declaring data model would be mapped.void
ignore
(TLcdDataType aType) Marks the given type that it should not be automatically mapped, even if its declaring data model would be mapped.void
mapDataModel
(TLcdDataModel aSourceModel, TLcdDataModel... aTargetModels) Maps a source data model on one or more target data models.mapType
(TLcdDataType aSourceType) Maps the given source type on a type with the same name in the target data models.mapType
(TLcdDataType aSourceType, TLcdDataType aTargetType) Maps the source type on the target type (and vice versa) using aTLcdDataTypeMapping
.void
mapType
(TLcdDataType aSourceType, TLcdDataType aTargetType, ILcdObjectTransformation aTransformation) Maps the source type on the target type using the given transformation.
-
Constructor Details
-
TLcdDataModelMapping
public TLcdDataModelMapping()Constructs a new instance. Properties on the source data withnull
value will not be transformed by default. -
TLcdDataModelMapping
Constructs a new instance that automatically maps the given source model to the given target model (see alsomapDataModel(TLcdDataModel, TLcdDataModel...)
). Properties on the source data withnull
value will not be transformed by default.- Parameters:
aSourceModel
- a source modelaTargetModel
- a target model
-
TLcdDataModelMapping
public TLcdDataModelMapping(TLcdDataModel aSourceModel, TLcdDataModel aTargetModel, boolean aTransformEmptyProperties) Constructs a new instance that automatically maps the given source model to the given target model (see alsomapDataModel(TLcdDataModel, TLcdDataModel...)
).- Parameters:
aSourceModel
- a source modelaTargetModel
- a target modelaTransformEmptyProperties
- indicates whether the transformations, created by this data model mapping, should make an attempt to transform properties without a value. This may be useful if anull
value in the source data should be mapped onto a non-null default value in the target data.
-
-
Method Details
-
mapDataModel
Maps a source data model on one or more target data models. All types declared in the source data model will be automatically mapped (unless they are explicitly mapped, see
mapType(TLcdDataType, TLcdDataType, ILcdObjectTransformation)
) to a type with the same name from the target data models.Calling this method will never cause any explicit type mappings to be overridden.
- Parameters:
aSourceModel
- the source data modelaTargetModels
- the target data models
-
ignore
Marks the given type that it should not be automatically mapped, even if its declaring data model would be mapped. Also marks all properties of this type that they should not be automatically mapped.- Parameters:
aType
- the type to ignore
-
ignore
Marks the given property that it should not be automatically mapped, even if its declaring data model would be mapped.- Parameters:
aProperty
- the property to ignore
-
mapType
Maps the given source type on a type with the same name in the target data models. The source type should be a data object type.
Before this method is called, the source data model should already have been mapped on one or more target data models. Otherwise the implementation will not be able to find a target type and an IllegalArgumentException will be thrown.
- Parameters:
aSourceType
- the source type- Returns:
- the data type mapping that maps the source type on the target type
- Throws:
IllegalArgumentException
- when no target type could be found- See Also:
-
mapType
Maps the source type on the target type (and vice versa) using aTLcdDataTypeMapping
. The returned type mapping can be used to further control how properties are mapped from the source type to the target type. Both source and target type are assumed to be data object types. Calling this method overrides the default mapping done bymapDataModel(TLcdDataModel, TLcdDataModel...)
.- Parameters:
aSourceType
- the source typeaTargetType
- the target type- Returns:
- the data type mapping that maps the source type on the target type
- Throws:
IllegalArgumentException
- in case one of the parameters isnull
-
mapType
public void mapType(TLcdDataType aSourceType, TLcdDataType aTargetType, ILcdObjectTransformation aTransformation) Maps the source type on the target type using the given transformation.- Parameters:
aSourceType
- the source typeaTargetType
- the target typeaTransformation
- the transformation that maps the source on the target type
-
configure
Registers transformations for the configured mappings and for all types in themapped
source data models (if it is not explicitly ignored and if a target type could be found).- Parameters:
aTransformerSFCT
- the transformer to configure
-
getInverse
Returns the inverse of this mapping. The inverse mapping is typically used only in cases where a source type can be mapped on multiple target types. In such a case, sometimes transformations from a target type to a source type are needed that have no inverse. These transformations can be mapped on this object's inverse.- Returns:
- the inverse of this mapping
-