Sven van 't Veer wrote:

> Dave Ford wrote:
> >
> > The reason I ask, is that I teach Java classes. My students ask me to
> > explain why we need to "cast" AND "narrow". I have not been able to give a
> > very satisfying answer.
> >
> javax.rmi.ProtableRemoteObject.narrow(Object, class) returns an Object.
> This object must then be cast. narrow just 'checks'if the object of
> remote or abstract interface *CAN* be cast to the desired class.
>

This is partially correct.  If the stub already implements the desired interface (the
narrow interface) then the PortableRemoteObject.narrow() method doesn't do anything; it
just returns the narrowFrom object so it can be cast to the desired type.

In the case of CORBA IIOP,  however, its possible to obtain a remote reference (stub) 
to
an object that doesn't implement all the server object's remote interfaces.  In this 
case
the narrow method queries the reference to see if its server object supports the 
desired
interface.  If it does, the ProtableRemoteObject will use the CORBA API to dynamically
load the proper stub and return that to the client. .  In cases where the EJB container
system uses IIOP the narrow method will transparently load the proper stub if native 
Java
casting doesn't work.

This type of explicit narrowing is plugable so vendors that use proprietary protocols 
can
provide their own narrowing facilities if needed.

Richard
--
Richard Monson-Haefel
Author of Enterprise JavaBeans, 2nd Edition
Published by O'Reilly & Associates
http://www.EjbNow.com

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to