• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB p.230: Why are NOT all methods compiler-checked?

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

please view the "Sharpen pencil" exercis below. Why aren't all methods compiler-checked . Isn't it that all three kinds we have to provide and compile prior to deployment.



Regards,
Darya
 
Pranav Shukla
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofcourse we have to provide all three kinds of methods, then compile and deploy. But the compiler only cares for the methods from SessionBean interface(session beans directly or indirectly implement javax.ejb.SessionBean interface). But the bean class which doesn't implement the other two kinds of methods will fail to deploy because those methods will be checked for by the container only at deployment time.

So we can provide the implementation of methods from SessionBean in a bean class and compile the bean successfully, but it is useless unless we provide implementation of the Home interface methods and Component interface methods because it can't be deployed without them.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Pranav but I don't understand your answer .

Regards,
Darya
 
Narayan R
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see any session bean class code, it says
public class abcxyz implements SessionBean {
.................. }

So as per Java rule the compiler will see if this class have implemented all methods from SessionBean inteface( I.e SetSessionContext,ejbPassivate,ejbActivate,ejbRemove) Only . It won't care (atleast for compling) about interface methods or component inteface methods.

Those things will be neede only when the class is been deployed in the container..

Think about this// how's the compiler supposed to know that this class should have getAdvice(), Do_not_getadvice(), give_only_goodAdvice()...etc method ?? if we have not implemented the Home/component inteface in the bean class..

FYI .. and we never ever say that the class implements home/component interface .. its all supposed to be understood by Container by looking at ejb-jar.xml file.

Hope this help..
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • AdviceHome is a (Home) interface that extends the EJBHome interface. create() is not part of the EJBHome interface - and you are just extending it not implementing it so the Java compiler cannot help here. The fact that you need to provide a create() method in the Home interface and that there should be a ejbCreate() method on the session bean is "Bean Law" (not "Java Law") and as such can only be enforced at deployment time.
  • Advice is a (Component) interface that extends the EJBObject interface. getAdvice() is not part of the EJBObject interface - and you are just extending it not implementing it so the Java compiler cannot help here. The fact that you should to provide a business method with a signature and return type equivalent to the on Session Bean is "Bean Law" (not "Java Law") and as such can only be enforced at deployment time.
  • AdviceBean is a class implementing the SessionBean interface. By "Java Law" you have to provide an implementation for all the methods of the interface in a concrete (non-abstract) class - so you implementing setSessionContext(), ejbActivate(), ejbPassivate(), and ejbRemoved will be checked by the compiler. On the other hand your ejbCreate() and getAdvice() methods can only be verified later at deployment time as their presence is required by "Bean Law".

  •  
    Darya Akbari
    Ranch Hand
    Posts: 1855
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks a lot for the explanations. Of course you are right .

    Regards,
    Darya
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic