First page Back Continue Last page Graphics

Continuation of Notes...


Notes:

Base Classes for Beans
Simple base classes can help simplify your bean code. Use these two classes -- one for session beans, one for entity beans -- as follows:
1. Write your class to extend the appropriate ancestor class.
2. Override or extend the desired methods only.
Note that the two base classes are marked abstract even though they do not have any abstract methods. This technique makes obvious that they have no utility by themselves, only as superclasses.
SessionBase
import javax.ejb.*;
public abstract class SessionBeanBase implements SessionBean {

protected SessionContext _ctxt;

public void ejbActivate() { } // Empty
public void ejbPassivate() { } // Empty
public void ejbRemove() { } // Empty
public void setSessionContext(SessionContext ctxt) {
_ctxt = ctxt;
}
}
EntityBase
import javax.ejb.*;
public abstract class EntityBeanBase implements EntityBean {

protected EntityContext _ctxt;

public void ejbActivate() { } // Empty
public void ejbPassivate() { } // Empty
public void ejbLoad() { } // Empty
public void ejbStore() { } // Empty
public void ejbRemove() { } // Empty
public void setEntityContext(EntityContext ctxt) {
_ctxt = ctxt;
}
public void unsetEntityContext() {
_ctxt = null;
}
}
See the usage examples on the next pages...