Extending decorators

Decorators can be easily extended according to the customer needs. To create a new decorator, follow these steps:
  1. Create a new class such as MyDecorator by subclassing from FormatDecorator 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 otherDecorator decorator with the MyDecorator class:
    <field id=otherDecorator value=myPackage.MyDecorator>
  3. Create the class constructors such as myDecorator() and myDecorator(String).
  4. Override the initializeFrom(Tag) method. This method instantiates the decorator with the attributes specified in an external definition file.
  5. Create the getters and setters for the decorator attributes.
  6. Override the addDecoration(String) method modify the string according to your requirements.
  7. Override the removeDecoration(String) method to modify the string according to your requirements by removing the decoration.
  8. Override the extract(String) method. This method is called by the removeDecoration() method of each decorator to extract from the provided string the part that it is able to process. This method returns an array of two strings. The first string is the string from which it will remove the decoration and the second is the remainder of the provided string.
  9. Override the toString() method to provide a visual representation of your decorator.

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