Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ProtableRemoteObject.narrow()

 
naresh govindaswmay
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
sankar singh
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic