FileDocCategorySizeDatePackage
PersonBean.javaAPI DocExample6933Thu Dec 15 21:03:32 GMT 2005com.oreilly.jent.ejb.containerManaged

PersonBean

public abstract class PersonBean extends Object implements javax.ejb.EntityBean
In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Java Enterprise in a Nutshell, Third Edition, by Jim Farley and William Crawford with Prakash Malani, John G. Norman, and Justin Gehtland. Copyright 2006 O'Reilly Media, Inc., 0-596-10142-2." If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com.

Fields Summary
public javax.ejb.EntityContext
mContext
Constructors Summary
public PersonBean()


  // Public empty constructor, to be used by the EJB container.
    
Methods Summary
public voidejbActivate()

    System.out.println("ProfileBean activated.");
  
public java.lang.StringejbCreate()

    System.out.println("Nameless PersonBean created.");
    setName(" ");
    setFirstName(" ");
    setLastName(" ");
    return null;
  
public java.lang.StringejbCreate(java.lang.String name, java.lang.String fname, java.lang.String lname)

    setName(name);
    setFirstName(fname);
    setLastName(lname);
    return null;
  
public voidejbLoad()

public voidejbPassivate()

public voidejbPostCreate()

    System.out.println("PersonBean post-create called.");
  
public voidejbPostCreate(java.lang.String name, java.lang.String fname, java.lang.String lname)

public voidejbRemove()

public voidejbStore()

public java.lang.StringgetFirstName()

 return getFirstNameLocal(); 
public abstract java.lang.StringgetFirstNameLocal()

public java.lang.StringgetLastName()

 return getLastNameLocal(); 
public abstract java.lang.StringgetLastNameLocal()

public abstract java.lang.StringgetName()

public com.oreilly.jent.ejb.ProfilegetProfile()

    Profile myProfile = null;
    try {
      // Get profile home interface
      Context ctx = new InitialContext();
      ProfileHome pHome = (ProfileHome)ctx.lookup("ejb/CMP20-ProfileHome");
      // Do a find based on our name (first name concatenated with last name)
      try {
        myProfile = pHome.findByPrimaryKey(getFirstName() + " " + getLastName());
      }
      catch (FinderException fe) {
        System.out.println("Error occurred looking up profile for " +
                           getFirstName() + " " + getLastName());
	    // Try creating a new profile
        myProfile = pHome.create(getFirstName() + " " + getLastName());
      }
    }
    catch (NamingException ne) {
      System.out.println("Error occurred looking up profile home.");
      throw new RemoteException("Error looking up profile home", ne);
    }
    catch (CreateException ce) {
      System.out.println("Could neither find nor create a profile for "
			 + getFirstName() + getLastName());
      throw new RemoteException("Error accessing profile", ce);
    }
    catch (NoSuchPersonException nspe) {
      System.out.println("Could neither find nor create a profile for "
			 + getFirstName() + getLastName());
      throw new RemoteException("Error accessing profile", nspe);
    }
      
    return myProfile;
  
public abstract ProfileLocalgetProfileLocal()

public voidsetEntityContext(javax.ejb.EntityContext context)

    mContext = context;
  
public voidsetFirstName(java.lang.String fname)

 setFirstNameLocal(fname); 
public abstract voidsetFirstNameLocal(java.lang.String fname)

public voidsetLastName(java.lang.String lname)

 setLastNameLocal(lname); 
public abstract voidsetLastNameLocal(java.lang.String lname)

public abstract voidsetName(java.lang.String name)

public abstract voidsetProfileLocal(ProfileLocal profile)

public voidunsetEntityContext()

    mContext = null;