Decision nodes

If you want one action to flow to the next regardless of conditions, a transition link is all that is necessary. If, however, you want to branch to more than one action based on a set of conditions, you need to include a decision node. In its most common usage, a decision node connects an action to all of its possible outcomes, including other actions, subdiagrams, and end symbols. Decision nodes can be used with the action, subdiagram, and iterator nodes. Do not place a decision node directly after a start symbol.

A decision node typically has at least two branches; the maximum number of branches is seven. Each branch has a condition associated with it that determines whether that branch is taken or not.
Important

When implementing a decision node, ensure that you define the conditions such that there will always be one that evaluates to true. If none of the conditions in your decision node evaluate to true, a runtime error occurs.

There are three types of branches in a decision node:

These branches are defined and their conditions set in the Decision Properties dialog box, as shown in Figure 31.

Figure 31. Decision Properties dialog box


Each defined branch of a decision node must have a transition link that connects it to its associated outcome (for example, an action node or a end symbol).

Figure 32 illustrates a sample activity diagram with a decision node. In this example, the decision node has three branches. The normal branch shifts the flow to Action 2 if its condition evaluates to true. The exception branch shifts the flow to End Failure if a JavaException exception is thrown. The default branch shifts the flow to Action 3 if the condition of the normal branch evaluates to false and a JavaException is not encountered.

Figure 32. Activity diagram with a decision node


Perform the following steps to add a decision node to your activity diagram:

  1. Ensure the diagram editor is open, and that you have already placed the symbol that is going to flow to the decision node. Decision nodes can be used by any action, subdiagram, or iterator node.
  2. Click the Decision Node button in the Symbols toolbar.
  3. In the diagram, position your cursor underneath the symbol that is going to use the decision node, and then click to place the node in the diagram.
  4. Create a transition link between the decision node and the symbol that calls it. See Creating a transition link for more information on creating transition links.

Defining a normal branch

Each normal branch requires a condition. These conditions are created with variables that you define in the collaboration template or the scenario. Before you can create a normal branch, you must define the necessary variable for the condition. See Declaring and editing template variables (the Declarations tab) and Defining scenario variables for more information.

Perform the following steps to define a normal branch in a decision node:

  1. In the activity editor, double-click the decision node symbol. The Decision Properties dialog box opens.
  2. In the row for the branch you are creating, click the table cell in the Type column and select Normal from the drop-down list of branch types.
  3. Right-click the table cell in the Condition column and select Condition Builder from the context menu.
    Note:
    You can also type the condition directly into the Condition table cell instead of using the Condition Editor.
    The Condition Editor dialog box is displayed.

    Figure 33. Condition Editor


  4. In the Variable Name field, use the drop-down list to select the variable you want to evaluate for the condition. This list contains all of the collaboration variables you have defined for the scenario.

    When you select a variable, the Data type field is automatically updated to include the variable type (for example, Boolean or String).

  5. In the Operator field, use the drop-down list to select the appropriate operator to use for evaluating the variable. The list contains only those operators supported by the type of variable you are using.
  6. In the Condition field, enter the value you want to use for the condition. (For example, if you have a Boolean variable named hasValue, you can set the condition to either true or false.)
  7. Click Ok to close the Condition Editor and return to the Decision Properties dialog box.
  8. Optionally, type a label for the branch in the Branch Label table cell. Labeling your branches can improve the readability of your activity diagram.
  9. Optionally, type a description for the branch in the Comment table cell.
  10. Click Apply to add the branch to the decision node. In the activity diagram, the decision node now contains a blue square to indicate the normal branch you just created.

After you add a normal branch, you must connect it to its associated result with a transition link.

Defining an exception branch

Perform the following steps to define an exception branch in a decision node:

  1. In the activity editor, double-click the decision node symbol. The Decision Properties dialog box opens.
  2. In the row for the branch you are creating, click the table cell in the Type column and select Exception from the drop-down list of branch types.
  3. Click the table cell in the Condition column and select the type of exception from the drop-down list of exception types.
  4. Optionally, type a label for the branch in the Branch Label table cell. Labeling your branches can improve the readability of your activity diagram.
  5. Optionally, type a description for the branch in the Comment table cell.
  6. Click Apply to add the branch to the decision node. In the activity diagram, the decision node now contains a red square to indicate the exception branch you just created.

After you add an exception branch, you must connect it to its associated result with a transition link.

Defining a default branch

Each decision node can have only one default branch. Adding a default branch is optional.

Perform the following steps to add a default branch to your decision node:

  1. In the activity editor, double-click the decision node symbol. The Decision Properties dialog box opens.
  2. In the row for the branch you are creating, click the table cell in the Type column and select Default from the drop-down list of branch types.
  3. Optionally, type a label for the branch in the Branch Label table cell. Labeling your branches can improve the readability of your activity diagram.
  4. Optionally, type a description for the branch in the Comment table cell.
  5. Click Apply to add the branch to the decision node. In the activity diagram, the decision node now contains a black square to indicate the default branch you just created.

Note that you cannot specify a condition for the default branch. The condition is implicit; it evaluates to true when all of the conditions associated with the other branches evaluate to false.

After you add the default branch, you must connect it to its associated result with a transition link.

Combining an exception and a condition in branching logic

A branch can be normal or an exception, but not both. However, there are times when you might want to specify the execution path to take in response to two simultaneous conditions: an exception occurred and another condition is true. This combination is the equivalent of using an AND operator in a conditional expression.

For example, suppose you want to model these two conditions:

Exception == JavaException && hasValue == false
 Exception == JavaException && hasValue == true 
 

To model such a construct, create two levels of decision nodes, putting an action node between them, as shown below:

Figure 34. Combining an exception and a condition


Copyright IBM Corp. 2003, 2004