Designing the Stateful Session Bean

Like other enterprise beans, stateful session beans consist of a home interface, component interface, enterprise bean class, and deployment descriptor. The home and component interfaces can be local, or remote, or both.

Figure 6.2 shows the design of the EnrollmentCart component. The EnrollmentCart stateful session bean implements the SessionBean interface. It implements the methods setSessionContext(), ejbCreate(), ejbActivate(), ejbPassivate(), and ejbRemove() as defined in the javax.ejb.SessionBean interface. In addition, it implements the addCourses(String[] courseIds) method, which accepts an array of course IDs and adds them to the cart. The getCourses() method returns a collection of course IDs in the cart and the empty() method clears the contents in the cart.

Figure 6.2. EnrollmentCart sample class diagram.


We provide remote interfaces to our stateful session bean. They include a remote home interface (EnrollmentCartHome) and a remote interface (EnrollmentCart). The EnrollmentCartHome home interface extends the javax.ejb.EJBHome interface and defines a single create() method. The EnrollmentCart remote interface extends the javax.ejb.EJBObject interface and defines the methods addCourses(), getCourses() and empty().

Note

Both stateful and stateless session beans provide the following class files: a) session bean class; b) session bean's remote home interface and remote interface, if the session bean provides a remote client view; c) session bean's local interface and local home interface, if the session bean provides a local client view.

Your session bean may provide both local and remote client views.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.107.85