To create a formatter, do the following:
- Create a class such as MyFormat by subclassing from FormatElement
or any of its subclasses.
- In the toolkit definition file, add the relationship between the
class name and the tag name. The following example associates
the otherFormat formatter with the MyFormat class:
<kColl id = "components">
<kColl id = "data">
<kColl id="classTable">
<field id="otherFormat" value="myPackage.MyFormat"/>
. . .
</kColl>
. . .
</kColl>
Depending on how you distribute the processes
using this formatter, you may need to add the definition to the toolkit definition
files for both the client and the server.
- Create the class constructors such as myFormat(), and myFormat(String).
- Override the initializeFrom(Tag) method. This
method initializes the formatter with the attributes defined in an external
definition file.
- Create the getters and setters for the formatter attributes.
- Override the format method to convert the passed object into a
formatted string that conforms to your requirements.
- Override the unformat method to convert the string into an object
that conforms to your requirements.
- Override the extract(String) method. The unformat method
of each formatter element calls this method to extract from the provided string
the part that it is unformat. This method returns an array of two strings.
The first string is the string that it is able to unformat and the second
is the remainder of the provided string.
- Override the toString() method to provide a visual representation
of your formatter.
The com.ibm.btt.base package contains the provided formatters,
which you can also use as a reference when building a new formatter.