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
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
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:
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
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.
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
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.
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;