Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The Switch Mediator is a an XPath filter. The XPath is evaluated and return a string. This string is matched against the regular expression in each of cases case statement, in the specified order. If a matching case is found, it will be executed. Further Once the match is found, further processing of the case statements won't happen after matching is found. If none of the case statements are matching and a default case is specified, it will be executed.

...

Table of Contents
maxLevel3
minLevel3
locationtop
styleborder:1
typeflat
separatorpipe

...

Syntax

Code Block
XML
XML
<switch source="xpath">
   <case regex="string">
     mediator+
   </case>+
   <default>
     mediator+
   </default>?

</switch>

The Switch Mediator will evaluate the given source XPath expression into its string value and match it against the given regular expressions. If the specified cases does do not match and a default case exists, it will be executed.

...

  • Source XPath - Here you can specify the source XPath to be evaluated.
  • Number of cases - The number of cases specified. You can add cases by clicking the "Add Case" link.
  • Specify default case - The link to add the default case. (This case is to be executed when all the other cases are failednot matching.)
Info
titleTip

You can click this link to add namespaces if you are providing an expression. You will be provided another panel named "Namespace Editor," where you can provide any number of namespace prefixes and URL that you have used in the XPath expression. See Common Screens and Dialog Boxes.

Switch-Case Mediator
Anchor
Switch-Case Mediator
Switch-Case Mediator

...

The Switch Default Mediator will be a child mediator for the Switch Mediator. It is used to define a default case for the current routing switch. If all the cases were not matched with the switch value, the sequence defined as children to the default mediator will be taken as the route of the message.

Info
titleNote

You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window.

...

Example

Code Block
XML
XML
<switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples/xsd">
      <case regex="IBM">
          <!-- the property mediator sets a local property on the *current* message -->
          <property name="symbol" value="Great stock - IBM"/>
      </case>
      <case regex="MSFT">
          <property name="symbol" value="Are you sure? - MSFT"/>
      </case>
      <default>
          <!-- it is possible to assign the result of an XPath expression as well -->
          <property name="symbol"
                expression="fn:concat('Normal Stock - ', //m0:getQuote/m0:request/m0:symbol)"
                xmlns:m0="http://services.samples/xsd"/>
      </default>
  </switch>

...