@echo off
rem find DBXML_HOME
if not "%DBXML_HOME%"=="" goto checkJava

rem check for dbXML in Program Files on system drive
if not exist "%SystemDrive%\Program Files\dbXML" goto checkSystemDrive
set DBXML_HOME=%SystemDrive%\Program Files\dbXML
goto checkJava

:checkSystemDrive
rem check for dbXML in root directory of system drive
if not exist "%SystemDrive%\dbXML" goto checkdbXML
set DBXML_HOME=%SystemDrive%\dbXML
goto checkJava

:checkdbXML
rem check for dbXML in root directory of system drive
if not exist "%SystemDrive%\dbXML" goto checkWorkdbXML
set DBXML_HOME=%SystemDrive%\dbXML
goto checkJava

:checkWorkdbXML
rem check for dbXML in root directory of system drive
if not exist "%SystemDrive%\work\dbXML" goto checkCurrent
set DBXML_HOME=%SystemDrive%\work\dbXML
goto checkJava

:checkCurrent
if exist ".\config" set DBXML_HOME=
echo %DBXML_HOME%
goto checkJava

:nodbXMLHome
echo DBXML_HOME is not set and dbXML could not be located. Please set DBXML_HOME.
goto end

:checkJava
if "%JAVACMD%" == "" set JAVACMD=java

set LOCALCLASSPATH=%CLASSPATH%
for %%i in ("%DBXML_HOME%\java\lib\*.jar") do call "%DBXML_HOME%\bin\lcp.bat" %%i

if "%JAVA_HOME%" == "" goto runCommand
if exist "%JAVA_HOME%\lib\tools.jar" call "%DBXML_HOME%\bin\lcp.bat" %JAVA_HOME%\lib\tools.jar
if exist "%JAVA_HOME%\lib\classes.zip" call "%DBXML_HOME%\bin\lcp.bat" %JAVA_HOME%\lib\classes.zip

:runCommand

set CL=
:loop
if "%1"=="" goto done
set CL=%CL% %1
shift
goto loop
:done

cd %DBXML_HOME%

set JAVA_PARAMS=
set JAVA_PARAMS=%JAVA_PARAMS% -Xms64m 
set JAVA_PARAMS=%JAVA_PARAMS% -Xmx384m

set JAVA_PROPS=
set JAVA_PROPS=%JAVA_PROPS% -Ddbxml.home="%DBXML_HOME%"
set JAVA_PROPS=%JAVA_PROPS% -Dcmd.home="%DBXML_HOME%\bin" 
set JAVA_PROPS=%JAVA_PROPS% -Dlabrador.quiet=true
set JAVA_PROPS=%JAVA_PROPS% -Dlabrador.config="%DBXML_HOME%\config\labrador.xml"  
set JAVA_PROPS=%JAVA_PROPS% -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl 
set JAVA_PROPS=%JAVA_PROPS% -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl

set JAVA_CLASS=com.dbxml.db.server.ServerBootstrap
%JAVACMD% %JAVA_PARAMS% %JAVA_PROPS% -classpath "%LOCALCLASSPATH%" %JAVA_CLASS% %CL%

:end
set LOCALCLASSPATH=

