First page Back Continue Last page Graphics
Continuation of Notes
Notes:
LegacyAppSessionBean Example
We will use our LegacyAppSessionBean class again to illustrate the setSessionContext( ) method of the SessionBean interface. It simply stores the SessionContext object in an instance variable.
import ...; // Import all necessary packages...
public class LegacyAppSessionBean implements SessionBean {
private SessionContext _ctxt;
// Other instance vars...
public void setSessionContext(SessionContext ctxt) {
_ctxt = ctxt;
}
// Rest of class...
}
ShoppingCartBean Example
In this example, ShoppingCartBean uses setSessionContext( ) to acquire references to BookHome and CustomerHome.
public class ShoppingCartBean implements SessionBean {
private SessionContext _sctxt; // For session context
private BookHome _bookhome;
private CustomerHome _custhome;
public void setSessionContext(SessionContext sctxt) {
_sctxt = sctxt;
// Look up related homes:
Context ctxt = ...; // Get initial JNDI context
_bookhome = ctxt.lookup(...); // Look up book home
_customerhome = ctxt.lookup(...); // Look up customer home
}
// Rest of class...
}