Extending formatters

About this task

To create a formatter, do the following:

Procedure

  1. Create a class such as MyFormat by subclassing from FormatElement or any of its subclasses.
  2. 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.

  3. Create the class constructors such as myFormat(), and myFormat(String).
  4. Override the initializeFrom(Tag) method. This method initializes the formatter with the attributes defined in an external definition file.
  5. Create the getters and setters for the formatter attributes.
  6. Override the format method to convert the passed object into a formatted string that conforms to your requirements.
  7. Override the unformat method to convert the string into an object that conforms to your requirements.
  8. 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.
  9. Override the toString() method to provide a visual representation of your formatter.

Results

The com.ibm.btt.base package contains the provided formatters, which you can also use as a reference when building a new formatter.