Runtime components : Core components : Formatters : Concepts : Built-in FormatElements : Format Decorator
  
Format Decorator
Formatter decorator follows the DECORATOR design pattern. You can add decorators for each format element. The decorator needs to be defined right after the format element. Every Format Decorator is a subclass of com.ibm.btt.format.BaseDecorator.
Following is a sample definition:
<format.xml>
  <format id="PersonFormat">
    <record>
      <fString dataName="name" encoding="cp937"/>
      <selfLength/>
      <fInteger dataName="age" byteOrdering="host"/>
      <selfLength/>
    </record>
  </format>
</format.xml>
Where, selfLength is a decorator. The first selfLength is decorator for fString. The second selfLenght is decorator for fInteger.
Decorator is used modify the binary message formatted by decorated format element and modify the binary message before the decorated format element unformat it.
Classes, Attributes and sample definitions of Format Decorator
 
ClassSample definition
Attributes
HexDelimiter
(Add a delimiter after the binary message)
<fInteger dataName="dInt" size="int" byteOrdering="pc"/>
<hexDelim hexDelimCharStr="DDDD" />
For example, if you format an integer value of -1024 with this format element, you will get the binary message: 00FCFFFFDDDD (hex value).
hexDelimCharStr:
a String that represents an array of hex values.
FixedLength
(Adjusts a formatted binary message to a fixed length by either truncating it or by padding and justifying it)
<fString dataName="name" encoding="cp937"/>
<fixedLength length="10" alignment="right"/>
For example, if you format a String “George” with this format element, you will get the binary message: 00000000C78596998785 (hex value). If you format a String “George. Wilhelm. T” with this format element, you will get the binary message: C785969987854B40E689 (hex value).
length:
an int value that indicates the length of the binary message.
default value is: 0.
padByte:
a byte in hex value representation. default value is: 00.
alignment:
optional values are: left, right.
default value is: left
MaximumLength
(Truncates the binary message if it is over the specified length. If the binary message is under the specified length, the decorator does not modify it)
<fString dataName="name" encoding="cp937"/>
<maxLength length="10"/>
For example, if you format a String “George. Wilhelm. T” with this format element, you will get the binary message: C785969987854B40E689 (hex value).
length:
a int value that indicates the maximum length of the binary message. default value is: 0.
NullCheckDecorator
(Handles conversions between binary message and data field when either the binary message is empty or the data field is null)
<fString dataName="name" encoding="cp937"/>
<nullCheck/>
For example, if you format a String which is null with this format element, you will get a binary message in 0 length. And if you unformat a binary message in 0 length, the format element will make no modification to the data field.
N/A
SelfLength
(Prefixes the length of the formatted binary message as an unsigned integer)
<fString dataName="name" encoding="cp937"/>
<selfLength/>
For example, if you format a String “George. Wilhelm. T”, you will get the binary message: 12C785969987854B40E68993888593944B40E3 (hex value).
size:
the length of prefix. default value is 1.
byteOrdering:
the byte ordering of prefix. optional values are: host, pc.
default value is: pc.
lengthIncluded:
whether to include the length of prefix when calculating the length of binary message. Optional values are: yes, no Default value is: no.
Go up to
Built-in FormatElements