/**
 * HelloImpl.java
 * 	An rmi server which implements Hello remote interface
 * @author Yoon Kyung Koo (yoonforh@moon.daewoo.co.kr)
 * @version 1.0 1999/05/09
 */

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

class HelloImpl extends UnicastRemoteObject
				implements Hello {
	/**
	 * constructor re-declaration is required
	 * at least to declare RemoteException
	 */
	HelloImpl () throws RemoteException {}

	/**
	 * implements Hello interface methods
	 * (NOTE: all interface methods are implicitly public)
	 */
	public String hello() throws RemoteException {
	        return "Hello, Remote World!";
	}

	/**
	 * register and bind this remote server on the RMI registry
	 */
	public static void main(String args[]) {
		// first create and install a security manager
		if (System.getSecurityManager() == null)
			System.setSecurityManager(new RMISecurityManager());
		try {
			HelloImpl impl = new HelloImpl();
			// bind this object instance to the name "HelloServer"
//			Naming.rebind("/HelloServer", impl);
			LocateRegistry.getRegistry().rebind("HelloServer", impl);
			System.out.println("/HelloServer successfully bound.");
		} catch (Exception e) {
			System.err.println("Error:"+e.getMessage());
			e.printStackTrace();
		}
	}
}
