Java Reference
In-Depth Information
L ISTING 12.3
Continued
public void setSessionContext(SessionContext ctx)
throws javax.ejb.EJBException, java.rmi.RemoteException {
this.ctx = ctx;
}
}
Remember that there is an ebjCreate() method to match each of the create() methods in the
home interface. The bean class fully implements each of the business methods specified in the
remote interface. Note the exact same signatures between the two methods.
All of the abstract methods defined in the base class SessionBean have been implemented,
even though most of them are empty. Every session bean is required to maintain the
SessionContext , which will be assigned to it by the container. The attribute is set through the
setSessionContext() method. This and the other callback methods, ejbActivate() ,
ejbPassivate() , and ejbRemove() , will all be discussed when we look at the container's inter-
action with the session bean and the bean's lifecycle.
The business method, calcMonthlyPayment() , includes code to perform the necessary calcula-
tions. This method is not written differently from any other Java method. The one piece of
code that is specific to an EJB is in the getCurrentInterestRate() method where you obtain
the yearly interest rate from the EJB's environment.
Deployment Descriptor
Deploying a group of EJBs gives the application server a description of each bean as well as a
set of instructions that tell it how to manage the beans. One or more EJBs are grouped into a
jar file along with an ejb-jar.xml file (the deployment descriptor), and they are deployed to
the application server to handle.
The ejb-jar.xml file can contain two types of information. The EJB's structural information
provides all of the dependency information for an EJB. This information is required, and is
usually not changed after it is solidified, because change will affect not only the structure of
the bean, but the clients that use it. The second type of information that can be present in the
ejb-jar.xml file is application assembly information. This information defines how each EJB
interacts to compose a larger application unit. The application assembly information is
optional, and by changing it you are only affecting how the bean works in the larger group.
The ejb-jar.xml file contains XML tags to describe all the necessary information. The struc-
ture of the ejb-jar.xml file is regulated by a document type definition (DTD) that can be
found at http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd . We will use only a small subset
of the XML tags that are possible in an EJB deployment descriptor.
Search WWH ::




Custom Search