Time for action – adding the <while> loop

Let us start with the <while> loop:

  1. Before adding the <while> loop, construct the BPEL flow. We will add two variables: NoOrders and i, both of the type xsd:int. We can add variables using the big green plus sign in the lower left window:
    Time for action – adding the <while> loop

    Alternatively, we can write source code directly:

    Time for action – adding the <while> loop
  2. Then we will need to know how many items we have in our list of book orders. We will use the XPath count() function to achieve this. Alternatively, we could use an Oracle extension function ora:countNodes(), but this would make our code vendor specific. At the same time, we will initialize the counter variable i. We will add an <assign> activity to the process flow and make both <copy> expressions. You can use the Edit Assign dialog windows (as we've shown in Chapter 3, Variables, Data Manipulation, and Expressions) or enter the source code directly:
    Time for action – adding the <while> loop
  3. Now we are ready to add the <while> loop construct to the BPEL flow. You should drag-and-drop the While activity from the Components palette on the right-hand side. You will find While under Structured Activities:
    Time for action – adding the <while> loop
  4. We need to set the condition as long as the <while> loop will execute. In our example, the loop will execute while i<= NoOrders. Double-click on the <while> activity to open the Edit While dialog and enter the Condition and the condition Name:
    Time for action – adding the <while> loop
  5. Within the <while> loop, we will extract the book order item from the array and prepare the request for the BookWarehousingBPEL process and invoke it. Finally, we will increase the counter i by one.
  6. Let's first add the <invoke> activity to the process within the <while> loop (again, drag-and-drop it from the Components palette). We will name the activity InvokeBookWarehousing. We will also create two global variables on the fly, BookWarehousingRequest and BookWarehousingResponse:
    Time for action – adding the <while> loop
  7. Next, we will add the <assign> activity to prepare the request. We will add the <assign> activity before the <invoke> activity and set the following copy expression:
    Time for action – adding the <while> loop

    As you can see, we will copy the $inputVariable.payload/ns1:BookData[$i] order item to the $BookWarehousingRequest.payload/ns1:BookData element.

  8. Finally, we need to add another <assign> activity after the <invoke> activity and increase the counter i by one:
    Time for action – adding the <while> loop

What just happened?

We have successfully developed the BookOrderManagementBPEL process, which iterates through book data items using a <while> loop. The process flow should look like this:

What just happened?

The source code should read as follows. We started with the variable initialization:

What just happened?

Then we implemented the loop, where we extracted the book data item, invoked the BookWarehousingBPEL process, and increased the counter:

What just happened?

With this, we have concluded the implementation of our first loop—the <while> loop.

Have a go hero – testing the process

It's your turn now. You should deploy and test the BookOrderManagementBPEL process. Be sure to select an array of the BookOrder items and to check whether they get propagated to the BookWarehousingBPEL process and to the individual bookstores.

The repeat until loop

The <repeatUntil> loop is very similar to the <while> loop. We have explained the syntax at the beginning of this section. The only difference to the <while> loop is that the condition is evaluated at the end of the <repeatUntil> loop (in <while> loop, it is evaluated in the beginning of the loop).

Because of the similarity, we will not show the example here, but instead we will ask you to implement it yourself.

Have a go hero – using <repeatUntil> instead of <while>

To practice loops, you should try to modify the preceding example and use the <repeatUntil> loop instead of the <while> loop. Please notice when the condition is evaluated in the <repeatUntil> loop.

The forEach loop

The <forEach> loop is a for loop, which can execute the loop branches serial (sequential) or in parallel. We have explained the syntax at the beginning of this section. Now, we will implement our scenario using the <forEach> loop (this is the same scenario that we have implemented with the <while> loop earlier).

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

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