This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

narrowing results

 
Mihai Alexe
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic