Data Mapper Bundle

The Data Mapper Bundle provides a tool for converting byte arrays to Java objects and vise versa.

Contents:


Bundle Information

Bundle JAR

The Data Mapper Bundle is packed in the datamapper.jar file, located in the bundles directory of Framework Professional Edition Package.

Import

Package Exporter Description
com.prosyst.util.xml ProSyst Util Bundle/
ProSyst Util Full Bundle
Classes for reading and processing XML documents..
net.sourceforge.jeval JEVAL-ProSyst Bundle Holds the classes of the JEval library.

Export

The Data Mapper Bundle exports com.prosyst.mbs.services.datamapper package. It provides an API for to using the Data Mapper functionality.

Main Features

Data Mapper can convert an input byte array into a Dictionary holding objects of basic Java types and vise versa. It can also convert a Dictionary of byte arrays into a Dictionary of Java objects. Special XML files define the rules according to which Data Mapper performs each conversion. For details on creating data mapping XMLs, refer to the "Providing a Data Mapping XML " section.

Data Mapper provides an universal way to access the data from different types of networks and communication protocols in Java applications. For example, you can use Data Mapper to create XML-based device drivers for EHS and EIB based systems without need to implement any Java code. Another example of its usage is to access the data available in a CAN bus.

Data Mapper Architecture

The figure below depicts the modules structuring the Data Mapper:


Figure1: Data Mapper architecture model

Mapping Parser

Mapping Parser generates a structure of Java objects out of each data mapping XML and stores this structure for late usage. It uses the ProSyst XML Utilities to process the data mapping XMLs.

Data Mapping

A structure of objects representing a data mapping XML.

Data Mapper

The core unit of the Data Mapper module. It uses the stored Data Mappings to generate Dictionary of Java objects out of bite arrays and vise versa.

Expression Evaluator

It evaluates conditions and mathematical expressions using the mathematical evaluator provided by the JEval library. The JEval library is delivered by the JEVAL-ProSyst bundle. The Expression Evaluator also uses the default implementation of a Custom Function Evaluator to perform byte extracting and decode operations.

Custom Function Evaluator

Custom functions allow applications to insert custom functionality into the mathematical expressions Data Mapper operates with.

Providing a Data Mapping XML

When initially started, Data Mapper does not have any data mapping XMLs, therefore third party bundles must supply it with such. There can be different data mapping XMLs depending on the data formats they are intended for. As an instance, you can provide data mapping XMLs created according to the EHS and EIB data format specifics.

XML DTD

DTD Elements Description
<!ELEMENT mapper (const*, var*, mapper_in, mapper_out)> Starts the data mapping XML. It includes one mapper_in and one mapper_out elements. Optionally, it can have one or more const and var elements representing constants and variables that are global for the whole XML document.
<!ELEMENT const (value)> Defines a constant with a given value.
<!ELEMENT var (value?)> Defines a variable that can optionally have a value.
<!ELEMENT value (#PCDATA)> Represents a general purpose value.
<!ELEMENT mapper_in (var*, mapping*)> Describes data mappings when creating a Dictionary holding Java objects out of a byte array. Optionally, it can have one ore more var and mapping elements.
<!ELEMENT mapper_out (var*, mapping*)> Describes data mappings for generating byte array out of a Dictionary holding Java objects. Optionally, it can have one ore more var and mapping elements.
<!ELEMENT mapping (condition?, map+)> Represents a data mapping unit. It has an optional condition element and one or more map elements. Each map element represents a key-value pair that will be included in the output Dictionary. If there is a condition element, the data mapping will be included in the output Dictionary only when the corresponding condition becomes satisfied.
<!ELEMENT condition (#PCDATA)> Represents a condition that has to be satisfied in order to include a data map in the output Dictionary or byte array.
<!ELEMENT map (var*, (value | case+))> Represents a key-value pair of objects in the output Dictionary. It can have zero or more var elements specifying variables which are valid locally for the map element. It also has a value element or one ore more case elements. The value is an expression including simple mathematical operations and functions. The possible mathematical operators are:

+, -, *, /, %, ==, >=, <=, >, <, |, &, !, ^, <<, >>, >>>.

Currently supported functions are:
  • Byte/bit extract - It has several formats: [a], [a..b], [a]{x}, [a]{x..y}, [a..b]{x..y}, [a;c]. Refer to the next section for detailed description of these formats.
  • "hasvar" - The usage format is "hasvar.<var_name>". It is a boolean function that indicates weather there is a variable with a given name in the input Dictionary. For example, if there is a variable with name "somename" in the input Dictionary, the function will be become "true", if there is not - it will turn into "false".
When the value of the map varies depending on some condition, you should use case instead of value. It has the following format of usage:
<case>
<condition>
some condition</condition> <value>some value</value>
</case>
A map element can include as many case elements as needed. When processing such a map, Data Mapper checks subsequently the conditions and stops at the first one that is fulfilled. The corresponding value is put in the output Dictionary as a value for this map. If there is no matching conditions, no entry is generated for the output Dictionary from this map.
<!ELEMENT case (condition, value)> Includes one condition and one value elements. It indicates that if certain condition is satisfied, then the corresponding value will take part in the output Dictionary.
<!ATTLIST mapper    
name CDATA #REQUIRED pid CDATA #REQUIRED>
  • name - The data mapping XML user-friendly name
  • pid - The data mapping XML PID
<!ATTLIST const 
name CDATA #REQUIRED type CDATA #REQUIRED>
  • name - The constant's name
  • type - The constant's type
<!ATTLIST var 
name CDATA #REQUIRED type CDATA #REQUIRED>
  • name - The variable's name
  • type - The variable's type
<!ATTLIST map 
name CDATA #REQUIRED
type CDATA #REQUIRED>
  • name - The data map's name
  • type - The data map's type

Scheme

Variables defined in the mapper element of the XML are called scheme and have a special function. They define how the bytes of the original byte array should be interpreted in the output Dictionary. The scheme must exists when generateRawData and processRawData methods of the Data Mapper service are called.

Variables included in the scheme must obey to the following rules:

Note: A variable with no value specified in the XML means that it must be taken from the input Dictionary. This in is case of generating a byte array out of Dictionary holding Java objects.

Example Data Mapping XML

For example, a data mapping XML can look like this:

<!DOCTYPE mapper SYSTEM "mapper_dtd.dtd"> <mapper name="DataMapperExample" pid="datamapper.example">
<!-- Scheme -->
<
var name="frame" type="byte[]"></var>
<
var name="type" type="int"> <value><![CDATA[var.frame[0]]]></value> </var>
<
var name="data" type="int"> <value><![CDATA[var.frame[1]]]></value> </var>
<!-- Generating a Dictionary of Java object out of a byte array -->
<mapper_in> <mapping> <condition><![CDATA[ var.type == 1]]></condition> <map name="exampleMap" type="int"> <value><![CDATA[ var.data * 2 ]]></value> </map> </mapping> </mapper_in> <!-- Generating a byte array out of a Dictionary of Java objects>
<
mapper_out> <!-- The value of these variables will be taken from the input Dictionary --> <var name="action" type="int"></var> <var name="sourcedata" type="int"></var>
<
mapping> <condition><![CDATA[ var.action == 0]]></condition> <!-- Defining scheme variables --> <map name="type" type="int"> <value><![CDATA[ 0 ]]></value> </map> <map name="data" type="int"> <value><![CDATA[ var.sourcedata ]]></value> </map> </mapping> </mapper_out> </mapper>

Listing 1: Data mapping XML

Data Mapper Manifest Header

Bundles that provide data mapping XMLs should have the following header in their manifest specifying the XML PIDs and names:

Data-Mapping: xml=<xml_name>;pid=<xml_pid> [, xml=<xml_name>;pid=<xml_pid>]

For example:

Data-Mapping: xml=myDataMapping_1.xml; pid=my.data.mapping.1, xml=myDataMapping_2.xml; pid=my.data.mapping.2, xml=myDataMapping_3.xml; pid=my.data.mapping.3

Services

Data Mapper Service

The Data Mapper service provides means to using the Data Mapper functionality. It is registered under the com.prosyst.mbs.services.datamapper.DataMapper interface. For details on the methods provided by the service, refer to the Data Mapper API documentation.

Custom Function Evaluator Service

The Custom Function Evaluator service provides means to create custom functions. It is registered under the com.prosyst.mbs.services.datamapper.CustomFunctionEvaluator interface. For details on its usage, refer to the Data Mapper API documentation.

To provide custom functions in an application, you just have to implement the evaluate method and register a Custom Function Evaluator service in the framework.

System Properties

System Property Default Value Description
mbs.datamapper.debug false Turns on/off debugging of Data Mapper.

Data Mapper Demo

Data Mapper demo provides a simple data mapping XML and performs data conversion according to it on both the directions: it creates a Dictionary of Java objects out of a short byte array and vise versa.

The JAR file of the Data Mapper demo is datamapperdemo.jar and is located in the demo/bundles directory. The other components of the demo are placed in demo/framework/datamapper folder. You can conveniently install and start the demo from its Kit Manager script.

References


Utility Bundles