Designing a Switch Node
To create logic for your Switch node, you must complete the following steps:
To Design the Switch Logic
- Double-click the Switch node to invoke the condition builder.
- 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.
- 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.
- In the decision builder, select a business process variable by clicking Select Variable.
A drop-down list of business process variables in your project is displayed.
- Select a variable that you have already created in your project, or create a new variable to use in your switch node:
- 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.
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:
Note: (To learn about creating business process variables and importing schemas to your project, see Business Process Variables and Data Types and Importing Files into the Schemas Project.)
When you select a variable, a representation of the XML Schema associated with that variable is displayed in the Select Node pane. Go to step 3.
- If you want to create a new variable, select Create new variable... from the drop-down list.
The Create Variable dialog box opens.
- Enter a name for your new variable in the Variable Name field.
- Select the 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.
- Click OK.
The Create Variable dialog box closes and your new variable is displayed in the Select Node pane.
- Building on our requestXML variable example, the following figure shows the XML Schema represented when the requestXML variable is selected:
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
in the GUI representation of the Schema.)
- In the Select Node panel, select the node in the XML Schema for which you want to define the switch.
- 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 data($requestXML/ns0:shipAddress/@street) is displayed in the Selected Element field.
- Click the X in the top right-hand corner to return to the Design View.
In the Design View, note that the Condition in your Decision node displays the following icons:
-
is a visual reminder that the condition you defined on this node is based on the evaluation of an XML document.
-
is a visual reminder that the condition you defined on this node is based on the evaluation of a MFL file.
- To save your work, select File —> Save.
Method
- Enter a name for the Java method in the Java Method Name field.
Note: To select an existing method, click
on the right side of the Java Method Name field.
- Click View Code in the lower right-hand corner of the Switch builder.
The Source View is displayed at the line of code in your JPD file at which the Java method is written.
- Edit your Java method and click the Design View tab to return to the Design View.
- Click the X in the top right-hand corner to close the decision builder.
In the Design View, note that the Condition in your Switch node displays the following icon:
. 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
- Double-click the Case node to invoke the case builder.
- 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.
- 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
- In the Value field, enter the constant value or variable that you want to match the case statement to.
Note: You can select an existing variable or create a new one by clicking
on the right side of the Constant Value field.
- To close the node builder, click the X in the top right-hand corner.
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.
- 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.
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.
- 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.
- To save your work, select File —> Save
Related Topics
Grouping Nodes in Your Business Process
Creating a Switch Node
Handling Exceptions
Adding Message Paths
Adding Timeout Paths