#!/bin/sh
#
# Script for start UML Server and ServerId, needed for
# new version of CUTE.
#

HOST="localhost"
PORT=3000
FILE="tests.uml"

DATA=""
USER=""
PASS=""
NAT=""

while [ $# -gt 0 ]; do
	
	if [ "$1" = "-?" -o "$1" = "--help"  ]; then
		echo ""
		echo "USAGE: StartServers [-h hostname] [-p port number] [-f filename] [-d database name] [-u user database name] [-pwd user password] [-nat]"
		echo ""
		echo "-h hostname	server name"
		echo "-p port   	CUTE server port number"
		echo "-f file   	CUTE diagram file"
		echo "-d database	database name"
		echo "-u user   	database user"
		echo "-pwd password	user database password"
		echo "-nat		use native threads"
		exit
	fi

	#host name option
	if [ "$1" = "-h" ]; then
		shift
		HOST="$1"
	fi

	#port number option
	if [ "$1" = "-p" ]; then 
		shift
		PORT=$1			
	fi

	#file name option
	if [ "$1" = "-f" ]; then
		shift
		FILE=$1
	fi

	#database option
	if [ "$1" = "-d" ]; then
		shift
		DATA="-d $1"
	fi

	#user database option
	if [ "$1" = "-u" ]; then
		shift
		USER="-u $1"
	fi

	#password for user database option
	if [ "$1" = "-pwd" ]; then
		shift
		PASS="-s $1"
	fi

	#native threads option
	if [ "$1" = "-nat" ]; then
		PASS="-native"
	fi

	shift

done

#just for testing
#echo $HOST $FILE $PORT $DATA $USER $PASS
#exit

nohup java $NAT  BW.UML.ObjId.ServerID -h $HOST $DATA $USER $PASS  > ServerID.out 2> ServerID.err & 

nohup java $NAT TOOL.UML.SERVER.UMLServerApp $PORT $FILE > UMLServerApp.out 2> UMLServerApp.err &

