#!/bin/sh

DBXML_HOME=/usr/local/share/java/dbXML

CMD_NAME=`basename $0`

# Read in the list of dbXML Jars to include in the CLASSPATH
JARS=`ls -1 $DBXML_HOME/java/lib/*.jar`
JAR_LIST=""
for jar in $JARS ; do
   JAR_LIST="$JAR_LIST `basename $jar`"
   CLASSPATH=$jar:$CLASSPATH ;
done

# Read in the extra VM paramters for starting the program
VMPROPS=""
if test -f $DBXML_HOME/config/vm.cfg; then
   PROPS="`cat $DBXML_HOME/config/vm.cfg`"
   for prop in $PROPS
   do
      VMPROPS="$VMPROPS $prop"
   done
fi

GUI=0
APP_NAME=""
case $CMD_NAME in
   dbxml-gui)	CLASS_NAME="com.dbxml.db.admin.Admin"; GUI=1; APP_NAME="Administrator" ;;
   dbxml)	CLASS_NAME="com.dbxml.db.client.tools.CommandLine"; GUI=0; APP_NAME="Shell" ;;
   *)           echo "Error mapping command link to Java class"
                exit 1 ;;
esac

if test $GUI = 1 ; then
   OS=`uname`
   if test "$OS" = "Darwin" ; then
      VMPROPS="$VMPROPS -Dapple.laf.useScreenMenuBar=true"
      VMPROPS="$VMPROPS -Dapple.awt.antialiasing=true"
      VMPROPS="$VMPROPS -Dapple.awt.showGrowBox=true"
      VMPROPS="$VMPROPS -Dcom.apple.mrj.application.apple.menu.about.name=$APP_NAME"
      VMPROPS="$VMPROPS -Xdock:icon=$DBXML_HOME/docs/images/$CMD_NAME.icns"
   else
      VMPROPS="$VMPROPS -Dswing.defaultlaf=com.incors.plaf.kunststoff.KunststoffLookAndFeel"
   fi
fi

/usr/local/bin/java -classpath "$CLASSPATH" -Xms16m -Xmx128m -Ddbxml.home="$DBXML_HOME" $VMPROPS $CLASS_NAME $*
