FileDocCategorySizeDatePackage
PersonBean.javaAPI DocExample2951Wed Apr 05 11:25:42 BST 2000entity.containerManaged

PersonBean.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.
 */

package entity.containerManaged;

import javax.ejb.*;
import java.rmi.RemoteException;
import NoSuchPersonException;
import java.util.Properties;

/**
 * A PersonBean, which represents a person stored in our database.
 */
public class PersonBean implements EntityBean {
  // First name of person
  public String mFirstName = "";
  // Last name
  public String mLastName = "";

  // Store context (non-persistent)
  private transient EntityContext mContext = null;

  /**
   * No need for us to activate anything in this bean, but we need to
   * provide an implementation.
   */
  public void ejbActivate() {
    System.out.println("ProfileBean activated.");
  }

  /**
   * Load bean from persistent store. Container is doing this for us, so
   * nothing to do here.
   */
  public void ejbLoad() throws RemoteException {}

  /**
   * Store bean to persistent store.  Container is doing this, so nothing
   * to do here, either.
   */
  public void ejbStore() throws RemoteException {}
  
  /**
   * Nothing to do on a remove.
   */
  public void ejbRemove() {}

  /**
   * No state to store on passivation (it's all in persistenct storage).
   */
  public void ejbPassivate() {}

  /**
   * Get context from container.
   */
  public void setEntityContext(EntityContext context) {
    mContext = context;
  }

  /**
   * Container is removing our context.
   */
  public void unsetEntityContext() throws RemoteException {
    mContext = null;
  }

  /**
   * Create method (corresponds to each create() method on the
   * home interface).  Nothing to initialize in this case.
   */
  public void ejbCreate() {
    System.out.println("Nameless PersonBean created.");
  }

  /**
   * Post-creation notification.  Nothing to do here, but we need
   * to provide an implementation.
   */
  public void ejbPostCreate() {
    System.out.println("PersonBean post-create called.");
  }
   
  /**
   * Create method with name of person.
   */
  public void ejbCreate(String fname, String lname) 
    throws NoSuchPersonException {
    mFirstName = fname;
    mLastName = lname;
  }

  /**
   * Post-creation notification.  Nothing to do here, what we need
   * to provide an implementation.
   */
  public void ejbPostCreate(String fname, String lname) {}
   
  // Finally, the remote methods.  Signatures of methods must match those
  // on remote interface (Profile), except that throwing
  // RemoteException is not necessary.

  public String getFirstName() {
    return mFirstName;
  }

  public String getLastName() {
    return mLastName;
  }
}