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 Bean class question 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 "Bean class question" Watch "Bean class question" New topic
Author

Bean class question

Ami Ambre
Ranch Hand

Joined: Dec 26, 2007
Posts: 58
why don't bean class implement component interface if it has to implement
the same methods? Java class allowed to implement more then one
interface?
class AdviceBean implements Advice,SessionBean
Advice is my component interface .
I don't understand answer from HF.
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
Not sure if I understood what you meant, but let me give you some explanations.

First of all, are you talking about EJB 3 or EBJ 2.1? If you're talking about EJB 3, the SessionBean interface is no longer required

About the SessionBean implement more than one interface, it isn't a problem, however, only one interface is gonna be the Business Interface.

Another important detail is about the implementation. Even without the "implements" keyword, a session bean can implement a business interface. But in this case, it must be mapped into ejb-jar.xml using the <business-interface> tag. For instance:

Interface


Session Bean


Look at the code above, it doesn't implement (directly) the interface, however it has the same method. In this case, we must set the business interface directly into the ejb-jar.xml. Like this



Did I answer your question? Hopefully the thing are clear for you now


Regards, Jair Rillo Junior
http://www.jairrillo.com/blog, SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, IBM SOA Associate (Test 664).
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Originally posted by Jair Rillo Junior:
Look at the code above, it doesn't implement (directly) the interface, however it has the same method. In this case, we must set the business interface directly into the ejb-jar.xml.


It can also be done by annotating your class with the @Remote or @Local annotations. Like this:



Also, the ejb-jar.xml element you need to use is business-remote or business-local, not business-interface.


[ September 18, 2008: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Vijay Ramalingam
Greenhorn

Joined: Jun 02, 2006
Posts: 18
"why don't bean class implement component interface if it has to implement
the same methods? Java class allowed to implement more then one
interface?"

In EJB 2.1 if the bean class directly implements the component interface, it allows the developer to write a code in the bean class, such that the refrence "this" could be accidently passed to another EJB. Since all EJB business method should be invoked via the EJBObject that the container provides/generates, this contract is advised by the EJB spec.
However not implementing the component interface by the bean prevents us to do compile time checks.
Example

public class ComponentInterfaceA extends Remote{
public void getA();
}

public class BeanImplA implements SessionBean, ComponentInterfaceA {

public void getA(){
//get another ejb reference say ComponentInterfaceB

ComponentInterfaceB.getB(this)// this is not allowed and should not be done

}

}

Hope i understood your question and answered.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean class question
 
Similar Threads
Implementing Remote Interface by Bean
Business Interface Pattern
mock question
bean class doubt
bean class doubt