//
//Server.  If successfull should send cookies
//
package rmicookie;

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class CookieServerImpl	extends UnicastRemoteObject
				implements CookieServer {

    // some star trek cookies
    static final String cookies[] = {
		"Scotch me up, Beamy !!!",
		"Logic is the beginning of wisdom, not it's end !",
		"Take us home, Mr. Scott !",
		"I don't know any more Star Trek cites ;-)"
    };

    // empty constructor
    public CookieServerImpl() throws java.rmi.RemoteException {}

    // getCookie Method
    public String getCookie(int i) throws RemoteException {
	String c;
	if (i >= 0 && i < cookies.length) {
	    c = cookies[i];
	} else {
	    c = "No such cookie !";
	}
	System.out.println("Returning " + c);
	return c;
    }
    
    public static void main(String args[]) {
	// Create and install security manager
	//System.setSecurityManager(new RMISecurityManager());
	
	try {
	    CookieServerImpl server = new CookieServerImpl();
	    System.out.println("CookieServer created.");
	    Naming.rebind("rmi://orion.rz.uni-ulm.de/CookieServer", server);
	    System.out.println("CookieServer registered.");
	} catch (Exception x) {
	    x.printStackTrace();
	}
    }

}
