• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

ProtableRemoteObject.narrow()

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
//AdviceHome home=(AdviceHome) PortableRemoteObject.narrow(object, AdviceHome.class);
AdviceHome home=(AdviceHome)object;

I have a doubt in his two lines.i am getting the Home object from these two lines.i want to know the meaning of these line.Please help me out of this.


Regards
naresh
 
author & internet detective
Posts: 41774
887
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naresh,
Per the JavaDoc:

hecks to ensure that an object of a remote or abstract interface type can be cast to a desired type.


They keyword here is "remote." A simple cast won't work for a remote object. if you had a local interface, this step wouldn't be necessary.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 1. AdviceHome home=(AdviceHome)object;

Line 2. //AdviceHome home=(AdviceHome) PortableRemoteObject.narrow(object, AdviceHome.class);

Line 1: When we do Casting, the return type would not give New Object meaning the reference pointing will change, but the actual Object would not be changed.

//Before casting (AdviceHome)object -- this (a) object value
AdviceHome home=(AdviceHome)object;
//After casting (AdviceHome)object -- this (b) object value

(a) and (b) are same..

Where the object value does not change. Only home reference gets change. Meaning (AdviceHome)object will not affect object.


Line 2: When we do Narrow, please note it here.. We are not doing casting, instead we are doing narrowing. Narrowing will give a new Object meaning the Not the reference, it�s giving new Objects. And why we do this? Context.lookup returns an object which might have implemented HomeInterface or Might have not implemented. Hence we are doing Narrowing and its purely vendor specific.

//Before narrow object value is (1)
(AdviceHome) PortableRemoteObject.narrow(object, AdviceHome.class);
//After narrow object value is (2)

Where object (1) and (2) are different.


Any one Can correct me if I am wrong.

Regards,
Sankar. S
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The EJB specification requires the EJB container to enable CORBA clients, even if not written in Java, to make EJB calls. The protocol used is RMI-IIOP which makes RMI-IIOP CORBA compatible.

When the client makes a JNDI lookup for the home stub, the object returned will not implement your remote home interface if it is a CORBA client. Therefore, the narrow method is supplied by the EJB server provider to convert the object so that it implements your remote interface.

If the container is not using RMI-IIOP as the underlying communication transport, then the narrow would not be needed. However, it costs little to do the narrow, so it should always be done in your example.
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic