@echo off
setlocal
if "%MULE_HOME%" == "" SET MULE_HOME=%~dp0..\..
if "%MULE_BASE%" == "" SET MULE_BASE=%MULE_HOME%

if exist "%MULE_HOME%" goto :continue
echo You must set the environment variable MULE_HOME to the location of your Mule install in order to run this example.
goto :eof

:continue
REM Translate MULE_HOME to unix notation. That's used to create a system property
REM mule.home.unix below which is used to configure openejb
set MULE_HOME_UNIX="%MULE_HOME:\=/%"

REM This extends the classpath to include the configuration directory
REM Any changes to the files in .\conf will take precedence over those deployed to %MULE_HOME%\lib\user
SET MULE_LIB=.\conf

REM 3rd party libraries for LoanBroker ESB
SET ACTIVEMQ=activemq-core-4.1.2.jar
SET OPENEJB=openejb-core-1.0.jar
REM 3rd party libraries for LoanBroker BPM
SET BSH=bsh-1.3.0.jar
SET DERBYDB=derby-10.3.1.4.jar

:testactivemq
if exist "%MULE_BASE%\lib\user\%ACTIVEMQ%" goto :testopenejb
if exist "%MULE_HOME%\lib\user\%ACTIVEMQ%" goto :testopenejb
goto :missinglibs

:testopenejb
if exist "%MULE_BASE%\lib\user\%OPENEJB%" goto :testbsh
if exist "%MULE_HOME%\lib\user\%OPENEJB%" goto :testbsh
goto :missinglibs

:testbsh
if exist "%MULE_BASE%\lib\user\%BSH%" goto :testderbydb
if exist "%MULE_HOME%\lib\user\%BSH%" goto :testderbydb
goto :missinglibs

:testderbydb
if exist "%MULE_BASE%\lib\user\%DERBYDB%" goto :mule
if exist "%MULE_HOME%\lib\user\%DERBYDB%" goto :mule

:missinglibs
echo This example requires additional libraries which need to be downloaded by the build script.  Please follow the instructions in the README.txt file.
goto :eof

:mule
REM ECHO The Loan Broker example is available in five flavors:
REM ECHO   1. Loan Broker ESB 
REM ECHO   2. Loan Broker ESN - synchronous
REM ECHO   3. Loan Broker ESN - asynchronous
REM ECHO   4. Loan Broker BPM
REM SET /P Choice=Select the one you wish to execute and press Enter...

REM IF '%Choice%'=='1' call "%MULE_BASE%\bin\mule.bat" -app loanbroker-esb -M-Dmule.home.unix="%MULE_HOME_UNIX%"
REM IF '%Choice%'=='2' call "%MULE_BASE%\bin\mule.bat" -app loanbroker-esn-sync
REM IF '%Choice%'=='3' call "%MULE_BASE%\bin\mule.bat" -app loanbroker-esn-async
REM IF '%Choice%'=='4' call "%MULE_BASE%\bin\mule.bat" -app loanbroker-bpm

call "%MULE_BASE%\bin\mule.bat" -app loanbroker-esn-sync
