File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Home and componen interface for multiple bean classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Home and componen interface for multiple bean classes" Watch "Home and componen interface for multiple bean classes" New topic
Author

Home and componen interface for multiple bean classes

Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
Home and component interfaces specify the services provided by a bean. I wonder whether polymorphism can be applied to enterprise bean. Instead of writing only one bean class for a given home and component interfaces, I write two bean classes(CardBean1 and CardBean2), each of which provides different functionalities. In one <session> in the deploymen descriptor, I fill <ejb-class> with CardBean1, and in another <session> I fill <ejb-class> with CardBean2.

The clien accesses the bean services via component interface. Since both beans have the same component interface, the client (a developer) does not know which bean provides the services.
Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
I wonder whether it is legal to do this. If it is, do both beans have the same home interface (It is impossible! )?
Keerthi P
Ranch Hand

Joined: Aug 19, 2003
Posts: 203
In this case, you will have to provide two JNDI names when deploying the beans - ejb/Card1 and ejb/Card2 - because you have two session tags in the DD.

Clients looking up ejb/Card1 will be able to consume the services of CardBean1 and those looking up ejb/Card2 will be able to consume the services of CardBean2. So the clients do know which bean they are talking to.


Cheers.<br />Keerthi<br />(SCJP, SCWCD, SCBCD)
Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
It is quite true if the client looks up home interface from the initial context. But what if the client does not lookup home from the initial context and obtain component interface from the home interface. The interface is passed to the client as an argument. Since both beans have the same interface, the client won't know which one is which. After the client invokes getEJBHome() method from this component interface, the Home interface is returned. The Home interface is the same for both bean!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Home and componen interface for multiple bean classes