// HelloClient.java

package hello;

import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.io.*;
import java.util.*;
import java.rmi.RemoteException;

/*
 * A simple client for accessing an EJB.
 */

public class HelloClient
{
  public static void main(String[] args)
  {
    System.out.println("client started...");
    try {

      // Initial context properties are set in the jndi.properties file

      Context context = new InitialContext();
      
      // This for use with com.evermind.server.rmi.RMIInitialContextFactory
      //      Object homeObject = context.lookup("HelloBean");

      // This is for use with com.evermind.server.ApplicationClientInitialContextFactory
      Object homeObject = context.lookup("java:comp/env/Helloworld");

      // Narrow the reference to HelloHome.
      HelloHome home =
	(HelloHome) PortableRemoteObject.narrow(homeObject, HelloHome.class);

      // Create remote object and narrow the reference to Hello.
      Hello remote =
	(Hello) PortableRemoteObject.narrow(home.create(), Hello.class);

      System.out.println(remote.sayHello("James Earl"));

    } catch(NamingException e) {
      System.err.println("NamingException: " + e.getMessage());
    } catch(RemoteException e) {
      System.err.println("RemoteException: " + e.getMessage());
    } catch(CreateException e) {
      System.err.println("FinderException: " + e.getMessage());
    }
  }
}
