Java Reference
In-Depth Information
Session Bean Interfaces and Classes
The differences that occur in the interfaces and classes required to build a session bean depend
on whether the bean is stateful or stateless. You will develop a sample session bean throughout
the next section.
The sample session bean is a stateless session bean, CalculateLoan , with a method that can be
used to calculate the monthly payment for a loan, given the necessary information.
Remote Interface
The remote interface for any session bean defines the client's access to the business logic con-
tained within the bean. These are the methods that define the usefulness of the bean.
This interface will drive the development for the bean class. Here you must design the client's
interaction with the bean. After this API is well defined it usually remains static. After it has
been integrated into client code, changing the existing prototypes will have detrimental effects
on the client. Because this is only an interface and contains no code, after it is finished it is
possible for clients to begin integrating it.
Defining the remote interface is governed by a few regulations. The interface must extend the
javax.ejb.EJBObject . Every method must follow the rules for RMI/Internet Inter-ORB
Protocol (IIOP). This means that each parameter and return type must be of valid types for
RMI/IIOP. Also, each method must include at least java.rmi.RemoteException in the throws
clause. Other than these two simple regulations all you must do is define what the public inter-
face for your session bean will contain.
The remote interface for the CalculateLoan bean is very simple. The source code for the
remote interface is in Listing 12.1.
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface CalculateLoan extends EJBObject
public Float calcMonthlyPayment(Integer months, Float principal)
throws RemoteException;
public Float getCurrentInterestRate() throws RemoteException
Let's look at the exceptions in this class. You will see that all of the methods throw
RemoteException as required by the EJB specification. As long as this exception is included in
the throws clause, any other exception can also be included in the throws clause. Once again
these exceptions are system specific and defined by the bean designer.
Search WWH ::

Custom Search