Question & Answer
Question
How can you customize the control flow within BPEL processes using the BPEL Choice activity?
Answer
This document shows how the control flow within BPEL processes can be customized using the BPEL Choice activity. It highlights which settings and expressions need to be set in the BPEL Case activity to control the flow of process execution. This process is based on the expression languages Simple condition as well as Java™.
The following information is based on WebSphere Integration Developer Version 7.0.
In WebSphere Integration Designer, you can influence the flow of a BPEL process based on the state of a business object.


The BPEL Choice activity (figure 1) provides a way to specify multiple flows for a process. It selects one activity branch from a set of case elements that are based on a runtime condition and hooses the first expression that equals true.
As shown in figure 2, you can add several Case elements to the Choice activity. Each Case activity is assigned an expression that is used to evaluate the business object state during runtime or the execution of the BPEL process. The remainder of this document lists the types of expressions that are possible and the best practices for each type.
Figure 3 (below) shows the Properties view of WebSphere Integration Developer when you select one of the Case elements within the Choice activity. For the Case element, only one expression language is allowed. However, you can specify a different expression language in another Case element.

There are four main expression languages available:
- Simple expressions (Boolean true or false)
- Condition-based expression
- Java expressions (visual or text)
- XPath expressions
This document focuses on condition-based and Java expression language in detail.
- Condition-based expression
This expression type enables you to compose a condition in the user interface and based it on the available variables within the BPEL process and their individual types.In the drop-down list, you need to select the No expression entry to create a new condition. (figure 4)

As figure 5 shows, a list of elements are available. They are simple elements like true or false. Available variables within the BPEL process, such as AmountOfMoney of type int, or MyName of type string and other predefined values, compare possibilities. The last one mentioned is not relevant here.
Assume this Case activity should be executed when the value stored in the AmountOfMoney variable equals to 5000. Therefore, first select the variable as the left part of the comparison expression.

Second, based on the specific data type of the selected variable, a set of possible operations are available (figure 6). Due to the fact that this variable is the integer type, the compare operations, such as equals (==), greater than (>) or less than (<) , and so on, are available. In addition, other arithmetic operations are also possible, but are not relevant for comparison here.
You can compare figures 6 and 7 to see the operations that are available based on the data type of the chosen variable. In figure 7, only the equals (==) or not equals (!=) operations are available. (+ means string concatenation). The other operations, for example greater than and less than, are not available because a string cannot be greater than another string B.


Third, you need to set the right hand side of the expression. This value can again either be a variable or a static value. For example, you can set it to the Number 5000 (figure 8).

Finally, the expression is complete. If the value of the AmountOfMoney variable equals 5000 during the execution of this BPEL process, this Case activity result is true and the flow continues after that specific case activity.

Note: The most important aspect here is the equals operator (==). This operator always compares the value of the variable. As mentioned before, the variable is of the data type, integer.
This statement is important for later discussion, when the Java expression language is described. In Java, you can also use the == operator for object reference comparison. But as mentioned before, in Simple Conditions the == operator always compares the value.
- Java expression type
When you choose Java as the expression language, you can use custom Java code to evaluate the expression. It is important that a Boolean expression value (either true or false) is returned.

The expression AmountOfMoney == 5000 is exactly the same as mentioned previously in the Simple Condition. Nevertheless, there is an important aspect using the == compare operator in Java code:
- Based on the official Java documentation for Integer objects, the == operator has two meanings. It compares the value for Java primitive values, like Boolean or int. But using Java objects, the == operation does not compare the value, it compares the object reference in memory.
As an example, the primitive data type int has a corresponding object type java.lang.Integer. Due to that fact, the == operator is applied on objects during runtime and it compares object references. This process might result in undesired behavior because the references are compared instead of the values of the integer variable. For that reason, all wrapper objects have the equals() method, which compares the value of the object instead of the reference.
As figure 11 shows, the expression is now based on the equals() method of the wrapper class.

Related Information
Product Synonym
WPS;WID
Was this topic helpful?
Document Information
Modified date:
15 June 2018
UID
swg21606217