#!/usr/bin/perl
#
# Data_View
#
# A wrapper for the Data_View Java application.
#
#	The PIRL_JAVA_HOME enviroment variable, if it is set, will be
#	prepended to the java runtime classpath. The value of PIRL_JAVA_HOME
#	may be a directory pathname where the PIRL subdirectory and all its
#	class files is located; or it may be the pathname to a jar file -
#	e.g. PIRL.jar - containing the class files for the PIRL Java
#	Packages.
#
#	N.B.: If the PIRL_JAVA_HOME enviroment variable is not set but the
#	/opt/java/PIRL pathname exists, then /opt/java will be used for the
#	value of PIRL_JAVA_HOME.
#
#	If the CLASSPATH environment variable is set its value is appended to
#	the java runtime classpath.
#
#	The location of the following third party packages are expected to be
#	in the java runtime classpath:
#
#	MySQL_JDBC - http://dev.mysql.com/downloads/connector/j/
#
#	The pathname to the MySQL JDBC driver jar file or the root directory
#	where its class files are located. Either the MySQL JDBC Driver or
#	the PostgreSQL JDBC Driver is required to provide Database support.
#	Default: $PIRL_JAVA_HOME/mysql-connector/mysql-connector.jar
#
#	PostgreSQL_JDBC - http://jdbc.postgresql.org/
#
#	The pathname to the PostgreSQL JDBC driver jar file or the root
#	directory where its class files are located. Either the PostgreSQL
#	JDBC Driver or the MySQL JDBC Driver is required to provide Database
#	support.
#	Default: $PIRL_JAVA_HOME/PostgreSQL/postgresql.jar
#
#	JCM - http://math.hws.edu/javamath
#
#	The pathname to the Java Components for Mathematics jar file or the
#	root directory where its class files are located. This package is a
#	required dependency.
#	Default: $PIRL_JAVA_HOME/jcm/jcm_data.jar
#
#	Note: On Apple OS X (Darwin) systems the Java Virtual Machine will
#	automatically include jar files in the ~/Library/Java/Extensions and
#	/Library/Java/Extensions directories, if they exist, in the java
#	runtime classpath.
#
#
#	CVS ID: Data_View,v 1.3 2011/10/27 22:52:39 castalia Exp

$CLASSPATH		= $ENV{"CLASSPATH"};

$PIRL_JAVA_HOME	= $ENV{"PIRL_JAVA_HOME"};
$PIRL_JAVA_HOME = "/opt/java"
	if (! $PIRL_JAVA_HOME &&
		-e "/opt/java/PIRL");
Add_to_CLASSPATH ($PIRL_JAVA_HOME);

$MySQL_JDBC = "$PIRL_JAVA_HOME/mysql-connector/mysql-connector.jar"
	unless $MySQL_JDBC = $ENV{"MySQL_JDBC"};
Add_to_CLASSPATH ($MySQL_JDBC);

$PostgreSQL_JDBC = "$PIRL_JAVA_HOME/PostgreSQL/postgresql.jar"
	unless $PostgreSQL_JDBC = $ENV{"PostgreSQL_JDBC"};
Add_to_CLASSPATH ($PostgreSQL_JDBC);

$JCM = "$PIRL_JAVA_HOME/jcm/jcm_data.jar"
	unless $JCM = $ENV{"JCM"};
Add_to_CLASSPATH ($JCM);


@Arguments = (java);
push @Arguments, "-cp", $CLASSPATH
	if $CLASSPATH;

push @Arguments, "PIRL.Database.Data_View", @ARGV;

exec @Arguments;


sub Add_to_CLASSPATH
{
my ($pathname) = @_;

if (-e "$pathname")
	{
	if ($CLASSPATH)
		{
		$CLASSPATH = "$CLASSPATH:$pathname"
			unless "$pathname" =~ /"$pathname"/;
		}
	else
		{
		$CLASSPATH = $pathname;
		}
	}
}
