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

Question for Kathy about PortableRemoteObject.narrow()

 
Sunil Patil
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathy,
Thanks for writing such a nice book on EJB's Head First EJB.
In the Client View chapter(page 121) you are saying that "The javax.rmi.PortableRemoteObject.narrow() method runs code written by the server vendor".But as PortableRemoteObject is part of JSE1.4 so i am not sure about how can it can run any code written by vendor.
In the JSDK help what it says for PortableRemoteObject.narrow() is "Checks to ensure that an object of a remote or abstract interface type can be cast to a desired type."
So if the home stub returned from the JNDI lookup is not implementing the home interface it will throw ClassCastException
Thank You
Sunil
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,
good question Sunil
The PortableRemoteObject.narrow() method doesn't do the actual narrowing... it simply calls on a vendor-provided class that implements javax.rmi.CORBA.PortableRemoteObjectDelegate (I think that's what the interface is...) and THAT class is implemented by the vendor, and is responsible for *somehow* taking care of the behavior defined in the API for narrow().
So, if what comes back from lookup() does NOT implement the component interface, then the vendor's code in narrow() has to create or return something which DOES (i.e. a stub to the component interface).
If you are using the R.I., it has it's own 'delegate' class that implements the narrow() method, and which is used when you call javax.rmi.PortableRemoteObject's narrow() method.
The good news is that this is all completely vendor-specific, so we don't (and usually *can't*) know anything else about it, other than what it is supposed to do, and how and when WE are supposed to use narrowing (i.e. only for remote stubs, and only when they are coming back from a method with a return type that is something OTHER than the actual interface the stub is supposed to implement... (which means the home lookup or the stub you get back from a handle, but NOT the return value of create() or find() or other entity home business methods which declare the component interface as the return type).
cheers,
Kathy
 
Karin Paola Illuminate
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To everyone...

What happens if I use a narrow method narrow (o, AdviceHome.class) and o does not refer to a stub that implements the AdiveHome interface?

Have anyone tried this out?

Thanks in advance.
 
Sankar Subbiramaniam
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get java.land.ClassCastException
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic