A mapper maps the properties of 2 different dataviews. A mapper has a name, a left and a right dataview and in between of the two dataviews it has a mapping direction. The following figure illustrates these minimum reuqirements of a mapper:
By default, a mapper maps only those attributes which match by their name, irrespective of their datatypes. A string property could be mapped to another string property or to an Integer property if only the two properties match by name. The default mapping could be overridden by so called property mappings within the body of a mapper. As soon as one or more property mappings are defined, the default mapping behaviour of the mapper is disabled and only the mapping rules defined with the help of the current property mappings count. A property mapping consists of a left attribute, taken from the left dataview of the mapper, a mapping direction and a right attribute, taken from the right dataview of the mapper. Here is an example:
Property Mappings must be consistent. Therefore, the same attribute either on the left or right side, must not be mapped twice by one or more opposite attributes. Or in other words: There must only be one property mapping which points the mapping direction to one attribute. Otherwise an attribute may be mapped twice, which does not make sense. In the following example, the left attribute emailAddress is mapped twice by the same attribute on the right side called emailAddress. Although one could consider this particular case as a redundancy the framework makes an error:
The next figure shows an inconsistency without possible redundancy, becaus the left-hand attribute emailAddress is mapped twice by the attributes lastName and emailAddress:
Because the default mapper behaviour maps between different datatypes, the generated mapper logic is capable of converting datatypes. Here is a taxative list of datatypes and their convertable counterparts:
Integer maps to (no mapping of Integer to: Boolean, Date, Timestamp):
String
BigDecimal
Double
Float
Integer
Long
Date maps to (no mapping of Date to: Integer, Double, Float, Boolean):
String
Date
BigDecimal
Long
Timestamp
BigDecimal maps to (no mapping of BigDecimal to: Boolean):
String
Date
BigDecimal
Double
Float
Integer
Long
Timestamp
Boolean maps to:
Boolean
String
outcome: "true" or "false"
Double maps to (no mapping of Double to: Boolean, Date, Timestamp):
String
BigDecimal
Double
Float
Integer
Long
Float maps to (no mapping of Float to: Boolean, Date, Timestamp):
String
BigDecimal
Double
Float
Integer
Long
Long maps to (no mapping of Long to: Boolean):
String
BigDecimal
Double
Float
Integer
Long
Timestamp
Date
Timestamp maps to (no mapping of Timestamp to: Integer, Double, Float, Boolean):
String
Date
BigDecimal
Long
Timestamp
String maps to:
Boolean
(true Strings: "true", "yes", "y", "on", "1")
(false Strings: "false", "no", "n", "off", "0")
String
BigDecimal
Double
Float
Integer
Long
Timestamp
Date
If the mapper is not able to execute a datatype conversion between
two different datatypes it will throw an
org.apache.commons.beanutils.ConversionException.
These are the steps to call a mapper:
inject the
org.openxma.dsl.platform.service.Mapper interface:
@Autowired private Mapper mapper;
create a java.util.Map with a
java.lang.String as the key and an optional object of
type org.openxma.dsl.platform.service.MapperConfig as
the value. The key must be of the following pattern:
"mapper:"+mapperName. The mapper name is specified in
the dom model. The MapperConfig should be used in case when the
mapper maps from Date,Timestamp to String or vice versa!
call any suitable method on the injected Mapper which takes a param named context, and put the created map from above as the methods context param
Example: