Skip Headers
Oracle® BPEL Process Manager Developer's Guide
10g Release 2 (10.1.2)
B14448-02
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

8 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:

8.1 Use Case for Conditional Branching

The BPEL process you created in Chapter 7, "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 samples:
  • C:\orabpel\samples\demos\LoanDemo\LoanFlow (for Eclipse BPEL Designer)

  • Oracle_Home\integration\orabpel\samples\demos\LoanDemo\LoanFlow (for JDeveloper BPEL Designer)


8.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 time-out. 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 11, "Events and Timeouts" explains this feature in detail.

8.3 Using a Switch Activity to Define Conditional Branching

In Chapter 7, 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 8-1 provides an overview of a BPEL conditional branching process that has been defined in a switch activity.

Figure 8-1 Conditional Branching

Description of Figure 8-1  follows
Description of "Figure 8-1 Conditional Branching"

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 JDeveloper BPEL Designer:

  1. Drag a switch activity from the Component Palette into your BPEL flow.

    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

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

    The Switch Case window appears.

  3. Enter an XPath Boolean expression in the Expression field. For example:

    bpws:getVariableDate('loanOffer1','payload','/loanOffer/APR') >
    bpws:getVariableData('loanOffer2','payload','/loanOffer/APR')
    
    
  4. 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 JDeveloper BPEL Designer:

8.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 inJDeveloper BPEL Designer:

  1. Drag and drop a while activity from 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 JDeveloper BPEL Designer:

8.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.