<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <title>WSO2 EI - Switch Mediator </title>
  <link href="css/EI-docs.css" rel="stylesheet" />
  <link href="styles/dist-docs.css" rel="stylesheet" type="text/css"
  media="all" />
</head>

<body>
<h2>Switch Mediator</h2>

<p>Switch mediator is another XPath filter. The XPath will be evaluated and
will return a string. This string is matched against the regular expression in
each of cases in the specified order. If a matchig case is found it will be
executed. Further proccessing of the case statements won't happen after a
matching is found. If none of the case statements are matching and default case
is specified, it will be executed.</p>

<h3>Syntax</h3>
<pre xml:space="preserve"> &lt;switch source="xpath"&gt;
   &lt;case regex="string"&gt;
     mediator+
   &lt;/case&gt;+
   &lt;default&gt;
     mediator+
   &lt;/default&gt;?
 &lt;/switch&gt;</pre>

<p>The &lt;switch&gt; 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 not match and a default case exists, it will be
executed.</p>

<h3>UI Configuration</h3>

<h4>Switch</h4>

<p><img src="../switch-mediator/images/switch_mediator_screenshot.jpg" alt=""
/> </p>

<p> Here are the options to configure the Switch Mediator. </p>
<ul>
  <li>Source XPath: Here you can specify the source xpath to be evaluated. </li>
  <li>Number of cases: The number of cases specified. You can add cases by
    clicking the "Add Case" link. </li>
  <li>Specify default case: The link to add the default case. (This case is to
    execute when all the other cases are failed.) </li>
</ul>

<h4>Case</h4>

<p><img src="../case-mediator/images/switch_case_mediator_screenshot.jpg"
alt="" /> </p>

<p>Switch Case Mediator</p>

<p>Here are the options to configure the Switch Case Mediator. </p>
<ul>
  <li>Case Value (Regular Expression): A regular expression to match with
    switching value. </li>
</ul>

<h4>Default</h4>

<p>The Switch Default Mediator will be a child mediator for the Switch
Mediator. It is to define a defalut 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. </p>

<p></p>

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

<p>In this scenario it will get the text of symbol element and match it against
values MSFT and IBM.</p>

<p></p>
</body>
</html>
