FileDocCategorySizeDatePackage
PersonClient.javaAPI DocExample1416Wed Apr 05 11:25:42 BST 2000None

PersonClient.java

/*
 * This example is from the book "Java Enterprise in a Nutshell".
 * Copyright (c) 1999 by O'Reilly & Associates.  
 * You may distribute this source code for non-commercial purposes only.
 * You may study, modify, and use this example for any purpose, as long as
 * this notice is retained.  Note that this example is provided "as is",
 * WITHOUT WARRANTY of any kind either expressed or implied.
 */

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.Properties;

public class PersonClient {
  public static void main(String[] args) {
    String name = args[0];

    try {
      // Get a JNDI context for our EJB server (EJBHome, in this case)
      Properties p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.ejbhome.naming.spi.rmi.RMIInitCtxFactory");
      // Add URL, host or port options, if needed...;
      Context context = new InitialContext(p);

      // Get the home interface for Person beans
      PersonHome pHome =
        (PersonHome)context.lookup("People");

      // Create a named person
      Person person = pHome.create(name);

      // Use the remote stub interface to access the person’s data
      // . . .
    }
    catch (NoSuchPersonException nspe) {
      System.out.println("Invalid person: " + name);
    }
    catch (Exception e) {
      System.out.println("Error while creating/using person.");
    }
  }
}