The data element classes can be easily extended to support application needs. For example, to extend a data field with the myAttribute instance variable, follow these steps:
1 Create a new class, for example, MyDataField extending DataField.
2 In the configuration file for the client, add the relationship between the class name and the tag name.
For example, the following data field definition would be added to the keyed collection of data definitions in the btt.xml file:
Depending on how the processes using this data field are distributed, the definition may need to exist in the configuration files for both the client and the server.
Alternatively, you can use implClass attribute to specify the class when you are defining an instance of the new entity in the data definition file. For example, you could add the following definition to the data file:
Since you have already specified the implementation class name, you do not need to add the mapping between the tag name "otherType" and the class name "myPackage.MyDataField" in the tags keyed collection of btt.xml.
3 In MyDataField, create a variable such as myAttribute to hold the new attribute.
4 In MyDataField, create the getter and setter methods for the new variable such as setMyAttribute and getMyAttribute.
5 In MyDataField, override the initializeFrom(Tag) method.
This method instantiates the object with its attributes specified in the XML file. For example:
/** * Initialize MyDataField with the Tag attributes. * @return java.lang.Object * @param aTag com.ibm.btt.base.Tag * @exception java.io.IOException */ public Object initializeFrom(Tag aTag) throws java.io.IOException { value = null; super.initializeFrom(aTag); for (int i=0; i<aTag.getAttrList().size(); i++) { TagAttribute attribute = (TagAttribute) aTag.getAttrList().elementAt(i); if (attribute.getName().equals("myAttribute")) { setMyAttribute((String)(attribute.getValue())); } } return this; }
6 In MyDataField, override the toString() method.
This method gives a visual representation of the object. For example: