//
// hwserver
//
package corbahw;

import corbahw.HelloWorld.*;

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

/**
 * The server creates an ORB and binds our implementation class to it.
 * It then establishes itself as the server by name using the
 * NameComponent class and the rebind operation.
 *
 * The last thing it does is enter a loop waiting to process requests.
 */

public class hwserver {

   /**
    * Main method for starting at the command line
    */
    public static void main(String args[]) {
	try {
	    // create and initialize the ORB
	    ORB orb = ORB.init(args, null);

	    // create servant and register it with the ORB
	    HelloWorldImpl HelloWorldRef = new HelloWorldImpl();
	    orb.connect(HelloWorldRef);

	    // get the root naming context
	    org.omg.CORBA.Object objRef = 
		    orb.resolve_initial_references("NameService");
	    NamingContext ncRef = NamingContextHelper.narrow(objRef);

	    // bind the Object Reference in Naming
	    NameComponent nc = new NameComponent("HelloWorld", "");
	    NameComponent path[] = {nc};
	    ncRef.rebind(path, HelloWorldRef);

	    // wait for invocations from clients
	    java.lang.Object sync = new java.lang.Object();
	    synchronized (sync) 
	    {
		    sync.wait();
	    }
	} catch (Exception e) {
	    System.err.println("ERROR: " + e);
	    e.printStackTrace(System.out);
	}
    }
}
