Integrating new formatter with other UDTT components
Generally speaking, it is suggested that you use the new formatter in your application. The new formatter is an independent component, you can use it anywhere whenever you need it. There are two ways to integrate new formatter with other toolkit components.
Using FormatFacade
The following example demonstrates how to use FormatFacade in other toolkit components:
public class FormatFacade { public static byte[] formatContext(String formatID, Context ctx) throws FormatterException { ReadAdapter adapter = new ContextReadAdapter(ctx); FormatElement format = FormatFactory.getFormatElement(formatID); Message message = format.format(adapter); return message.toBytes(); } public static void unformatContext(String formatID, byte[] data, Context ctx) throws FormatterException { WriteAdapter adapter = new ContextWriteAdapter(ctx); FormatElement format = FormatFactory.getFormatElement(formatID); format.unformat(new Message(data), adapter); } }
Using FormatAdapter
Sometimes, you cannot use the new formatter directly. In this case, you can use FormatAdapter to integrate the new formatter with other toolkit components.
▪ Configure old formatter component to create FormatAdapter:
You need to configure the old formatter component and new formatter to use the same definition file, and configure the old formatter to create FormatAdapter when necessary. Following is an example:
In this example, externalizer in the old formatter component creates the a FormatAdapter when the root tag is format.
▪ Define new FormatElement:
Then you need to define FormatElement in the way of new formatter component. The root tag is different with the old formatter. In the old formatter component, the root tag can only be fmtDef. But in the new formatter component, you can configure the root tag in classTable.
In this way, the format instance is created from FormatElement. FormatElement.readObject("sampleFmt") is an instance of com.ibm.btt.format.impl.FormatAdapter. FormatAdapter extends com.ibm.btt.base.FormatElement and it delegates all the logic to the new formatter component.