Introduction to Conditional Branching

Using Conditional Branching in a BPEL Process 10-3

10.2.1.1 How to Create a Switch Activity

To create a switch activity: 1. In the Component Palette, expand BPEL Constructs. 2. Drag a Switch activity into the designer, as shown in Figure 10–2 . The Switch activity has two switch case branches by default, each with a box for functional elements. If you want to add more branches, select the entire switch activity, right-click, and select Add Switch Case from the menu. Figure 10–2 Switch Activity

3. In the first branch, double-click the condition box.

A dialog for entering a condition is displayed, as shown in Figure 10–3 . Figure 10–3 Condition Dialog

4. In the Label field, enter a name for the condition branch. When complete, this

name is displayed in Oracle BPEL Designer.

5. In the Description field, enter a description of the capabilities of this condition

branch.

6. In the Condition field, click the Expression Builder icon to access the Expression

Builder dialog. 7. Create your expression. bpws:getVariableDate’loanOffer1’,’payload’,’loanOfferAPR’ bpws:getVariableData’loanOffer2’,’payload’,’loanOfferAPR’ In this example, two loan offers from completing loan companies are stored in the global variables loanOffer1 and loanOffer2. Each loan offer variable contains the loan offer’s APR. The BPEL flow must choose the loan with the lower APR. One of the following switch activities takes place: ■ If loanOffer1 has the higher APR, then the first branch selects loanOffer2 by assigning the loanOffer2 payload to the selectedLoanOffer payload. 10-4 Oracle Fusion Middleware Developers Guide for Oracle SOA Suite ■ If loanOffer1 does not have the lower APR than loanOffer2, the otherwise case assigns the loanOffer1 payload to the selectedLoanOffer payload.

8. Click OK.

The expression is displayed. The value you entered in the Label field of the dialog becomes the name of the condition branch. Figure 10–4 provides details. Figure 10–4 Completed Condition Dialog

9. Click OK.

10. Add and configure additional activities as needed.

Figure 10–5 provides details. Figure 10–5 Switch Activity Design

10.2.1.2 What Happens When You Create a Switch Activity

A switch activity, like a flow activity, has multiple branches. In Example 10–1 , there are only two branches shown in the .bpel file after design completion. The first branch, which selects a loan offer from a company named United Loan, is executed if a case condition containing an XPath boolean expression is met. Otherwise, the second branch, which selects the offer from a company named Star Loan, is executed. By default, the switch activity provides two switch cases, but you can add more if you want. Example 10–1 Switch Activity switch name=switch-1 case condition=bpws:getVariableDataloanOffer1,payload, autoloan:loanOfferautoloan:APR bpws:getVariableDataloanOffer2,payload,autoloan:loanOfferautoloan:APR