#!/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): ____________________________________.
# Contributor(s): 
#     Emmanuel Cecchet: $JAVA_OPTS as last parameters for JVM
#
# ---------------------------------------------------------------------------
# $Id$
# ---------------------------------------------------------------------------

if [ ! -f $JONAS_ROOT/bin/unix/config_env ]
then
    echo "JONAS_ROOT must be set"
    exit 1
fi

. $JONAS_ROOT/bin/unix/config_env

TOMCAT_OPTS=""
if [ -n "$TOMCAT_HOME" ]
then
   TOMCAT_OPTS="$TOMCAT_OPTS -Dtomcat.home=$TOMCAT_HOME"
fi
if [ -n "$CATALINA_HOME" ]
then
   TOMCAT_OPTS="$TOMCAT_OPTS -Dcatalina.home=$CATALINA_HOME"
fi
if [ -n "$CATALINA_BASE" ]
then
   TOMCAT_OPTS="$TOMCAT_OPTS -Dcatalina.base=$CATALINA_BASE"
fi

if [ "$OBJECTWEB_ORB" = "DAVID" ]
then
    if [ "$1" = "" ]
    then
	echo "Usage: 'EJBServer host port' where host and port are the address of a running CosNaming"
	echo "Example: EJBServer localhost 14727"
    else
    if [ "$2" = "" ]
    then
	echo "Usage: 'EJBServer host port' where host and port are the address of a running CosNaming"
	echo "Example: EJBServer localhost 14727"
    else
	host=$1
	port=$2
	shift
	shift
	$JAVA \
	-Dinstall.root=$JONAS_ROOT \
	-Djava.security.policy=$JONAS_ROOT/config/java.policy \
	-Dtomcat.home=$TOMCAT_HOME \
	-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=$host \
	-Ddavid.CosNaming.default_port=$port \
	$JAVA_OPTS \
	org.objectweb.jonas.server.Server \	
	"$@"
    fi
    fi
else
    $JAVA \
    -Dinstall.root=$JONAS_ROOT -Djava.security.policy=$JONAS_ROOT/config/java.policy \
    $TOMCAT_OPTS \
    $JAVA_OPTS \
    org.objectweb.jonas.server.Server \
    "$@"
fi
