#!/bin/sh

# Starts a toy xml-rpc server on the current host, suitable for the
# demo.rpc.CallAdder demo.

if [ -z "$JAVA_SAGA_LOCATION" ] ; then
    JAVA_SAGA_LOCATION="$SAGA_LOCATION"
    export JAVA_SAGA_LOCATION
fi

if [ -z "$JAVA_SAGA_LOCATION" ] ; then
    echo "please set JAVA_SAGA_LOCATION to the location of your SAGA installation" 1>&2
    exit 1
fi

# Jar-files from library.
XMLRPCSERVER_CLASSPATH=""
add_to_xmlrpcserver_classpath () {
    JARFILES=`cd "$1" && ls *.jar 2>/dev/null`
    for i in ${JARFILES} ; do
	if [ -z "$XMLRPCSERVER_CLASSPATH" ] ; then
	    XMLRPCSERVER_CLASSPATH="$1/$i"
	else
	    XMLRPCSERVER_CLASSPATH="$XMLRPCSERVER_CLASSPATH:$1/$i"
	fi
    done
}

add_to_xmlrpcserver_classpath $JAVA_SAGA_LOCATION/lib/adaptors/XMLRPCAdaptor

java -cp "$JAVA_SAGA_LOCATION/lib/saga-demo.jar:$XMLRPCSERVER_CLASSPATH:$CLASSPATH" demo.rpc.server.Server
