<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:spring="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:bpm="http://www.mulesource.org/schema/mule/bpm/2.0"
       xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.0"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.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.0 http://www.mulesource.org/schema/mule/core/2.0/mule.xsd
       http://www.mulesource.org/schema/mule/bpm/2.0 http://www.mulesource.org/schema/mule/bpm/2.0/mule-bpm.xsd
       http://www.mulesource.org/schema/mule/vm/2.0 http://www.mulesource.org/schema/mule/vm/2.0/mule-vm.xsd">

    <bpm:connector name="bpmConnector" bpms-ref="jbpm"/>

    <model name="processModel">

        <service name="fromSimpleProcess">
            <inbound>
                <bpm:inbound-endpoint process="simple"/>
            </inbound>
            <component class="org.mule.component.simple.LogComponent"/>
        </service>

        <service name="fromMessageProcess">
            <inbound>
                <bpm:inbound-endpoint process="message"/>
            </inbound>
            <component class="org.mule.component.simple.LogComponent"/>
            <outbound>
                <outbound-pass-through-router>
                    <vm:outbound-endpoint path="echo"/>
                </outbound-pass-through-router>
            </outbound>
        </service>

        <service name="echoService">
            <inbound>
                <vm:inbound-endpoint path="echo"/>
            </inbound>
            <component class="org.mule.component.simple.EchoComponent"/>
        </service>

    </model>

    <!-- ***************************************************
    BPMS Configuration
    *************************************************** -->

    <context:property-placeholder location="classpath:derby.properties"/>
    
    <!-- BPMS object for Mule's BPM Connector -->
    <spring:bean id="jbpm" class="org.mule.transport.bpm.jbpm.Jbpm" destroy-method="destroy">
        <spring:property name="jbpmConfiguration">
            <spring:ref local="jbpmConfig"/>
        </spring:property>
    </spring:bean>

    <!-- jBPM Configuration -->
    <spring:bean id="jbpmConfig" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
        <spring:property name="sessionFactory">
            <spring:ref local="jbpmSessionFactory"/>
        </spring:property>
        <spring:property name="configuration">
            <spring:value>jbpm.cfg.xml</spring:value>
        </spring:property>
        <spring:property name="createSchema">
            <spring:value>false</spring:value>
        </spring:property>
    </spring:bean>

    <!-- JBPM Hibernate SessionFactory -->
    <spring:bean id="jbpmSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <spring:property name="dataSource">
            <spring:ref local="jbpmDataSource"/>
        </spring:property>
        <spring:property name="mappingLocations">
            <spring:value>classpath*:/org/jbpm/**/*.hbm.xml</spring:value>
        </spring:property>
        <spring:property name="typeDefinitions">
            <spring:ref local="jbpmTypes"/>
        </spring:property>
        <spring:property name="hibernateProperties">
            <spring:props>
                <!-- These properties may depend on your database -->
                <spring:prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</spring:prop>
                <spring:prop key="hibernate.query.substitutions">true 1, false 0</spring:prop>
                <spring:prop key="hibernate.jdbc.batch_size">0</spring:prop>
                <!-- Create/update the database tables automatically when the JVM starts up -->
                <spring:prop key="hibernate.hbm2ddl.auto">update</spring:prop>
                <!-- EhCache is no longer the default cache provider as of Hibernate 3.2 
                  Refer to http://www.hibernate.org/hib_docs/v3/reference/en/html/performance.html
                  for Hibernate's different cache providers. -->
                <spring:prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider
                </spring:prop>
                <!-- C3P0 (connection pooling) properties -->
                <spring:prop key="hibernate.c3p0.min_size">1</spring:prop>
                <spring:prop key="hibernate.c3p0.max_size">3</spring:prop>
                <!-- Write SQL statements to log -->
                <spring:prop key="hibernate.show_sql">false</spring:prop>
            </spring:props>
        </spring:property>
    </spring:bean>

    <!-- JBPM Datasource -->
    <spring:bean id="jbpmDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <spring:property name="driverClassName">
            <spring:value>org.apache.derby.jdbc.EmbeddedDriver</spring:value></spring:property>
        <spring:property name="url">
            <spring:value>${database.connection}</spring:value></spring:property>
    </spring:bean>

    <!-- JBPM data types -->
    <spring:bean id="jbpmTypes" class="org.springframework.orm.hibernate3.TypeDefinitionBean">
        <spring:property name="typeName">
            <spring:value>string_max</spring:value>
        </spring:property>
        <spring:property name="typeClass">
            <spring:value>org.jbpm.db.hibernate.StringMax</spring:value>
        </spring:property>
    </spring:bean>

</mule>
