EJB Interfaces


One of the most important aspects of understanding Enterprise JavaBeans is becoming familiar with a bean’s interfaces as well as its life cycle. Let’s begin with an exploration of EJB interfaces before discussing each respective bean’s life cycle.

EJB component interfaces expose business logic to clients. The session bean class must implement the javax.ejb.SessionBean interface; the entity bean class must implement the javax.ejb.EntityBean interface. Both home and remote interfaces for session and entity beans extend the same parent interfaces.

The bean developer must provide two specialized types of interfaces for accessing remote objects:

  • Home interface

  • Remote interface (sometimes referred to as the component interface)

The client utilizes the home interface to create, remove, and destroy EJB instances.

The remote interfaces expose methods that offer shopping cart services, such as allowing clients to add selected items to a purchasing list. Once the client has completed the order, the home interface methods remove the shopping cart instance from memory and destroy the EJB instance.

Remote Home Interface

Every bean type contains one home interface, as demonstrated here:

public interface javax.ejb.EJBHome extends java.rmi.Remote {
public EJBMetaData getEJBMetaData() throws RemoteException;
public HomeHandle getHomeHandle() throws RemoteException;
public void remove(Handle handle)
throws RemoteException, RemoveException;
public void remove(Object primaryKey)
throws RemoteException, RemoveException;}

In order to write EJBs, it is necessary to observe the following methods declared in the home interface:

getEJBMetaData();
getHomeHandle();
remove(Object, primaryKey);
remove(Handle handle);
getEJBMetaData();

The purpose of these methods is as follows:

  • The getEJBMetaData() method returns the Enterprise JavaBean’s ejbMetaData interface.

  • The getHomeHandle() method returns a home handle. This references a remote home object.

  • The remove(Object, primaryKey) method removes an instance of the entity bean associated with a primary key.

  • The remove(Handle handle) method removes a bean instance associated with its handle.

  • The getEJBMetaData() method necessitates using the PortableRemoteObject.narrow() method to narrow the returned EJBMetaData method. This also applies to the getHomeHandle() method.

Remote Component Interface

The remote component interface executes methods implemented in the bean class. This interface extends the javax.ejb.EJObject interface and throws a RemoteException. Observe the following code:

public interface javax.EJB.EJBObject extends java.rmi.Remote{
public EJBHome getEJBHome() throws RemoteException;
public Object getPrimaryKey() throws RemoteException;
public void Remove() throws RemoteException, RemoveException;
public Handle getHandle() throws RemoteException;
public Boolean isIdentical(EJBObject obj) throws Remote
Exception;}

Local Component Interfaces

Local component interfaces (exposing business methods) can only be called by local clients residing in the same JVM. See the following code for this interface:

public interface EJBLocalObject {
public EJBLocalHome getEJBLocalHome() throws EJBException;
public Object getPrimaryKey() throws EJBException;
public boolean isIdentical() throws EJBException;
public void remove() throws EJBException, RemoveException;
}

Note

The message-driven bean (MDB) has no remote/local home interface or remote/local interface. See “Considering Message-Driven Beans,” later in the chapter.




.NET & J2EE Interoperability
Microsoft .NET and J2EE Interoperability Toolkit (Pro-Developer)
ISBN: 0735619220
EAN: 2147483647
Year: 2004
Pages: 101
Authors: Simon Guest

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net