Let us start with the <while>
loop:
<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:Alternatively, we can write source code directly:
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:<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:<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:<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.<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
:<assign>
activity to prepare the request. We will add the <assign>
activity before the <invoke>
activity and set the following copy expression:As you can see, we will copy the $inputVariable.payload/ns1:BookData[$i]
order item to the $BookWarehousingRequest.payload/ns1:BookData
element.
<assign>
activity after the <invoke>
activity and increase the counter i
by one:We have successfully developed the BookOrderManagementBPEL
process, which iterates through book data items using a <while>
loop. The process flow should look like this:
The source code should read as follows. We started with the variable initialization:
Then we implemented the loop, where we extracted the book data item, invoked the BookWarehousingBPEL
process, and increased the counter:
With this, we have concluded the implementation of our first loop—the <while>
loop.
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 <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.
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 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).