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

Creating Case Statements

A Switch node is used to select one path of execution based on the evaluation of an expression specified on a condition node. A Switch node contains one condition node, one or more case paths, and one default path. At run time, the expression on the condition node is executed, and the resulting value is compared to the values associated with each case path. Execution continues with activities inside the first case path that contains a matching value (case paths are evaluated left-to-right in the Switch node). When no conditions are met, activities defined on the default path are executed.

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

Comparing Decision Nodes and Switch Nodes

How does a Decision node differ from a Switch node?

A Decision node can include one or more conditions to be evaluated at run time. For a scenario in which a Decision node is defined, the business process evaluates the conditions (one on each path) sequentially, and executes the path for the first condition that evaluates as true. (Conditions are evaluated left-to-right in the Decision node.) In other words, 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 activities defined on the default path are executed if no conditions are met.

A Switch node includes a single condition. For a scenario in which a Switch node is defined, the business process evaluates an expression specified on a single condition node and selects one path of execution based on the evaluation of that expression. The possible paths of execution in a Switch node include one or more case paths, and one default path. Execution continues with activities inside the first case path that contains a matching value. (Case paths are evaluated left-to-right in the Switch node.) If the value resulting from the evaluation of the condition expression does not match any of the case paths, then the activities defined on the default path are executed.

Creating a Switch Node

To Create a Switch Node in Your Business Process
  1. On the Package Explorer pane, right-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 XML Schema Switch in the Node Palette.
  4. Drag and drop the Switch 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 Switch node, as shown in Figure 9-1.

    Figure 9-1 Switch Node


    Switch Node

Note the following characteristics of the Switch node:

Related Topics

Designing a Switch Node

Designing a Switch Node

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

To Design the Switch Logic
  1. Double-click the Switch node to invoke the condition builder.
  2. Select the option which you want the left side of your condition to be based on:
    • Variable—Select this option if, at run time, you want the business process to evaluate a match based on the value of an element in an XML document or a MFL file.
    • Method—Select this option if, at run time, you want the business process to evaluate a match, based on a result returned from Java code that you create.
    • The node builder displays options depending on whether you selected Variable or Method.

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

The following steps describe how to select a business process variable, which is associated with an XML or MFL schema. Select one or more nodes in the schema on which to define a switch or case node.

  1. In the decision builder, select a business process variable by clicking Select Variable.
  2. A drop-down list of business process variables in your project is displayed.

  3. Select a variable that you have already created in your project, or select Create new variable..., to create a new variable to use in your switch node:
    1. If you want to use a variable that is already created, select the variable that contains the XML or typed non-XML on which you want to build the condition.
    2. For example, if we import an XML Schema (QuoteRequest.xsd) into our project, and create 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 as shown in Figure 9-2.

      Figure 9-2 Select Variable


      Select Variable

      Note: (To learn about creating business process variables and importing schemas to your project, see Business Process Variables and Data Types and Creating and Importing Schema Files.)

      When you select a variable, a representation of the XML Schema associated with that variable is displayed in the Select Node pane.

    3. If you want to create a new variable, select Create new variable... from the drop-down list.
    4. The Create Variable dialog box opens.

    5. Enter a name for your new variable in the Variable Name field.
    6. Select the Simple, XML or nonXML option, depending on whether your variable is based on an XML document or MFL file and select the appropriate variable type in the displayed list of type options.
    7. Click OK.
    8. The Create Variable dialog box closes and your new variable is displayed in the Select Node pane.

  4. Building on our requestXML variable example, Figure 9-3 shows the XML Schema represented when the requestXML variable is selected:
  5. Figure 9-3 XML Schema


    XML Schema

    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 our 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 XML Schema in the GUI representation of the Schema.)

  6. In the Select Node panel, select the node in the XML Schema for which you want to define the switch.
  7. The node which you selected is displayed in the Selected Element field. For example, if you selected the element street in the preceding example, the $requestXML/ns0:shipAddress/@street) is displayed in the Selected Element field.
  8. Click Close to return to the Design view.
  9. In the Design view, note that the Condition in your Decision node displays the following icons:

    • XML Schema is a visual reminder that the condition you defined on this node is based on the evaluation of an XML document.
    • XML Schema is a visual reminder that the condition you defined on this node is based on the evaluation of a MFL file.
  10. To save your work, select FileArrow symbolSave.
Method
  1. Enter a name for the Java method in the Java Method Name field.
  2. Note: To select an existing method, click XML Schema on the left side of the Java Method Name field.
  3. Click View Code in the lower left-hand corner of the Switch builder.
  4. The Source view is displayed at the line of code in your Process.java file at which the Java method is written.

  5. Edit your Java method and click the Design tab to return to the Design view.
  6. Click Close, to close the decision builder.
  7. In the Design view, note that the Condition in your Switch node displays the following icon: XML Schema. It is a representation of the condition you defined in source code to specify 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.

To Specify the Case Statement
  1. Double-click the Case node to invoke the case builder.
  2. Select the option which you want the right side of your condition to be based on:
    • Schema—Select this option if, at run time, you want the business process to evaluate a match based on the value of an element in an XML document or an MFL file.
    • Method—Select this option if, at run time, you want the business process to evaluate a match based on a result returned from Java code that you create.
    • Constant or Variable—Select this option if, at run time, you want the business process to evaluate a match based on a constant that you specify.
    • The node builder displays options depending on whether you selected Schema, Method, or Constant or Variable.

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

For information about how to complete the Case builder when using the Schema option, see Variable (Schema) in the preceding section.

Method

For information about how to complete the Case builder when using the Method option, see Method in the preceding section.

Constant or Variable
  1. In the Value field, enter the constant value or variable that you want to match the case statement to.
  2. Note: You can select an existing variable or create a new one by clicking XML Schema on the right side of the Constant Value field.
  3. To close the node builder, click Close.
To Add Activities to the Paths in Your Switch Node

After you define the condition that is evaluated when the flow transitions to the Switch 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 Switch node to define the activity that is executed when the conditions you defined on the Case nodes at the beginning of the path match at run time.
  2. This can be any node that performs the 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, to define activities that are executed when none of the case statements match 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 Switch node, your decision logic is represented as a series of conditions and actions in your business process.

  1. To save your work, select FileArrow symbolSave

Related Topics

Grouping Nodes in Your Business Process

Creating a Switch Node

Handling Exceptions

Adding Message Paths

Adding Timeout Paths


  Back to Top       Previous  Next