Each EJB provides some interfaces that its clients use to work with the EJB.
Remote Interface
The remote interface is the business end of the EJB.
This is the set of actual services provides by the EJB. (or)
A remote interface defines the business methods that a client may call.
The business methods are implemented in the enterprise bean code.
Example : C:\myejb\myRemote.java
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface myRemote extends EJBObject
{
//Business Methods called by Client
public double find_income(double salary, double part_time_jobs, double tips)
throws RemoteException;
public double find_savings(double income, double expense)
throws RemoteException;
}
Home Interface
The home interface is the book-keeping interface.
It helps clients create a new instance of an EJB, or to find an existing
instance of an EJB.
The methods used to find existing EJBs are known as "finder" methods.
Since session beans are not designed to be shareable,
there are no session bean finder methods. (or)
A home interface defines
the methods that allow a client to create,
find, or remove an enterprise bean .
The Home interface contains
a single create() method, which returns an object of the remote interface type
Example : C:\myejb\myHome.java
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface myHome extends EJBHome
{
myRemote create() throws RemoteException, CreateException;
}
Implementation
The home interface doesn't actually need an implementation!
This is because its tasks are straightforward enough that the EJB container
can automatically provide the implementation.
The remote interface, however, needs an implementation
which is supplied by the EJB programmer.
Example : C:\myejb\myEJB.java
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class myEJB implements SessionBean
{
public double find_income(double salary, double part_time_jobs, double tips)
{
return ( salary+part_time_jobs+tips ) ;
}
public double find_savings(double income, double expense)
{
return (income-expense);
}
public myEJB() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
|