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 Confusion!!

 
Claire Simpson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Could someone please clarify how to know when to narrow an object. I understand that we need to narrow remote stubs but how do we tell what a remote stub is. For example, in mock exams I have seen that we need to narrow the result of
handle.getEJBObject() which return EJBObject
but just need a normal Java cast for EJBContext.getEJBObject()

How are you supposed to tell the difference??

Here's a list of what I do know.
Must narrow:
jndi lookup of EJBHome
Single entities from Finder method Collection results
getEJBObject from Handle class
getEJBHome from Home Handle

Need not narrow:
EJBContext.getEJBObject
Single Finder method results
EJBObject creation in create methods

What happens with:
EJBContext.getEJBHome
EJBObject.getEJBHome

Thanks in advance!
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question Claire!

Here is the answer:

The narrow() method only needs to be used when a remote reference to an EJB home or EJB object is returned without a specific Remote interface type. This occurs in six circumstances:

a) When an EJB home reference is obtained using the javax.naming.Context.lookup() method:

b) When an EJB object reference is obtained using the javax.ejb.Handle.getEJBObject() method:

c) When an EJB home reference is obtained using the javax.ejb.HomeHandle.getEJBHome() method:

d) When an EJB home reference is obtained using the javax.ejb.EJBMetaData.getEJBHome() method:

e) When an EJB object reference is obtained from a collection returned by a Home interface finder method:

f) When a wide EJB object type is returned from any business method.

The PortableRemoteObject.narrow()method is not required when the remote type is specified in the method signature. This is true of the create() methods and find methods that return a single bean.

Please refer to the link: [ UD: removed link to copyrighted material ]
Thanks

-- Ravi

[ March 30, 2005: Message edited by: Ravindra Janapareddy ]
[ August 03, 2007: Message edited by: Ulf Dittmer ]
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer your question

EJBContext
public EJBHome getEJBHome()
Obtain the enterprise bean's remote home interface.
Returns: The enterprise bean's remote home interface.
Narrowing not needed

HomeHandle
public EJBHome getEJBHome()
Obtain the home object represented by this handle.
Narrowing needed

EJBObject
public EJBHome getEJBHome()
Obtain the enterprise Bean's remote home interface.
Returns: A reference to the enterprise Bean's home interface.
Narrowing not needed
[ March 30, 2005: Message edited by: Ravindra Janapareddy ]
 
Claire Simpson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Superb answer. Thanks Ravi!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic