Chapter 4. Conditions and Loops

Conditions and loops are important constructs in every programming language. Conditions allow us to implement branches. Loops provide the possibility for the code to execute more than once. In this chapter, we will look at conditions and loops in BPEL. We will look at the if/elseif/else activity, which is how conditions are expressed in BPEL. For loops, BPEL has more options. We will become familiar with while, repeat until, and for each loops. We will also explain which to use when. We will look into the detailed syntax of each loop and learn when to use parallel loops.

In this chapter, we will take a closer look at the if/elseif/else activity and at the various loop activities provided by BPEL. As we move along the chapter, we will cover the following topics:

  • Understanding conditions and learning how to use the <if> activity
  • Understanding loops
  • Getting familiar with the <while> loop
  • Getting familiar with the <repeatUntil> loop
  • Getting familiar with the <forEach> loop
  • Understanding parallel <forEach> execution
  • Learning about delays, deadlines, and durations
  • Understanding how to end a BPEL process

So, let's get started...

Conditions

To make choices based on conditions in BPEL 2.0, we use the <if> activity to define the conditional branches, which replaced the <switch> activity in BPEL 1.1. The <if> activity can have several <elseif> branches and one <else> branch. The following example shows the structure of the <if> activity:

<if>
  <condition>boolean-expression</condition>
  <!--activities -->

  <elseif>
    <condition>boolean-expression</condition>
    <!--activities -->
  </elseif>

  <elseif>
    <condition>boolean-expression</condition>
    <!--activities -->
  </elseif>
  ...
  <else>
    <!--activities -->
  </else>
</if>

The Boolean expressions for the <condition> elements are expressed in the XPath. We can use any valid XPath expression that returns a Boolean value. To use variables in conditions, we can use the $ operator, the same way as in assignments, which we have covered in Chapter 3, Variables, Data Manipulation, and Expressions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.231.93