Coding the extensions to the toolkit

The following is an example of how to add the code for the new data element HostField defined as an extension to the toolkit entity definitions.

To define a new data element with the behavior required for the HostField data element, create a new class called HostField that extends DataField (see Extending data elements). This class adds an attribute that represents the backend system field identifier, as follows:

class HostField extends DataField { 
    String hostIdentifier; 
} 

Add the corresponding setter and getter methods, setHostIdentifier() and getHostIdentifier().

To enable initialization of the object from its definition in the entity definition file, override the initializeFrom method to parse the new hostId tag. The new method is implemented as follows:

public Object initializeFrom(Tag aTag) throws java.io.IOException {

  super.initializeFrom(aTag); 
  for (int i=0;i<aTag.getAttrList().size();i++) { 
    TagAttribute attribute = (TagAttribute)
Tag.getAttrList().elementAt(i); 
    if (attribute.getName().equals("hostId"))
setHostIdentifier((String) 
        (attribute.getValue())); 
  } 
  return this; 
} 

The new formatters, HostDecorator and HostStringFormat, are also coded to extend the toolkit. Browse the com.ibm.dse.samples.appl package to see the classes HostStringFormat and HostDecorator class implementations.

Note: In the format used for building the backend system message, the AccountNumber and BranchId fields are formatted using this special format (the fHostString tag corresponds to the HostStringFormat class), while the date and amount are formatted using the decorator (the fHostDecor tag corresponds to the HostDecorator class).