What Happens When You Create a forEach Activity

9-22 Oracle Fusion Middleware Developers Guide for Oracle SOA Suite copy assign sequence scope forEach -- respond output to requestor -- reply name=replyOutput partnerLink=client portType=tns:Test operation=process variable=output sequence Example 9–13 shows the .bpel file after design is complete for a parallel forEach activity. Example 9–13 forEach Activity - Parallel sequence -- pick input from requestor -- receive name=receive createInstance=yes partnerLink=client portType=tns:Test operation=process variable=input assign copy frominput.payloadtns:value1from torequest.payloadto copy copy fromfrom tooutput.payloadto copy assign forEach counterName=i parallel=yes startCounterValueinput.payloadtns:value1 + 1startCounterValue finalCounterValueinput.payloadtns:value2 + 2finalCounterValue scope name=scope1 partnerLinks partnerLink name=DummyService partnerLinkType=tns:DummyService myRole=DummyServiceClient partnerRole=DummyServiceProvider partnerLinks sequence assign copy fromconcatoutput.payload, Afrom tooutput.payloadto copy assign invoke name=invokeDummyService partnerLink=DummyService portType=tns:DummyPortType operation=initiate inputVariable=request receive name=receiveFromDummyService partnerLink=DummyService portType=tns:DummyCallbackPortType operation=onResult variable=response assign copy fromconcatoutput.payload, Bfrom tooutput.payloadto copy assign sequence scope Using Parallel Flow in a BPEL Process 9-23 forEach -- respond output to requestor -- reply name=replyOutput partnerLink=client portType=tns:Test operation=process variable=output sequence 9-24 Oracle Fusion Middleware Developers Guide for Oracle SOA Suite 10 Using Conditional Branching in a BPEL Process 10-1 10 Using Conditional Branching in a BPEL Process This chapter describes how to use conditional branching in a BPEL process service component. Conditional branching introduces decision points to control the flow of execution of a BPEL process service component. This chapter includes the following sections: ■ Section 10.1, Introduction to Conditional Branching ■ Section 10.2, Defining Conditional Branching ■ Section 10.3, Creating a While Activity to Define Conditional Branching ■ Section 10.4, Creating a repeatUntil Activity to Define Conditional Branching ■ Section 10.5, Specifying XPath Expressions to Bypass Activity Execution For additional information on creating conditional branching in a SOA composite application, see the Fusion Order Demo application.

10.1 Introduction to Conditional Branching

BPEL applies logic to make choices through conditional branching. You can use the following activities to design your code to select different actions based on conditional branching: ■ Switch activity in a BPEL version 1.1 project Enables you to set up two or more branches, with each branch in the form of an XPath expression. If the expression is true, then the branch is executed. If the expression is false, then the BPEL process service component moves to the next branch condition, until it either finds a valid branch condition, encounters an otherwise branch, or runs out of branches. If multiple branch conditions are true, then BPEL executes the first true branch. For information about how to create switch activities, see Section 10.2.1, Defining Conditional Branching with the Switch Activity in BPEL 1.1. ■ If activity in a BPEL version 2.0 project Enables you to use an if activity when conditional behavior is required for specific activities to decide between two or more branches. The if activity replaces the switch activity that appeared in BPEL 1.1 processes. For information about how to create if activities, see Section 10.2.2, Defining Conditional Branching with the If Activity in BPEL 2.0. ■ While activity 10-2 Oracle Fusion Middleware Developers Guide for Oracle SOA Suite Enables you to create a while loop to select between two actions. Section 10.3, Creating a While Activity to Define Conditional Branching describes while activities. Many branches are set up, and each branch has a condition in the form of an XPath expression. You can program a conditional branch to have a timeout. That is, if a response cannot be generated in a specified period, the BPEL flow can stop waiting and resume its activities. Chapter 14, Using Events and Timeouts in BPEL Processes explains this feature in detail.

10.2 Defining Conditional Branching

This section describes how to define conditional branching with the following activities: ■ Switch activity in a BPEL version 1.1 project ■ If activity in a BPEL version 2.0 project

10.2.1 Defining Conditional Branching with the Switch Activity in BPEL 1.1

Assume you designed a flow activity in the BPEL process service component that gathered loan offers from two companies at the same time, but did not compare either of the offers. Each offer was stored in its own global variable. To compare the two bids and make decisions based on that comparison, you can use a switch activity. Figure 10–1 provides an overview of a BPEL conditional branching process that has been defined in a switch activity. Figure 10–1 Conditional Branching Note: You can also define conditional branching logic with business rules. See Oracle Fusion Middleware Users Guide for Oracle Business Rules and the WebLogic Fusion Order Demo application for details. Select starLoan assign switch case conditon 1 otherwise BPEL Process condition 1 Boolean XPATH Expression Select unitedLoan assign ? 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.