#!/bin/sh
# ---------------------------------------------------------------------------
# JOnAS: Java(TM) Open Application Server
# Copyright (C) 1999 Bull S.A.
# Contact: jonas-team@objectweb.org
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA
#
# Initial developer(s): Philippe Durieux
# Contributor(s): ______________________________________.
#
# ---------------------------------------------------------------------------
# $Id: jclient.sh,v 1.4 2002/12/10 15:59:43 durieuxp Exp $
# ---------------------------------------------------------------------------

# Check JONAS_ROOT is set. A remote client should have JONAS_ROOT set on a
# subset of the JONAS install directory (See objectweb/jonas/build.xml)
JONAS_LIB=$JONAS_ROOT/lib
if [ ! -d $JONAS_ROOT/lib ]
then
    echo "JONAS_ROOT must be set"
    exit 1
fi
. $JONAS_ROOT/bin/unix/setenv

# ---------------------------------------------
# Get args
# ---------------------------------------------
ARGS=
COSNAMING_PORT=14727
COSNAMING_HOST=localhost
while [ "$#" -gt 0 ]
do	case "$1" in
	-cp)
		shift
		CLASSPATH=$CLASSPATH$SPS$1
		;;
	-cnhost)
		shift
		COSNAMING_HOST=$1
		;;
	-cnport)
		shift
		COSNAMING_PORT=$1
		;;
	-D*)
		JAVA_OPTS="$JAVA_OPTS $1"
		;;
	*)
		# all other args are passed "as is" to the java program
		ARGS="$ARGS $1"
		;;
	esac
	shift
done

if [ -f $JONAS_LIB/${OBJECTWEB_ORB}_client.jar ]
then
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/${OBJECTWEB_ORB}_client.jar
else
    # Clients may use all these
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/j2ee/ejb.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/j2ee/jaas1_0.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/j2ee/jndi.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/j2ee/jta-spec1_0_1.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/j2ee/jts-spec1_0.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/j2ee/providerutil.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/j2ee/jms.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/joram/mom.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/joram/joram.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/joram/JCup.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/log/ow_util_log_wrp_log4j.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/log/ow_util_log_wrp_pw_only.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/log/ow_util_log_file.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/log/log4j.jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/connector/ow_tx_api.jar

    # should only put here a minimum client jar
    CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/common/ow_jonas.jar

    # add ORB dependant libraries
    case "$OBJECTWEB_ORB" in
    DAVID)
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/david/ow_jonas_$OBJECTWEB_ORB.jar
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/jonathan/jonathan.jar
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/jonathan/kilim.jar
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/jonathan/nanoxml-lite-2.2.1.jar
        ;;
    RMI)
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/rmi/ow_jonas_$OBJECTWEB_ORB.jar
        ;;
    JEREMIE)
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/jeremie/ow_jonas_$OBJECTWEB_ORB.jar
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/jonathan/jonathan.jar
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/jonathan/kilim.jar
        CLASSPATH=$CLASSPATH$SPS$JONAS_LIB/jonathan/nanoxml-lite-2.2.1.jar
        ;;
    *)
        echo "OBJECTWEB_ORB must be set"
        exit 1
        ;;
    esac
fi

# ---------------------------------------------
# CLASSPATH can be upgraded here : 
# i.e. to run JOnAS examples
# ---------------------------------------------
CLASSPATH=$CLASSPATH$SPS$JONAS_ROOT/examples/classes

# ---------------------------------------------
# Set options for DAVID
# ---------------------------------------------
if [ "$OBJECTWEB_ORB" = "DAVID" ]
then
    JAVA_OPTS="$JAVA_OPTS \
    -Dorg.omg.CORBA.ORBClass=org.objectweb.david.libs.binding.orbs.iiop.IIOPORB \
    -Dorg.omg.CORBA.ORBSingletonClass=org.objectweb.david.libs.binding.orbs.ORBSingletonClass \
    -Djavax.rmi.CORBA.StubClass=org.objectweb.david.libs.stub_factories.rmi.StubDelegate \
    -Djavax.rmi.CORBA.PortableRemoteObjectClass=org.objectweb.david.libs.binding.rmi.ORBPortableRemoteObjectDelegate \
    -Djavax.rmi.CORBA.UtilClass=org.objectweb.david.libs.helpers.RMIUtilDelegate \
    -Ddavid.CosNaming.default_method=0 \
    -Ddavid.rmi.ValueHandlerClass=com.sun.corba.se.internal.io.ValueHandlerImpl \
    -Ddavid.CosNaming.default_host=$COSNAMING_HOST \
    -Ddavid.CosNaming.default_port=$COSNAMING_PORT \
    "
fi

$JAVA $JAVA_OPTS $ARGS
