JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»

e Business methods we want to expose to users of this EJB.

The home interface

Looking at
listing 12.1, we see no methods that help us create or get a reference to an instance of the CatalogueEntry EJB. This inability will be a problem for us since we want to, of course, create catalogue entries and search for products. You do not see these services in the EJB’s remote interface because these are not services that the EJB itself provides, but are services provided by its home interface. An EJB’s home interface is implemented by the EJB container and, using the container, this home implementation will support creation and searching for our CatalogueEntry EJB. To make this possible, all we need to do is define a home interface as seen in listing 12.2.

Custom tags and J2EE

Listing 12.2 The home interface of the CatalogueEntry EJB

package book.ejb.catalogue;

import java.util.Collection; import java.rmi.RemoteException; import javax.ejb.EJBHome; import javax.ejb.CreateException; import javax.ejb.FinderException;

public interface CatalogueEntryHome extends EJBHome {

public CatalogueEntry create(String serial,

String type,

String name,

String description, int dollars, int cents)

throws RemoteException, CreateException;

public CatalogueEntry findByPrimaryKey(String serial) throws FinderException, RemoteException;

public Collection findByType(String type)

throws FinderException, RemoteException;

О Creates a method used to create an instance of CatalogueEntry EJB C Finds a CatalogueEntry EJB by its serial number D Finds a CatalogueEntry EJB by its

type The home interface defines a creation method as well as numerous find-xxx() methods. Using these methods, one can create EJB instances and then search for them by serial number or type. We should also note here that all the home interface’s methods throw some type of exception: (1) The creation methods throw a CreateException, which signals that the creation failed. (2) The findxxx() methods can throw a FinderException which indicates that there was some error while looking for the appropriate EJBs. (3) All methods throw a RemoteException to signal a possible communication error with the remote server. In using these exceptions one gains a good idea of its method call status.

Скачать в pdf «JSP Tag Libraries»