Runtime tools : Core components : Formatters : Tasks : Handling binary message : Handling different kinds of Data Object : Handling UDTT Context
  
Handling UDTT Context
This section describes how to handle UDTT Context:
1 Defining data element:
Following is the sample definition of data element:
<data.xml>
  <kColl id="personData">
    <field id="name" />
    <field id="age" />
  </kColl>
</data.xml>
2 Defining context:
Following is a sample definition of context:
<context.xml>
  <context id="sampleContext" type="op">
    <refKColl refId="personData" />
  </context>
</context.xml>
3 Defining format element:
Following is the sample definition of format element:
<format.xml>
  <format id="PersonFormat">
    <record>
      <fString dataName="name" encoding="cp937"/>
      <selfLength/>
      <fInteger dataName="age" byteOrdering="host"/>
      <selfLength/>
    </record>
</format>
</format.xml>
4 Formatting the context:
Following is the sample code to format the UDTT context:
public static void main(String[] args) throws Exception {
Context context = ContextFactory.createContext("sampleContext");
context.setValueAt("name", "George. Wilhelm. T");
context.setValueAt("age", 57);
FormatElement format = FormatFactory.getFormatElement("PersonFormat");
ReadAdapter read = new ContextReadAdapter(context);
Message msg = format.format(read);
System.out.println("====Format Result====");
System.out.println(msg);
}
If you run this main method, you can get the following result in the console:
Read BTT configuration from : "jar:///btt.xml"
Initialize BTT Component: traces
Initialize BTT Component: traces [Success]
Initialize BTT Component: dataElement
Initialize BTT Component: dataElement [Success]
Initialize BTT Component: context
Initialize BTT Component: context [Success]
Initialize BTT Component: format
Initialize BTT Component: format [Success]
4 BTT Components initialized.
====Format Result====
12C785969987854B40E68993888593944B40E30400000039
5 Unformatting the context:
Following is the code sample to unformat the UDTT context:
public static void main(String[] args) throws Exception {
Context context = ContextFactory.createContext("sampleContext");

FormatElement format = FormatFactory.getFormatElement("PersonFormat");
WriteAdapter write = new ContextWriteAdapter(context);
byte[] bytes = HexCodecUtil.decodeHex("06C785969987850400000012".toCharArray());
Message message = new Message(bytes);
format.unformat(message, write);
System.out.println("====Unformat Result====");
System.out.println(context.getKeyedCollection());
}
If you run this main method, you can get the following result in the console:
Read BTT configuration from : "jar:///btt.xml"
Initialize BTT Component: traces
Initialize BTT Component: traces [Success]
Initialize BTT Component: dataElement
Initialize BTT Component: dataElement [Success]
Initialize BTT Component: context
Initialize BTT Component: context [Success]
Initialize BTT Component: format
Initialize BTT Component: format [Success]
4 BTT Components initialized.
====Unformat Result====
<kColl id="personData" dynamic="false" compress="false">
<field id="name" value="George" description="" />
<field id="age" value="18" description="" />
</kColl>
Go up to
Handling different kinds of Data Object