#!/bin/csh -f
#
#	CVS ID: Conductor1,v 2.1 2008/09/11 02:21:21 castalia Exp
#
# Conductor1
#
# A wrapper for the Java process management application, first generation.

#	Location of the PIRL Java Packages.
if (! $?PIRL_JAVA_HOME) set PIRL_JAVA_HOME = /opt/java
if (! -e ${PIRL_JAVA_HOME}) then
	echo "No such file or directory: ${PIRL_JAVA_HOME}"
	exit -1
endif
set classpath = $PIRL_JAVA_HOME

#	Database drivers:

#	Location of the MySQL JDBC driver.
if (! $?MySQL_JDBC) then
	if ($PIRL_JAVA_HOME !~ "*.jar") \
		set MySQL_JDBC = $PIRL_JAVA_HOME/mysql-connector
endif
if ($?MySQL_JDBC) then
	if (! -e ${MySQL_JDBC}) then
		echo "No such file or directory: ${MySQL_JDBC}"
		exit -1
	endif
	set classpath = ${classpath}:${MySQL_JDBC}
endif

#	Location of the PostgreSQL JDBC driver.
if (! $?PostgreSQL_JDBC) then
	if ($PIRL_JAVA_HOME !~ "*.jar") \
		set PostgreSQL_JDBC = $PIRL_JAVA_HOME/PostgreSQL/postgresql.jar
endif
if ($?PostgreSQL_JDBC) then
	if (! -e ${PostgreSQL_JDBC}) then
		echo "No such file or directory: ${PostgreSQL_JDBC}"
		exit -1
	endif
	set classpath = ${classpath}:${PostgreSQL_JDBC}
endif

#	External Java packages:

#	Location of the Java Components for Mathematics.
if (! $?JCM) then
	if ($PIRL_JAVA_HOME !~ "*.jar") \
    	set JCM = $PIRL_JAVA_HOME/jcm
endif
if ($?JCM) then
	if (! -e ${JCM}) then
		echo "No such file or directory: ${JCM}"
		exit -1
	endif
	set classpath = ${classpath}:${JCM}
else
	echo "The Java Components for Mathematics are required by Conductor."
	echo "See http://math.hws.edu/javamath"
	exit -1
endif


#	Apple's OS X JVM won't allow Java classes to be run remotely
#	if they employ any graphics (Swing) functionality
#	regardless of whether this functionally is actually used.
#	The workaround is to tell the JVM to run "headless" when
#	the monitor mode is not specified on the command line.
set Graphics_Mode = -Djava.awt.headless=true
foreach arg ($argv)
	if ("$arg" =~ -[Mm]*) then
		set Graphics_Mode = ""
		break
	endif
end


#	Add the Conductor Native_Methods library location to the appropriate path.
set OS = `uname -s`
set PLATFORM = `uname -p`
set JNI_DIR = $OS.$PLATFORM
if (-d $PIRL_JAVA_HOME/PIRL/Conductor/JNI_DIR) then
	if ($PLATFORM == "powerpc") then
		if ($?DYLD_LIBRARY_PATH) then
			setenv DYLD_LIBRARY_PATH $PIRL_JAVA_HOME/PIRL/Conductor/${JNI_DIR}:$DYLD_LIBRARY_PATH
		else
			setenv DYLD_LIBRARY_PATH $PIRL_JAVA_HOME/PIRL/Conductor/${JNI_DIR}
		endif
	else
		if ($?LD_LIBRARY_PATH) then
			setenv LD_LIBRARY_PATH $PIRL_JAVA_HOME/PIRL/Conductor/${JNI_DIR}:$LD_LIBRARY_PATH
		else
			setenv LD_LIBRARY_PATH $PIRL_JAVA_HOME/PIRL/Conductor/${JNI_DIR}
		endif
	endif
endif


exec java $Graphics_Mode -cp $classpath PIRL.Conductor.Conductor1 $argv:q
