The overall process to use Switch Rules follows this sequence.
- Create a Switch Rule in the Ruleset editor.
- Select the Switch Rule, and then use the Rule tab in the Properties view to map source data.
- Create and define new Cases and/or Case conditions.
- Add Methods to each Case.
Create Switch Rules
Use the New Switch option that is available as part of the toolbar in the Rule section of the Ruleset editor. A Switch Rule requires at least one Case. By default, a Switch Rule is created with one Case and new Cases are created with a Type Guard of Object.
To add Cases to a Switch Rule:
- Select the Switch Rule;
- Right-click and select Add New Case.
Use tabs in the Properties View
The Properties view displays different options based on the Case in the Switch Rule that is selected in the Rules section. This is how you can view and define rules, conditions, and other properties.
Type Guard (tab): In this tab, you can set the Type Guard by clicking the Select Subtype button (). This will display the fully qualified names (FQN) of the Subtypes available for the Type of the element mapped in the Switch Rule. If a Condition has been added to the Case, the Remove Type Guard button will be enabled; allowing you to remove the Type Guard from the selected Case.
Condition (tab):This tab is similar to the Condition tab in Simple and Composite Rules. It allows you to map a Conditional Action to the Case, or remove it from the selected Case if a Type Guard is also provided.
Method (tab): This tab is used to map a Method to a Case in a Switch Rule. You can drag and drop a Method from the Methods pane of the Ruleset editor. After a Method is selected, you can also use this tab to map the Method’s input.
All Method parameters are defined as input, which is slightly different from other Rules in that this allows you to map from the Target schema to the targetParm input (if a Target exists for the Method). Since the targetParm input parameter is a mapping from the Target schema, the editor marks it with by a cross-hair icon ( ).
For more information, see Creating Methods for use in a Ruleset.
Create and define Cases
Use the following right-click options to create and define Cases from the Rules section of the Ruleset editor.
- New Case: adds a new Case Rule to your Switch Rule.
- Add/Remove Case Condition: adds or removes a conditional action to the selected Case.
- Add/Remove Case Method: displays any existing method that can be added to or removed from your Case.
Add Methods to Cases
A Ruleset Method, like a Composite Rule, is used to group rules. An important difference, however, is that the method includes Type parameters that correspond to data types in the source and target of the Ruleset. Methods can also be re-used within the Ruleset, thereby providing better maintainability.
To add a method to a Case:
- Select the Case;
- Right-click and select Add Case Method, which provides a list of existing Methods. Another option is to drag the specific method from the Methods pane onto the Case or, into the Method tab of the Properties view.
Note: For more information, see the Method topic found in the Using Actions, Variables, and Methods to Define Rules section.