When we execute a lookup to get the home interface of our bean, we normally use the lookup() method of the javax.naming.InitialContext interface.This method will return us an Object that needs to be casted to the home interface we've asked for. Unfortunately, this cannot be done using the normal/explicit casting [MyHome myHome = (MyHome)returnedObject].
As we have already found out, the reason is connected to CORBA. Why?
For EJB, the communication between the server and the client is based on RMI (both remote and local interfaces, in fact, do implements the java.rmi.Remote interface).
The underlying protocol that it is used for the communication is IIOP , that is part of CORBA standards. It is normally used to describe this communication system using the Java RMI over IIOP. IIOP has not been designed for Java, but for generic languages, and this means that there are some limitations. Some languages, in fact, do not have the concept of casting.
As we have already found out, the reason is connected to CORBA. Why?
For EJB, the communication between the server and the client is based on RMI (both remote and local interfaces, in fact, do implements the java.rmi.Remote interface).
The underlying protocol that it is used for the communication is IIOP , that is part of CORBA standards. It is normally used to describe this communication system using the Java RMI over IIOP. IIOP has not been designed for Java, but for generic languages, and this means that there are some limitations. Some languages, in fact, do not have the concept of casting.
Java RMI-IIOP provides a mechanism to narrow the the Object we have received from from our lookup, to the appropriate type. This is done through the javax.rmi.PortableRemoteObject class and, more specifically, using the narrow() method.
Just a note: when we are using the new EJB 2.0 Local Client API, you should be able to do a direct/explicit cast from the looked up Object, to the interface you need.