Runtime components : Core components : Contexts : Tasks : Customizing contexts : Defining contexts
  
Defining contexts
Contexts are externalizable objects, which means that the toolkit can create them from definitions in the context, data, and type definition files stored outside of the system. You can edit these files using any ASCII editor. For more information on externalizable objects, see Externalizers. Contexts created from external definitions are static and you declare them at installation or configuration time. Using external definition files to create contexts does not preclude creating other contexts dynamically during the runtime of the application.
To define a static context, use external definitions as shown in the following example. The first definition defines the myBranch context and the second definition defines a myWorkstation context and chains it to the myBranch context. The first definition also initializes an element (branchId) of the context's keyed collection with a value.
<context id=" myBranch" type="branch" parent="null">
  <refKColl refId="myBranchData">
    <iniValue name="branchId" value="Branch125"/>
  </refKColl>
  <refService refId="realCSClient" type="client" alias="real"/>
  <refService refId="printerService" type="service" alias="printer"/>
</context>
<context id="myWorkstation" type="workstation" parent=" myBranch">
  <refKColl refId="myWorkstationData">
  </refKColl>
  <refService refId="msreService" type="service" alias="msre"/>
</context>
Note Each context has references to data and services, which you declare in the data and services definition files.
Example data definition
<kColl id="myBranchData">
  <field id="branchId"/>
  <field id="field2"/>
  <refData refId="indexCollection"/>
</kColl>
<kColl id="indexCollection">
  <field id="field1"/>
</kColl>
<kColl id="myWorkstationData">
  <field id="field1"/>
  <field id="field2"/>
</kColl>
Example service definition
<CSClient id="realCSClient"/>
<!-- WOSA service used in the WOSA printer sample-->
<WOSADevice id="printerService" logicalName="TESTSPI"
deviceType="DSEWPTR" timeout="0" SPMMinVersion="1.00"
SPMMaxVersion="2.00" traceLevel="1"/>
See
Managing service in context lifecycle
Defining root context
Chaining to parent context automatically
Go up to
Customizing contexts