Java Reference
In-Depth Information
Notice the matching argument lists and throws clauses. As mentioned before, because this
create() method accepts an argument list, it would probably be associated with a stateful ses-
sion bean. This also explains why the body of the ejbCreate() method initializes the bean's
state. The create() / ejbCreate() combination of methods acts as a pseudoconstructor that the
client uses for the bean.
Next are the responsibilities of the bean class in relation to the remote interface. The bean class
must implement each of the business methods defined in the remote interface. This includes
following all the rules laid out for these methods, for example RMI/IIOP compliance. One
important rule is that the name of these methods cannot begin with ejb , to avoid naming con-
flicts with the callback methods that begin this way. The sample bean class still remains a
fairly simple class. You can find the source for the bean class in Listing 12.3.
L ISTING 12.3
CalculateLoanBean.java
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.rmi.RemoteException;
import javax.naming.Context;
import javax.naming.InitialContext;
public class CalculateLoanBean implements SessionBean {
protected SessionContext ctx = null;
public CalculateLoanBean() {
}
public Float calcMonthlyPayment(Integer months,
Float principal)
throws RemoteException {
Float yearlyIntTmp = getCurrentInterestRate();
// Perform all of the calculations to figure out
// the monthly payment.
float yearlyInt = yearlyIntTmp.floatValue() / 100;
float monthlyInt = yearlyInt / 12;
double payment = (principal.floatValue() * monthlyInt) /
(1 - (Math.pow(1 / (1 + monthlyInt),
months.intValue())));
return new Float((float)payment);
}
Search WWH ::




Custom Search