Runtime tools : Core components : Formatters : Concepts : Formatter overview
  
Formatter overview
The following diagram shows the components in the formatter:
Components in the formatter
FormatElement
The UNICOM® Digital Transformation Toolkit (UDTT™) Formatter provides a set of FormatElements. All the FormatElements implement the interface com.ibm.btt.formatter.FormatElement. A FormatElement knows how to format or unformat its corresponding type of Node in the structured data. For example, StringFormatElement knows how to format or unformat a String filed in the structured data, and RecordFormatElement knows how to format or unformat a Composite Node in the structured data.
Besides the FormatElement provided by the toolkit, you can implement your own FormatElement according to your requirements.
Formatter Definition
A Formatter Definition is defined in an XML file. It has the same structure with the corresponding structured data. Following is a sample definition for the structured data:
<formatter id="PersonFormatter">
  <record>
    <jInteger dataName="age" size="2"/>
    <jString dataName="name" size="8"/>
    <record dataName="address">
      <jString dataName="number" size="5"/>
      <jInteger dataName="street" size="20"/>
    </record>
  </record>
</formatter>
Each node in the XML presents a FormatElement. And the tag name stands for the class name of the FormatElement. For example, record stands for com.ibm.btt.format.impl.RecordFormat, while jInteger stands for com.ibm.btt.format.impl.IntegerFormat. And the related class name for each tag name is customized in btt.xml.
Formatter
Formatter is a composite instance of FormatElement. It can be created using FormatFactory by the ID from the formatter definition. While Formatter is an instance composited with FormatElement, it complies with Composite pattern (GOF). FormatFactory is responsible for creating the Formatter instance, and there is only one formatter instance for each ID as shown in the following diagram:
Formatter instance: PersonFormatter
For each node in the definition, FormatFacade will create an instance of FormatElement corresponding to the tag name of the node. And the created node will be added to its parent FormatElement according to the tree structure of the XML node. Meanwhile, the attribute defined in the XML file will be populated to the corresponding FormatElement instance.
Data Adapter
Data Adapter is an abstract layer to read and write the structured data. Instead of accessing the structured data object directly, Formatter will access it through Data Adapter. It helps to protect Formatter algorithm from the various types of structured data such as BTTContext, SDO, JavaBean and so on. If you want to support a new kind of structured data, you only need to implement a Data Adapter for the structured data.
FormatFactory
Given a Formatter ID, FormatFactory will search the Formatter Definition for the ID. If the ID does not exist, the FormatFactory will create a Formatter instance from the Formatter Definition. FormatFactory will also hold a cache of the Formatter instance, to make sure that there is only one instance of Formatter for each Formatter ID.
Go up to
Concepts