aspose file tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes narrowing results Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Reply Bookmark "narrowing results" Watch "narrowing results" New topic
Author

narrowing results

Mihai Alexe
Greenhorn

Joined: Apr 13, 2005
Posts: 19
Hi all!

One question: while browsing the EJB 2 API specification, I noticed that there are several methods that have the declared return type as either EJBHome or EJBObject. A couple of examples:



from HomeHandle



from SessionContext.

My question is: do I have to narrow the result of any of these methods or a simple Java cast to my Component or Home interface will suffice?

Thanks!

[ September 04, 2005: Message edited by: Mihai Alexe ]
[ September 04, 2005: Message edited by: Mihai Alexe ]

SCJP for Java 1.4<br />SCBCD for J2EE 1.3
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Let's be clear about what does and does not need to be narrowed.

The only things that must be narrowed are remote stubs. Nothing else retrieved from an RMI-IIOP call must be narrowed. To be specific, the only stubs that need to be narrowed are those for which the declared return type does not match the interface to which you are casting it. So:

* The home stub needs to be narrowed, because it is coming from a method with a return type of Object. This means all JNDI lookups of the remote home interface (your initial lookup of the bean's home).

* All calls to getHandle() or getHomeHandle() (because they always return a remote stub).

But you should not narrow:

* Lookups of a local home interface.
* All calls to create() or find(), regardless of whether it is remote or local. The EJBObject stub that you get from create() or find() methods do not need to be narrowed because the return types already specify the exact interface type to which you would be casting.

* All other remote calls unless the remote business method is returning a remote stub, and only if the return type of the method is not the same as the interface type to which you intend to cast it.

Narrowing has been described as a form of exotic casting for stubs. If you need to cast the stub, then you probably need to narrow it as well. But if it is not a stub, then you never need to narrow it, regardless of whether it needs to be cast, and regardless of whether it is coming from a remote call.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: narrowing results
 
Similar Threads
gc question
a mock question
I can't get seem to get this quicksort algorithm to work...
mock question
DI with @Resource adnotation understanding