5.5 Mapper

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:

Figure 5.9. 


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:

Figure 5.10. 


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:

Figure 5.11. 


The next figure shows an inconsistency without possible redundancy, becaus the left-hand attribute emailAddress is mapped twice by the attributes lastName and emailAddress:

Figure 5.12. 


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:

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:

Example: