Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Question for Kathy about PortableRemoteObject.narrow()

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
Cowgirl and Author
Posts: 1589
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
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.
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic