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)
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
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