Skip Headers
Oracle® BPEL Process Manager Developer's Guide
10g (10.1.3.1.0)

Part Number B28981-03
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

7 Conditional Branching

This chapter describes conditional branching. Conditional branching introduces decision points to control the flow of execution of a BPEL process.

This chapter contains the following topics:

7.1 Use Case for Conditional Branching

The BPEL process you created in Chapter 6, "Parallel Flow" collected two loan offers, one from United Loan and another from Star Loan. This chapter describes how to design the BPEL process to select the loan with the lowest annual percentage rate (APR) automatically.

See Also:

The following sample:
  • SOA_Oracle_Home\bpel\samples\demos\LoanDemo\LoanFlow

7.2 Overview of Conditional Branching Concepts

BPEL applies logic to make choices through conditional branching. You can use either of the following activities to design your code to select different actions based on conditional branching:

A number of 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 of time, the BPEL flow can stop waiting and resume its activities. Chapter 10, "Events and Timeouts" explains this feature in detail.

7.3 Using a Switch Activity to Define Conditional Branching

In Chapter 6, the flow activity of the BPEL process gathered two loan offers 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 offers and make decisions based on that comparison, the BPEL flow requires a switch activity.

Figure 7-1 provides an overview of a BPEL conditional branching process that has been defined in a switch activity.

Figure 7-1 Conditional Branching

Description of bpmdg017.gif follows
Description of the illustration bpmdg017.gif

A switch activity, like a flow activity, has multiple branches. In this example, there are only two branches. The first branch, which selects a loan offer from United Loan, is executed if a case condition containing an XPath Boolean expression is met. Otherwise, the second branch, which selects the Star Loan loan offer, is executed. By default, the switch activity provides two switch cases, but you can add more if you want.

<switch name="switch-1">
     <case condition="bpws:getVariableData('loanOffer1','payload',
     '/autoloan:loanOffer/autoloan:APR') <;
     bpws:getVariableData('loanOffer2','payload','/autoloan:loanOffer/autoloan:APR
     ')">
          <assign name="selectUnitedLoan">
            <copy>
               <from variable="loanOffer1" part="payload">
               </from>
               <to variable="selectedLoanOffer" part="payload"/>
            </copy>
          </assign>
     </case>
     <otherwise>
        <assign name="selectStarLoan">
          <copy>
            <from variable="loanOffer2" part="payload">
            </from>
            <to variable="selectedLoanOffer" part="payload"/>
          </copy>
         </assign>
     </otherwise>
</switch>

Adding a Switch Activity

To add a switch activity to your BPEL flow in Oracle JDeveloper:

  1. Drag a switch activity from the Process Activities list of the Component Palette into your BPEL flow.

  2. Click the + sign to expand the switch activity.

    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.

    Description of switch3.gif follows
    Description of the illustration switch3.gif

  3. Right-click the first branch and select Edit from the menu.

    The Switch Case window appears.

  4. Enter an XPath Boolean expression in the Expression field by pressing the Ctrl key and then the space bar to start the XPath Building Assistant. For example:

    bpws:getVariableDate('loanOffer1','payload','/loanOffer/APR') >
    bpws:getVariableData('loanOffer2','payload','/loanOffer/APR')
    
    
  5. Enter this expression on one line. To use the XPath Expression Builder, click the XPath Expression Builder icon above the Expression field.

    The two loan offers that the LoanFlow tutorial uses 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 loanOffer2's payload to selectedLoanOffer's payload.

    • If loanOffer1 does not have the lower APR than loanOffer2, then the otherwise case assigns loanOffer1's payload to selectedLoanOffer's payload.

See Also:

The following documentation for examples of creating switch activities in Oracle JDeveloper:

7.4 Using a While Activity to Define Conditional Branching

Another way to design your BPEL code to select between multiple actions is to use a while activity to create a while loop. The while loop repeats an activity until a specified success criteria is met. For example, if a critical Web service is returning a service busy message in response to requests, you can use the while activity to keep polling the service until it becomes available. The condition for the while activity is that the latest message received from the service is busy, and the operation within the while activity is to check the service again. Once the Web service returns a message other than service busy, the while activity terminates and the BPEL process continues, ideally with a valid response from the Web service.

To create a while activity in Oracle JDeveloper:

  1. Drag and drop a while activity from the Process Activities list of the Component Palette into your BPEL flow.

    The while activity has icons to allow you to build condition expressions and to validate the while definition. It also provides an area for you to drop an activity to define the while loop.

    Description of while1.gif follows
    Description of the illustration while1.gif

  2. Drag the activity that you want to use to define the while condition onto the Drop Activity Here area of the while activity.

    The activity can be an existing activity or a new activity, such as an invoke activity to launch a task.

See Also:

The following documentation for examples of defining a while activity in Oracle JDeveloper:

7.5 Summary

This chapter discusses the concepts and procedures for creating a switch activity conditional flow that selects different behavior based on comparing two pieces of information. The BPEL process in this example considers two loan offers, and selects the offer with the lower APR. This chapter also discusses the while looping conditional activity.