About this task
To use data elements, do the following:
Procedure
- During the analysis and design of the application, identify
the data it needs.
- For each type of data, check whether the data definition
file or the processor self-defined file already contains a definition
that you can use.
- Create data structures for the application. Use
references for data elements that have already been defined elsewhere
or create data element definitions for the ones that have not. If
the data element is a keyed collection and the application needs to
add elements to it during runtime, set its dynamic attribute to true
- If the data is to appear in a context, include a reference
to it in the context keyed collection definition.
- Instantiate the data elements needed by the application. The toolkit automatically instantiates data elements belonging
to a context when it instantiates the context. You can instantiate
other data elements at any time by using the DataElement readObject(String)
method.
- To obtain the value of a data field, use the getValue()
method without parameters. To obtain the value of a data field inside
a collection, use the getValueAt(String key) method in which you pass
a simple or composite key.
- To set the value of a data field, use the setValue(Object)
method. If the data field is to be added to a dynamic keyed
collection, use the setValueAt(String, Object) method, where String
can be a simple or a composite key, and Object is the value of the
data field. Note that if the collection has its dynamic attribute
set to false and you pass in a data element name that does not exist
in the collection, an exception occurs.
Results
For more information on using data elements, see the Javadoc
for DataElement, DataField, DataCollection, KeyedCollection, and IndexedCollection.