moonriver
07-05-2005, 03:33 AM
I just retrieve some sample codes from SUN's J2EE 1.4 Tutorial:
Source codes of Remote Interface:
==============================================================
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;
public interface Converter extends EJBObject {
public BigDecimal dollarToYen(BigDecimal dollars)
throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen)
throws RemoteException;
}
=======================================================
Source codes of Enterprise Bean:
===============================================================
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;
public class ConverterBean implements SessionBean {
**BigDecimal yenRate = new BigDecimal("121.6000");
**BigDecimal euroRate = new BigDecimal("0.0077");
**public BigDecimal dollarToYen(BigDecimal dollars) {
****BigDecimal result = dollars.multiply(yenRate);
****return result.setScale(2,BigDecimal.ROUND_UP);
**}
public BigDecimal yenToEuro(BigDecimal yen) {
BigDecimal result = yen.multiply(euroRate);
return result.setScale(2,BigDecimal.ROUND_UP);
}
public ConverterBean() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
===============================================================
It is well known that business methods declared in a remote interface are implemented in an Enterprise Bean. However, in term of interface's definition, a class must implement an interface before implementing the interface's methods. What I am confused is why the class convertBean implements SessionBean instead of the remote interface Convertor. What is the relationship between the SessionBean and the Convertor interfaces? or the SessionBean and the EJBObject interfaces? Could you give me a draft for the relationship between those relevant interfaces of EJB?
Source codes of Remote Interface:
==============================================================
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;
public interface Converter extends EJBObject {
public BigDecimal dollarToYen(BigDecimal dollars)
throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen)
throws RemoteException;
}
=======================================================
Source codes of Enterprise Bean:
===============================================================
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;
public class ConverterBean implements SessionBean {
**BigDecimal yenRate = new BigDecimal("121.6000");
**BigDecimal euroRate = new BigDecimal("0.0077");
**public BigDecimal dollarToYen(BigDecimal dollars) {
****BigDecimal result = dollars.multiply(yenRate);
****return result.setScale(2,BigDecimal.ROUND_UP);
**}
public BigDecimal yenToEuro(BigDecimal yen) {
BigDecimal result = yen.multiply(euroRate);
return result.setScale(2,BigDecimal.ROUND_UP);
}
public ConverterBean() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
===============================================================
It is well known that business methods declared in a remote interface are implemented in an Enterprise Bean. However, in term of interface's definition, a class must implement an interface before implementing the interface's methods. What I am confused is why the class convertBean implements SessionBean instead of the remote interface Convertor. What is the relationship between the SessionBean and the Convertor interfaces? or the SessionBean and the EJBObject interfaces? Could you give me a draft for the relationship between those relevant interfaces of EJB?