The com.ibm.dse.base.Context class provides methods for managing the resources in a context (such as adding and removing data elements and services), managing the context tree (such as chaining and unchaining to contexts and getting the parent context), and for retrieving specific context instances.
Avoid using "currentContext" and "currentChild" contexts: having several processes chain contexts in parallel may return inconsistent results to the application. Make sure that you do confuse this with the current context for a client/server session identifier, which actually returns the corresponding instance of the context related to that session.
For examples of how you can work with contexts, see the following sections.
Updating the data elements of a context's keyed collection
To show how to update a data element of a context's keyed collection, the example code assumes that the definition files contain the following definitions:
To reset a context keyed collection so that part or all of the keyed collection re-initializes with values from external definition files, invoke the clearKeyedCollection method in the Context class. This method resets the current context's keyed collection based on the following rules:
▪ If the dsedata.xml file contains the definition for the context keyed collection, the method uses the DataElement.readObject method to reinitialize the keyed collection.
▪ If the dsetype.xml file contains the definition for the context keyed collection defined as a Type, the method uses the DSEType externalizer to re-initialize the type.
▪ If neither the dsedata.xml file nor the dsetypes.xml file contains the definition and any of the two parameters or both are set to false, the method throws an IOException. Otherwise, the method does the following depending on the values of the parameters:
How clearKeyedCollection re-initializes the context keyed collection
keepKCollStatus = true clearOnlyValues = true
Re-initializes only the values of the data elements inside the keyed collection. The method does not affect the data element attributes. If the keyed collection has dynamically added elements, this re-initialization does not change them in any way.
If the method does not find an external definition for the keyed collection, the method considers all the data elements as dynamic data elements and does not change them in any way. The method also retains the keyed collection attributes.
keepKCollStatus = true clearOnlyValues = false
Re-initializes the attributes and values of the data elements in the keyed collection. The method does not re-initialize keyed collection attributes such as ErrorInfo, State, and Parameters. If the keyed collection has dynamically added elements, this re-initialization removes them.
If the method does not find an external definition for the keyed collection, it throws an IOException.
keepKCollStatus = false clearOnlyValues = true
Re-initializes the attributes of the keyed collection and the data element values without changing the rest of the data element attributes. If the keyed collection has dynamically added elements, this re-initialization does not change them in any way.
If the method does not find an external definition for the keyed collection, it throws an IOException.
keepKCollStatus = false clearOnlyValues = false
Re-initializes the context without preserving attributes and values. If the keyed collection has dynamically added elements, this re-initialization removes them.
If the method does not find an external definition for the keyed collection, it throws an IOException.