aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes ProtableRemoteObject.narrow() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ProtableRemoteObject.narrow()" Watch "ProtableRemoteObject.narrow()" New topic
Author

ProtableRemoteObject.narrow()

naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
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


Thanks and Regards<br />Naresh govindaswamy
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sankar singh
Ranch Hand

Joined: Aug 17, 2007
Posts: 40
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

Joined: Sep 29, 2002
Posts: 1683
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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ProtableRemoteObject.narrow()
 
Similar Threads
Class not found error when running the trial example from Headfirst book
question on isIdentical()
HF - What goes where question
Head First EJB, AdviceBean & that damned SerialContextProvider
EJB call without stubs