//
// Actual implementation of the CookieServer Interface
//
package corbacookie;

import corbacookie.Cookie.*;

import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;

import java.util.Random;

class CookieServerImpl extends _CookieServerImplBase {

    // Random number generator
    Random r = new Random();

    // 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 ;-)"
    };

    public String getRandomCookie() {

	int i = r.nextInt(cookies.length-1);

	return getCookie(i);
    }

    public String getCookie(int i) {
	String c;
	if (i >= 0 && i < cookies.length) {
	    c = cookies[i];
	} else {
	    c = "No such cookie !";
	}
	System.out.println("Returning " + c);
	return c;
    }
}
