/*
* Client Implementation for HelloWorld Server
*/

package corbahw;

import corbahw.HelloWorld.*;	// 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 hwclient {

    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("HelloWorld", "");
            NameComponent path[] = {nc};
	    // use the narrow method to resolve our refence
	    HelloWorld myHW =
		    HelloWorldHelper.narrow(ncRef.resolve(path));

	    /*
	     * We now have an object which we can talk to.
	     */
	    System.out.println(myHW.HelloWorld());
	} catch (Exception e) {
	    System.out.println("ERROR : " + e) ;
	    e.printStackTrace(System.out);
	}
    }
}
