Setting conditions on the property value

The AgentProperty class provides the ability to define conditions on an agent property. A condition can restrict the values of one agent property, called a dependent property, based on the value of another agent property. A condition has two parts, each part a particular kind of subcondition, as Table 53 shows.

Table 53. Parts of an agent-property condition

Subcondition Description ODK API class
Input condition Defines a condition on the current agent property's value InputCondition
Dependent condition Defines a condition that must be met on the dependent property when the associated input condition evaluates to true DependentCondition

Defining the complete condition

To represent a condition, the ODK API defines a complete-condition object, which is an instantiation of the CompleteCondition class. Table 54 shows the member variables that a complete-condition object contains.

Table 54. Contents of a complete-condition object

Member variable Description
allInputConditions
An array of input-condition (InputCondition) objects, each object defining one condition on the value of the agent property
allDependentConditions
An array of dependent-condition (DependentCondition) objects, each object defining one restriction on the value of a dependent property. This restriction applies to the dependent property's value when the associated input conditions (in the allInputConditions array) evaluate to true.

A complete-condition object contains the information that describes a single condition on an agent property. An agent property can have many conditions defined on it. Each condition's complete-condition object is stored in the allDependencies member variable of the agent property's AgentProperty object.

To create one condition on an agent property, take the following steps:

  1. Instantiate a CompleteCondition object to hold the condition information.
  2. Instantiate the appropriate InputCondition objects to describe input conditions for the agent property. Save each InputCondition object in the input-conditions array (allInputConditions member variable) of the complete-condition object. For more information about input conditions, see Defining input conditions.
  3. Instantiate the appropriate DependentCondition objects to describe dependent conditions for the agent property. Save each DependentCondition object in the dependent-conditions array (allDependentConditions member variable) of the complete-condition object. For more information, see Defining dependent conditions.
  4. Save the complete-condition object in the agent property's condition array. The allDependencies member variable of the agent-property object contains this condition array.

Defining input conditions

The InputCondition class represents an input condition, which describes a condition on the current agent property's value. When an input condition evaluates to true, the associated dependent conditions are applied to the dependent agent property. Table 55 shows the information needed to define an input condition.

Table 55. Information for an input condition

Input-condition information Description InputCondition
member variable
Operator The kind of comparison to make on the agent-property value. A comparison is indicated as a relational operator and is specified as one of the operator constants in the CompleteCondition class. operatorType
Specific value The value with which to compare the agent property's value. This value can be a constant or the name of another agent property. specificValue, typeOfSpecificValue
Whether the comparison of the agent property's value is performed dynamically A boolean value to indicate whether to compare the current agent property's value with another property's value dynamically. Comparisons that involve constants do not require dynamic comparisons. isDynamic

To create an input condition, use one of the forms of the InputCondition() constructor. The code fragment in Figure 74 creates input conditions that compare the agent-property value with two constant string values, "optionA" and "optionB". You can also compare the agent-property value with some other property's value. The code fragment in Figure 72 creates an input condition to compare an agent property's value with the value currently in the Property2 agent property.

Figure 72. Input condition to compare a property value with another property's value

// Instantiate a complete-condition object
 condition1 = new CompleteCondition();
 
// Input condition to compare property value with Property2's value
 condition1.allInputConditions[0] = new InputCondition(
    CompleteCondition.OP_NOT_EQUAL, true, AgentProperty.TYPE_INTEGER, "Property2"); 
 

In Figure 72, the isDynamic member variable is set to true so that Business Object Wizard knows to first obtain the current value of the Property2 property before comparing the user-specified value with this value. In addition, the specificValue is set to "Property2", the name of the property against which the comparison is made. As a result of this input condition, the dependent conditions for the property apply only if this property's value is not the same as Property2's value.

Defining dependent conditions

The DependentCondition class represents a dependent condition, which describes a restriction on the value a particular dependent property. A dependent property is a property whose value in some way depends on the current property's value. When the associated input condition (or conditions) evaluates to true, the dependent property's value must meet the restriction that the dependent condition specifies. Table 56 shows the information needed to define a dependent condition.

Table 56. Information for a dependent condition

Dependent-condition information Description DependentCondition
member variable
Name The name of the dependent property to which the dependent condition applies if the associated input condition (or conditions) evaluates to true. propertyName
Operator The kind of comparison to make on the dependent-property value. A comparison is indicated as a relational operator and is specified as one of the operator constants in the CompleteCondition class. operatorType
Specific value The value with which to compare the dependent-property value. This value can be a constant or the name of another agent property. specificValue, typeOfSpecificValue
Whether the comparison of the user-specified value is performed dynamically A boolean value to indicate whether to compare the dependent property's value with another property's value dynamically. Comparisons that involve constants do not require dynamic comparisons. isDynamic

To create a dependent condition, use one of the forms of the DependentCondition() constructor. The code fragment in Figure 74 creates the following dependent conditions:

You can also compare the dependent-property value with some other property's value. The code fragment in Figure 73 creates a dependent condition to compare a dependent property's value with the value currently in the Property2 agent property.

Figure 73. Dependent condition to compare a property value with another property's value

// Dependent condition to compare property value with Property2's value
 condition1.allDependentConditions[0] = new DependentCondition(
    CompleteCondition.OP_EQUAL, true, AgentProperty.TYPE_INTEGER, "Property2"); 
 

In Figure 73, the isDynamic member variable is set to true so that Business Object Wizard knows to first obtain the current value of the Property2 property before comparing the dependent property's value with this value. In addition, the specificValue is set to "Property2", the name of the property against which the comparison is made.

Defining a sample condition

Suppose that you want to define conditions on an agent property (Property1) that specifies restrictions on two dependent properties, based on values of Property1, as follows:

Figure 74 shows the code that implements these two conditions.

Figure 74. Defining two agent-property conditions

// 1. Instantiate the complete-condition object
 condition1 = new CompleteCondition();
 
// 2. Create the condition on the "optionA" value
 //   a) Instantiate the input condition on "optionA"
    condition1.allInputConditions[0] = new InputCondition(
       CompleteCondition.OP_EQUAL, false, AgentProperty.TYPE_STRING,
       "optionA");
 
//   b) Instantiate the dependent conditions for DepProperty1
    condition1.allDependentConditions[0] = new DependentCondition(
       "DepProperty1", CompleteCondition.OP_EQUAL, false, 
       AgentProperty.TYPE_INTEGER, "0"); 
 
   condition1.allDependentConditions[1] = new DependentCondition(
       "DepProperty1", CompleteCondition.OP_EQUAL, false, 
       AgentProperty.TYPE_INTEGER, "1");
 
   condition1.allDependentConditions[2] = new DependentCondition(
       "DepProperty1", CompleteCondition.OP_EQUAL, false, 
       AgentProperty.TYPE_INTEGER, "256");
 
   condition1.allDependentConditions[3] = new DependentCondition(
       "DepProperty1", CompleteCondition.OP_EQUAL, false, 
       AgentProperty.TYPE_INTEGER, "512");
 
// 3. Instantiate the next complete-condition object
 condition2 = new CompleteCondition();
 
// 4. Create the condition on the "optionB" value
 //   a) Instantiate the input condition on "optionB"
    condition2.allInputConditions[0] = new InputCondition(
       CompleteCondition.OP_EQUAL, false, AgentProperty.TYPE_STRING,
       "optionB");
 
//   b) Instantiate the dependent conditions for DepProperty2
    condition2.allDependentConditions[0] = new DependentCondition(
       "DepProperty2", CompleteCondition.OP_GREATER_THAN_EQUAL, false, 
       AgentProperty.TYPE_INTEGER, "1"); 
 
   condition2.allDependentConditions[1] = new DependentCondition(
       "DepProperty2", CompleteCondition.OP_LESS_THAN_EQUAL, false, 
       AgentProperty.TYPE_INTEGER, "5");
 
// Save conditions in the agent-property object
 agentProp.allDependencies[0] = condition1;
 agentProp.allDependencies[1] = condition2;
 

Copyright IBM Corp. 1997, 2004