13.1.4 Stateless Session Bean Implementation Without getting into (Linux web host)

13.1.4 Stateless Session Bean Implementation Without getting into anything too elaborate, we next want to come up with an implementation of our session fa ade. We’ll make a few decisions here to simplify things, but the result will be all we need to illustrate how to interface the web and application tiers. It will also be good enough for you to deploy in an EJB container and use to test your Struts interface. If you were given the task of implementing the application tier of the Storefront application using EJB, you probably would produce a design consisting of both session and entity beans. You could represent the model components using entity beans, and you’d likely have a number of session beans to provide the functionality for security, catalog, and order operations. The session beans would provide the workflow functionality required from process business objects, and the entity beans would serve as the corresponding entity business objects. We’ve already made the decision to use only a single session bean for the example. The session fa ade makes our next simplification easy as well. Because we’ve isolated the interface between our two tiers into a fa ade, any division of responsibilities between session and entity beans is of no concern to us as Struts developers. The web tier sees only session-bean methods and DTO classes, so nothing else about the implementation will affect the web components. Given that, we’ll implement our fa ade using a single stateless session bean that does not require any other EJBs. If you’re starting with an EJB implementation that includes entity beans, you might want to use XDoclet (available from http://www.sourceforge.net/projects/xdoclet/) to automatically generate Struts ActionForms from these beans. For more complex EJB implementations than what we’re looking at here, XDoclet also provides an automated means of generating the various interfaces and deployment descriptors required for a bean. This code generation is performed based on special JavaDoc tags that you include in your EJB implementation classes. Because we’re not using entity beans, we can make use of the same ORM approach and entity business object classes already used by the StorefrontServiceImpl class. In fact, our implementation will look very much like that class, with the exception of the callback methods required by the javax.ejb.SessionBean interface. This is shown in Example 13-3. Example 13-3. The Storefront session bean package com.oreilly.struts.storefront.service; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import org.odmg.*; import ojb.odmg.*;
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply