<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:spring="http://www.springframework.org/schema/beans"
       xmlns:script="http://www.mulesource.org/schema/mule/scripting/2.2"
       xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
       xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
       xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
       http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
       http://www.mulesource.org/schema/mule/scripting/2.2 http://www.mulesource.org/schema/mule/scripting/2.2/mule-scripting.xsd
       http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
       http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">

    <description>
        This example demonstrates invoking a JSR-223 script as the service component.
    </description>
    
    <!--
    Adds the default configuration for the 'scriptfile' and 'currency' variables below.
    Users can override these values by passing them as VM parameters i.e. -Dcurrency=GBP.
    If running from the example shell script you will be prompted with options.
    -->
    <context:property-placeholder location="default-config.properties"/>
    
    <configuration defaultSynchronousEndpoints="true"/>
        
    <stdio:connector name="SystemStreamConnector"
                     promptMessage="How much more change do you need? (enter an amount such as 2.37)"
                     messageDelayTime="1000"/>

    <custom-transformer name="StringToNumber" class="org.mule.example.scripting.StringToNumber"/>

    <custom-transformer name="DollarsToCents" class="org.mule.example.scripting.SimpleMathTransformer">
        <spring:property name="operation" value="multiply"/>
        <spring:property name="factor" value="100"/>
    </custom-transformer>

    <model name="main">
        <service name="Accumulator">
            <inbound>
                <stdio:inbound-endpoint system="IN" transformer-refs="StringToNumber DollarsToCents"/>
                <!-- For unit testing -->
                <vm:inbound-endpoint path="input" transformer-refs="DollarsToCents"/>
            </inbound>
            <component>
                <singleton-object class="org.mule.example.scripting.AccumulatorComponent"/>
            </component>
            <outbound>
                <chaining-router>
                    <vm:outbound-endpoint path="script"/>
                    <stdio:outbound-endpoint system="OUT"/>
                </chaining-router>
            </outbound>
        </service>

        <service name="ScriptService">
            <inbound>
                <vm:inbound-endpoint path="script"/>
            </inbound>
            <script:component>
                <script:script file="${scriptfile}">
                    <property key="currency" value="${currency}"/>
                </script:script>
            </script:component>
        </service>
    </model>
</mule>
