Guide to Building Business Processes

     Previous  Next    Open TOC in new window  Open Index in new window  View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Defining Conditions For Branching

A common design pattern in business processes is one which selects one path of execution based on the evaluation of one or more conditions. You can create this pattern by designing a Decision node in your business process.

By default, a Decision node consists of one condition, a path below the condition, which represents the path of execution followed when the decision evaluates to true, and a path to the right of the condition, which represents the path of execution followed when the condition evaluates to false (the default path). A Decision node can contain additional conditions, in which case if the first condition evaluates to false, the second condition is evaluated. If the second condition evaluates to false, the next condition is evaluated, and so on. The default path is executed if no conditions are met.

Note: To create case statements, WebLogic Integration provides a customized node, called a Switch node. To learn about using Switch nodes and how they differ from Decision nodes, see Comparing Decision Nodes and Switch Nodes in Creating Case Statements.

This section describes how to add a Decision node to your business process, define conditions, and define activities for the alternative paths of execution in the Decision node. It contains the following topics:

Creating a Decision Node in Your Business Process

To Create a Decision Node in Your Business Process
  1. On the Package Explorer pane, click the business process (Process.java file) you want to design.Your business process is displayed in the Design view.
  2. If the Node Palette is not visible in BEA Workshop for WebLogic Platform, choose WindowArrow symbolShow ViewArrow symbolNode Palette from the BEA Workshop for WebLogic Platform menu.
  3. Click Decision Node Decision on the Node Palette.
  4. Drag and drop the Decision node onto the business process in the Design view, placing it on the business process at the point in your business process that requires branching to one of several possible paths of execution, based on the evaluation of one or more conditions.
  5. The Design view is updated to contain a Decision node, as shown Figure 8-1.

    Figure 8-1 Decision Node


    Decision Node

Note the following characteristics of the Decision node:

Related Topics

Designing Your Decision Node

Creating Case Statements

Designing Your Decision Node

To create logic for your Decision node, you must complete the following steps:

To Design the Condition Logic
  1. Double-click the Condition node to invoke the decision builder.
  2. Select one of the options:
    • Variable—Select this option if, at run time, you want the business process to make a decision, based on the value of an element in an XML or non-XML variable.
    • Method—Select this option if, at run time, you want the business process to make a decision, based on a boolean result returned from Java code that you create.
    • The node builder displays different options depending on whether you select Variable or Method.

  3. Complete the selections in the node builder appropriate for the selection you made in the preceding step: Variable (Schema) or Method.
Variable (Schema)

The following steps describe how to select a business process variable that is associated with an XML or MFL schema.

Note: To learn about creating business process variables and importing schemas to your project, see Business Process Variables and Data Types.
  1. In the condition builder, select a business process variable by clicking Decision Node.
  2. A drop-down list of business process variables in your project is displayed.

    For example, if you imported an XML Schema (QuoteRequest.xsd) into your project, and created a business process variable (requestXML) of type quoteRequest (based on the QuoteRequest.xsd schema), the requestXML variable is available in the drop-down list of business process variables.

  3. Click the arrow in the Select Variable drop-down list, then select a variable that contains the XML or typed non-XML on which you want to build the condition.
  4. A representation of the XML Schema associated with that variable is displayed in the Select Expression Node field as shown in Figure 8-2.

    Figure 8-2 Select Expression Node


    Select Expression Node

    The elements and attributes of an XML document, assigned to this variable, are represented as nodes in a hierarchical representation, as shown in the preceding figure. Note that the schema in the example (QuoteRequest.xsd) specifies a root element (quoteRequest), and child elements: customerName, shipAddress, and widgetQuoteRequests. The widgetQuoteRequests element, in turn, specifies a repeating element: widgetQuoteRequest. (A repeating XML element is represented by Select Expression Node in the GUI representation of the Schema.)

  5. In the Select Expression Node field, select the node in the XML Schema for which you want to define the condition.
  6. To continue with the example, supposed you selected customerName from the XML variable represented in the preceding figure. The Selected Expression field is populated with the following expression:

    fn:data($requestXML/ns0:customerName)
  7. Click Select. Your new variable is displayed in the Left Hand Expression field.
  8. Select an operator from the Operator drop-down list.
  9. For example, =

  10. In the Right Hand Expression field, enter a value or choose a variable and expression with which to create the decision logic.
  11. For example, enter BEA.

  12. Click Add. The condition you created is added to the condition list.
  13. For example, fn:data($requestXML/ns0:customerName) = "BEA"

  14. Select a join option of either AND or OR to qualify your conditions.
  15. To add a condition based on an existing value in the Left Hand Expression field:
    1. In the condition list pane, select a condition. The Left Hand Expression, Operator, and Right Hand Expression fields are populated with the appropriate values.
    2. In the Right Hand Expression field, select the value.
    3. For example, BEA.

    4. Change the entry you selected.
    5. For example, Avitek.

    6. Select the arrow beside the Update button, then select Add from the menu.
    7. The new condition is added to the bottom of the condition list.

  16. To edit the conditions after you create them:
    1. In the condition list pane, click the condition that you want to change. The Left Hand Expression, Operator, and Right Hand Expression fields are populated with the appropriate values.
    2. Change the value in any of the fields.
    3. Click Update.
    4. Alternatively, you can edit conditions directly in the code. To do so, in the Condition builder, click View Code in the lower left-hand corner. The XQuery function that was written to the file from the design work in the condition builder is displayed at the line of code in your Process.java file; it is indicated by the @com.bea.wli.commom.XQuery annotation.

  17. To edit Join Options after you create them:
    1. In the condition list pane, click the Join Option that you want to change.
    2. Select the appropriate join option.
    3. Click Update.
  18. Click Close in the top right-hand corner of the condition builder.
  19. In the Design view, note that the Condition in your Decision node displays the following icons:

    • Select Expression Node is a visual reminder that the condition you defined on this node is based on the evaluation of an XML document.
    • Select Expression Node is a visual reminder that the condition you defined on this node is based on the evaluation of a MFL file.
    • Defining an XML or MFL condition produces an XQuery function that is written to your Process.java file, which you can see in the Source view. The condition defined by following the preceding example (in steps 1 through 7) creates the following XQuery function in the Process.java file:

      @com.bea.wli.common.Xquery(prolog =
      " declare namespace ns0 =\http://ww.example.org./quote\";"+
      " declare function cond_requestXML_1($requestXML) as  xs:boolean {"+
      " fn:data($requestXML/customerName) = \"BEA\""+
      "};")
  20. To save your work, select FileArrow symbolSave.
Method

The following steps describe how to select a business process variable that is associated with an XML or MFL schema.

  1. In the Java Method Name field, enter a name for the Java method, or, to choose an existing method, click Select Expression Node.
  2. Click View Code in the lower left-hand corner of the node builder.
  3. The Source view is displayed at the line of code in your Process.java file at which the Java method is written.

  4. Edit your Java method.
  5. To return to the Design view, click the tab.
  6. Close the condition builder by clicking Close.
  7. In the Design view, note that the Condition in your Decision node displays the following icon: Select Expression Node. It is a representation of the condition you defined in source code that specifies the Java method on which to base the decision. To make any further changes to the condition represented on this node, you must edit the source code in the Source view.

  8. To save your work, select FileArrow symbolSave.
To Add Activities to the Paths in Your Decision Node

After you define the condition that is evaluated when the flow transitions to the Decision node at run time, you are ready to define the actions on the paths that represent the paths of execution in the flow.

  1. Add a node (or nodes) to each path in the Decision node to define the activity that is executed when the conditions you defined on the Condition node at the beginning of the path evaluates to true.
  2. This can be any node that performs an activity appropriate for your business process business logic. For example you can use a control to interact with an external resource, such as a database, a JMS queue, or an EJB.

  3. Add a node (or nodes) to the default path that defines which activities are executed when no condition evaluates to true at run time. The nodes on the default path can be any that define activities appropriate for your business process business logic.

When you complete the addition of activities on the paths of your Decision node, your decision logic is represented as a series of conditions and actions in your business process.

Example Decision Node

Figure 8-3 shows an example Decision node in the Design view.

Figure 8-3 Decision Node

Decision Node

Building on the QuoteRequest example used in building the Variable (Schema) condition, two Perform nodes are added to the paths on the Decision node. At run time, the following sequence represents the flow of control in this decision node:

  1. The condition defined on the Check Customer condition node is evaluated:
  2. fn:data($requestXML/ns0:customerName) = "BEA"
    Note: The XML evaluated by the condition node is assigned to the requestXML business process variable.
  3. If the Check Customer condition evaluates to true at run time, the activities defined on the BEA Orders node are performed, then the flow exits the Decision node.
  4. If the Check Customer condition evaluates to false at run time, the path of execution is the Default path. The activities defined on the Non BEA Orders node are performed, then the flow of control exits the Decision node.

Related Topics

Creating a Decision Node in Your Business Process

Grouping Nodes in Your Business Process

Handling Exceptions

Adding Message Paths

Adding Timeout Paths

Business Process Source Code

Interacting With Resources Using Controls


  Back to Top       Previous  Next