/*
* Client Implementation for Cookie Server
*/

package corbacookie;

import corbacookie.Cookie.*;	// Our package defining the proxy class
import org.omg.CosNaming.*;	// Support for naming service
import org.omg.CORBA.*;		// support for the CORBA objects themselves

/**
 * public class client
 * Contains the main method which will submit requests to the server
 */

public class cclient {

    public static void main(String args[]) {
    // Be good and always wrap code in try blocks!
	try {

	    // create and initialize the ORB
	    // If this was as applet instead we would replace
	    // args with the this pointer
	    // so that the ORB could get arguments from it.
	    ORB orb = ORB.init(args, null);

	    // get the root naming context
            org.omg.CORBA.Object objRef = 
			orb.resolve_initial_references("NameService");
            NamingContext ncRef = NamingContextHelper.narrow(objRef);
 
            // resolve the Object Reference in Naming
            NameComponent nc = new NameComponent("CookieServer", "");
            NameComponent path[] = {nc};
	    // use the narrow method to resolve our refence
	    CookieServer myCookie =
		    CookieServerHelper.narrow(ncRef.resolve(path));

	    /*
	     * We now have an object which we can talk to.
	     */
	    System.out.println("Ordered:\n---------");
	    for (int i=0; i<5; i++) {
		System.out.println(myCookie.getCookie(i));
	    }
	    System.out.println("Random :\n---------");
	    for (int i=0; i<5; i++) {
		System.out.println(myCookie.getRandomCookie());
	    }
	} catch (Exception e) {
	    System.out.println("ERROR : " + e) ;
	    e.printStackTrace(System.out);
	}
    }
}
