13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

498Chapter 22Building an EJBExample 22.2 Sample remote interfacepackage com.jadol.budgetpro;import javax.ejb.*;import java.rmi.*;import net.multitool.util.*;/*** Remote Interface for the M<strong>on</strong>ey EJB*/public interfaceM<strong>on</strong>eyextends EJBObject{// the methods from the remote object which we will callpublic Costsave(double amt, double rate, double paymnt)throws java.rmi.RemoteExcepti<strong>on</strong>;public Costdebt(double amt, double rate, double paymnt)throws java.rmi.RemoteExcepti<strong>on</strong>;} // interface M<strong>on</strong>eyThe crucial thing to note with this interface is that we have defined twomethods that match the two methods in our Sessi<strong>on</strong>Bean—the save() anddebt() methods. These are the methods that will actually be called by our applicati<strong>on</strong>,and the J2EE mechanisms will do their work behind the scenes toc<strong>on</strong>nect to the methods of our Sessi<strong>on</strong>Bean implementati<strong>on</strong> and send backthe results.22.2.3 EJBHomeBetween the Sessi<strong>on</strong>Bean and its remote interface lies the home interface, alsocalled the remote home interface, since it pairs with the remote interface. Anobject that implements the home interface is the kind of object that is returnedafter the lookup() and then narrow() method calls. It is used to create a referenceto the EJB. The home interface for a stateless sessi<strong>on</strong> bean needs <strong>on</strong>lyimplement a single method, the create() method with no arguments. Thebody of the method needs do nothing. All the real work is d<strong>on</strong>e by theunderlying object supplied by J2EE.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!