<!--
  ~  SCI-Flex: Flexible Integration of SOA and CEP
  ~  Copyright (C) 2008, 2009  http://sci-flex.org
  ~
  ~  This program is free software; you can redistribute it and/or modify
  ~  it under the terms of the GNU General Public License as published by
  ~  the Free Software Foundation; either version 2 of the License, or
  ~  (at your option) any later version.
  ~
  ~  This program is distributed in the hope that it will be useful,
  ~  but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~  GNU General Public License for more details.
  ~
  ~  You should have received a copy of the GNU General Public License along
  ~  with this program; if not, write to the Free Software Foundation, Inc.,
  ~  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  -->

<!-- A simple Synapse configuration -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <!-- A task is defined here to inject a message, namely a tick to the ESB based on a     -->
    <!-- triggered event                                                                     -->
    <task class="org.apache.synapse.startup.tasks.MessageInjector" name="Tick">
        <!-- The address to which the generated event is forwarded                           -->
        <property name="to" value="http://localhost:9900/soap/Tick"/>
        <!-- The value of the SOAP-Action field                                              -->
        <property name="soapAction" value="http://localhost:9900/soap/Tick"/>
        <!-- The message injected, which contains an XML payload with some information       -->
        <property name="message">
            <tick xmlns="http://mycom.com/ns/tick">
                <s>IBM</s>
                <p>89.6</p>
            </tick>
        </property>
        <!-- The interval at which the task will be triggered.                               -->
        <trigger interval="1"/>
    </task>
    <in>
        <!-- Initially a filter is applied to select messages having the 'To' Address equal  -->
        <!-- to http://localhost:9.../soap/.*, a regular expression. This address is a       -->
        <!-- requirement of Apache Synapse (and also WSO2 ESB) sample client applications    -->
        <!-- and services that run based on these XML configurations.                        -->
        <filter source="get-property('To')" regex="http://localhost:9000/soap/SimpleStockQuoteService">
            <!-- Next we setup the SCI-Flex XML Mediator, which is a Synapse-Esper Mediator  -->
            <!-- designed to specifically handle messages representable in XML format.       -->
            <class name="org.sciflex.plugins.synapse.esper.mediators.XMLMediator">
                <!-- In order to make use of the SCI-Flex Synapse-Esper Mediators, they      -->
                <!-- require to be initially configured. This involves the specification     -->
                <!-- of the Esper Configuration to use. Esper requires to configured either  -->
                <!-- statically or dynamically (greater support was introduced in Esper      -->
                <!-- 2.3.0).                                                                 -->
                <property name="Configuration">
                    <esper-configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                      xmlns="http://www.espertech.com/schema/esper" xsi:noNamespaceSchemaLocation="esper-configuration-2-0.xsd">
                        <!-- The Esper Configuration involves setting up of a XML DOM Event  -->
                        <!-- type, with some alias. The DOM Event can be configured to       -->
                        <!-- find elements, and evaluate XPath expressions                   -->
                        <event-type alias="StockQuoteEvent">
                            <xml-dom root-element-name="getQuote" default-namespace="http://services.samples/xsd">
                                <namespace-prefix prefix="m0" namespace="http://services.samples/xsd"/>
                                <xpath-property property-name="xsymbol" xpath="//m0:getQuote/m0:request/m0:symbol" type="string"/>
                            </xml-dom>
                        </event-type>
                        <!-- In here we define an event which is an Axiom Event which        -->
                        <!-- listens to the tick generator instead of an incoming payload    -->
                        <!-- causing a loop like behaviour.                                  -->
                        <plugin-event-representation uri="type://xml/apacheaxiom/OMNode" 
                          class-name="com.espertech.esperio.representation.axiom.AxiomEventRepresentation"/>
                            <plugin-event-type alias="AxiomEvent">
                            <resolution-uri value="type://xml/apacheaxiom/OMNode"/>
                            <initializer>
                                <xml-axiom root-element-name="tick" default-namespace="http://mycom.com/ns/tick">
                                     <namespace-prefix prefix="t" namespace="http://mycom.com/ns/tick"/>
                                     <xpath-property property-name="symbol" xpath="//t:tick/t:s" type="string"/>
                                     <xpath-property property-name="price" xpath="//t:tick/t:p" type="number"/>
                                </xml-axiom>
                            </initializer>
                        </plugin-event-type>
                    </esper-configuration>
                </property>
                <!-- A URI is used to share the Esper instance between multiple mediators.   -->
                <!-- The second mediator will not require to configure Esper, but make use   -->
                <!-- of the configured instance.                                             -->
                <property name="InstanceURI" value="urn:CEPInstance"/>
                <!-- In here we define the EPL statment this is applied on the events that   -->
                <!-- processed by Esper. The EPL statement is quite similar to a SQL         -->
                <!-- statement. Also, another interesting fact is that it treats a type of   -->
                <!-- event as a source.                                                      -->
                <property name="Statement" value="select xsymbol from StockQuoteEvent"/>
                <!-- The 'To' Address to which the event generated by Esper is forwarded is  -->
                <!-- defined in here.                                                        -->
                <property name="EventToAddress" value="http://localhost:8999/soap/EventListener"/>
            </class>
        </filter>
    </in>
    <!-- Afterwards a filter is applied to select messages having the 'To' Address equal     -->
    <!-- to http://localhost:9900/soap/Tick. This makes it possible to filter the events     -->
    <!-- generated by the Message Generator that creates tick events per every interval.     -->
    <filter source="get-property('To')" regex="http://localhost:9900/soap/Tick">
        <!-- Next we setup the SCI-Flex Axiom Mediator, which is a Synapse-Esper Medoiator   -->
        <!-- designed to specifically handle messages representable in Axiom format. This is -->
        <!-- the second mediator used in this example. The two mediators share the same CEP  -->
        <!-- instance by using the same instance URI.                                        -->
        <class name="org.sciflex.plugins.synapse.esper.mediators.AxiomMediator">
            <!-- A URI is used to share the Esper instance between multiple mediators. The   -->
            <!-- second mediator will not require to configure Esper, but make use of the    -->
            <!-- configured instance.                                                        -->
            <property name="InstanceURI" value="urn:CEPInstance"/>
            <!-- In here we define the EPL statment this is applied on the events that       -->
            <!-- processed by Esper. The EPL statement is quite similar to a SQL statement.  -->
            <!-- Also, another interesting fact is that it treats a type of event as a       -->
            <!-- source.                                                                     -->
            <property name="Statement" value="select a.price as price from AxiomEvent.win:length_batch(10) as a, StockQuoteEvent.std:lastevent() as b where a.symbol = b.xsymbol"/>
            <!-- The 'To' Address to which the event generated by Esper is forwarded is      -->
            <!-- defined in here.                                                            -->
            <property name="EventToAddress" value="http://localhost:8999/soap/Tick"/>
        </class>
    </filter>
    <!-- In here, another filter is applied to the flow of messages, and the address in      -->
    <!-- concern is now different. Add the capturing of the message in this filter is to     -->
    <!-- solely make it possible to log the outgoing payload.                                -->
    <filter source="get-property('To')" regex="http://localhost:8999/soap/.*">
        <!-- A log level of full means that generally everything is logged.                  -->
        <log level="full"/>
    </filter>
    <!-- A switch filer to switch based on the 'To' Address which is intended to determine   -->
    <!-- the destiny of the of the event in here.                                            -->
    <switch source="get-property('To')">
        <!-- Any message sent to http://localhost:.9../soap/Tick will be dropped at the ESB  -->
        <!-- and not forwarded any beyond. Please note that the address is specified as a    -->
        <!-- regular expression.                                                             -->
        <case regex="http://localhost:.9../soap/.*"/>
        <!-- All others will be blindly forwarded to their destinations                      -->
        <default>
            <send/>
        </default>
    </switch>
</definitions>

