FileDocCategorySizeDatePackage
ProfileBean.javaAPI DocExample5215Wed Apr 05 11:25:42 BST 2000entity.containerManaged

ProfileBean

public class ProfileBean extends Object implements EntityBean
A ProfileBean, which provides enterprise profile information for a named person.

Fields Summary
public String
mName
private transient Properties
mEntries
public byte[]
mEntriesBytes
private transient EntityContext
mContext
private transient boolean
mDirtyBit
Constructors Summary
Methods Summary
public voidejbActivate()
No need for us to activate anything in this bean, but we need to provide an implementation.

  
  // Entity bean methods

                      
     
    System.out.println("ProfileBean activated.");
  
public voidejbCreate(java.lang.String name)
Create method with name of profile owner.

    mName = name;
    System.out.println("ProfileBean created for " + mName + ".");
  
public voidejbCreate()
Create method (corresponds to each create() method on the home interface, ProfileHome). Nothing to initialize in this case.

    System.out.println("Nameless ProfileBean created.");
  
public voidejbLoad()
Load bean from persistent store. Since the profile entries are stored in a non-primitive object (Properties), they are stored in the database as a raw byte array. In this load method, we convert the serialized bytes loaded by the container into the Properties object.

    try {
      ByteArrayInputStream byteIn = new ByteArrayInputStream(mEntriesBytes);
      ObjectInputStream objIn = new ObjectInputStream(byteIn);
      mEntries = (Properties)objIn.readObject();
    }
    catch (Exception e) {
      System.out.println("Failed to load ProfileBean: ");
      e.printStackTrace();
      throw new RemoteException("ejbLoad failed: ", e);
    }
    System.out.println("ProfileBean load finished.");
  
public voidejbPassivate()
No state to store on passivation.

    System.out.println("ProfileBean passivated.");
  
public voidejbPostCreate(java.lang.String name)
Post-creation notification. Nothing to do here, what we need to provide an implementation.

    System.out.println("ProfileBean post-create called.");
  
public voidejbPostCreate()
Post-creation notification. Nothing to do here, but we need to provide an implementation.

    System.out.println("ProfileBean post-create called.");
  
public voidejbRemove()
Nothing to do on a remove.

    System.out.println("ProfileBean removed.");
  
public voidejbStore()
Store bean to persistent store. We store our Properties object in the database as a serialized byte array. Here, we serialize the Properties object so that the container can store it.

    try {
      ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
      ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
      objOut.writeObject(mEntries);
      mEntriesBytes = byteOut.toByteArray();
    }
    catch (Exception e) {
      System.out.println("Failed to store ProfileBean: ");
      e.printStackTrace();
      throw new RemoteException("ejbStore failed: ", e);
    }
    System.out.println("ProfileBean store finished.");
  
public java.lang.StringgetEntry(java.lang.String key)

    return mEntries.getProperty(key);
  
public java.lang.StringgetName()

    return mName;
  
public booleanisDirty()

    return mDirtyBit;
  
public voidsetEntityContext(EntityContext context)
Get context from container.

    System.out.println("ProfileBean context set.");
    mContext = context;
  
public voidsetEntry(java.lang.String key, java.lang.String value)

    mEntries.put(key, value);
    mDirtyBit = true;
  
public voidsetName(java.lang.String name)

    mName = name;
    mDirtyBit = true;
  
public voidunsetEntityContext()
Container is removing our context.

    System.out.println("ProfileBean context unset.");
    mContext = null;