@Echo Off
Rem ---------------------------------------------------------------------------
Rem JOnAS: Java(TM) Open Application Server
Rem Copyright (C) 1999-2008 Bull S.A.S.
Rem Contact: jonas-team@objectweb.org
Rem
Rem This library is free software; you can redistribute it and/or
Rem modify it under the terms of the GNU Lesser General Public
Rem License as published by the Free Software Foundation; either
Rem version 2.1 of the License, or any later version.
Rem
Rem This library is distributed in the hope that it will be useful,
Rem but WITHOUT ANY WARRANTY; without even the implied warranty of
Rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Rem Lesser General Public License for more details.
Rem
Rem You should have received a copy of the GNU Lesser General Public
Rem License along with this library; if not, write to the Free Software
Rem Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
Rem USA
Rem
Rem Initial developer(s): Nicolas Tachker
Rem Contributor(s): S. Ali Tokmen:
Rem          - Automatic setting of JONAS_ROOT
Rem          - Fixed issues when using this batch in a folder contaning spaces
Rem ---------------------------------------------------------------------------
Rem $Id$
Rem ---------------------------------------------------------------------------

Rem Keep variables local to this script
setlocal ENABLEDELAYEDEXPANSION

Rem ---------------------------------------------
Rem set JAVA_OPTS
Rem ---------------------------------------------
Rem JAVA_HOME must be  set since config_env.bat requires it for tools.jar
if ["%JAVA_HOME%"]==[""] goto setjava

Rem  Check for JONAS_ROOT, if not set set it to the default
if "%JONAS_ROOT%"=="" Goto SetJONAS_ROOT
echo JONAS_ROOT is set to %JONAS_ROOT%
Goto ExecuteBatch

Rem %~dp0 is the directory in which this batch file is,
Rem therefore JONAS_ROOT\bin\nt in our case.
:SetJONAS_ROOT
pushd "%~dp0"
cd ..
cd ..
@set JONAS_ROOT=%CD%
@echo Setting JONAS_ROOT to %JONAS_ROOT%
popd

:ExecuteBatch
Rem ---------------------------------------------
Rem set environment
Rem ---------------------------------------------
call "%JONAS_ROOT%\bin\nt\setenv.bat"
call "%JONAS_ROOT%\bin\nt\config_env.bat"

Rem include jonas classes
set CLASSPATH=%JONAS_ROOT%\lib\common\ow_jonas_bootstrap.jar;%JONAS_ROOT%\lib\commons\jonas\jakarta-commons\commons-logging-api.jar;%CLASSPATH%


Set JORAM_LIBS=%JONAS_ROOT%\lib\commons\jonas\joram

rem Building the Classpath
Set CLASSPATH=%JORAM_LIBS%\joram-raconfig.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_api.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_core.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_file.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_helper.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_remote.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_common.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_javalog.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_log4j.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_p6spy.jar
Set CLASSPATH=%CLASSPATH%;%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_pw.jar

set RARJORAM="%JONAS_BASE%\rars\autoload\joram_for_jonas_ra.rar"
set HOST=localhost
set PORT=16010
set SERVER=0

Rem ---------------------------------------------
Rem Get args
Rem ---------------------------------------------
if [%1]==[]   goto no_arg

:loop_on_args
Set VALUE=%~1
if [%1]==[-p]    goto port_arg
if [%1]==[-h]    goto host_arg
if [%1]==[-s]    goto sid_arg
set ARGS=%ARGS% %1
goto next_arg

:port_arg
shift
if [%1]==[] goto usage
set PORT=%1
goto next_arg

:host_arg
shift
if [%1]==[] goto usage
set HOST=%1
goto next_arg

:sid_arg
shift
if [%1]==[] goto usage
set SERVER=%1
goto next_arg

:next_arg
shift
if not [%1]==[] goto loop_on_args

Rem ---------------------------------------------
Rem Run java command
Rem ---------------------------------------------
REM start Joram RAConfig
%JAVA% %JAVA_OPTS% -cp "%CLASSPATH%" org.objectweb.joram.client.connector.utils.RAConfig -rar %RARJORAM% -uhp %HOST% %PORT% %SERVER% -conf "%JONAS_BASE%\conf"
goto :EOF

:setjava
echo JAVA_HOME not set.
goto :EOF

:no_arg
echo No arguments specified.
goto usage

:usage
echo "Usage : joram_raconfig.bat -p <port> -h <host> -s <serverid>"
goto :EOF
