CHAPTER 3. PYTHON LANGUAGE MAPPING ISSUES 19
Case Objref Type
1. The received id is the same as the target id received
2. The received id is not the same as the target id, but
the ORB knows that the received interface is derived
from the target interface
received
3. The received id is unknown to the ORB target
4. The received id is not the same as the target id, and
the ORB knows that the received interface is not de-
rived from the target interface
target
Cases 1 and 2 are the most common. Case 2 explains why it is not necessary
to narrow the result of calling resolve_initial_references("RootPOA"): the
return is always of the known type PortableServer.POA, which is derived from
the target type of CORBA.Object.
Case 3 is also quite common. Suppose a client knows about IDL modules M1
and M3 from above, but not module M2. When it calls getA() on an instance of
M3::C, the return value may validly be of type M2::B, which it does not know.
By creating an object reference of type M1::A in this case, the client is still able
to call the object’s opA() operation. On the other hand, if getObj() returns an
object of type M2::B, the ORB will create a reference to base CORBA::Object,
since that is the target type.
Note that the ORB never rejects an object reference due to it having the
wrong type. Even if it knows that the received id is not derived from the target
interface (case 4), it might be the case that the object actually has a more derived
interface, which is derived from both the type it is claiming to be and the target
type. That is, of course, extremely unlikely.
In cases 3 and 4, the ORB confirms the type of the object by calling _is_a()
just before the first invocation on the object. If it turns out that the object is
not of the right type after all, the CORBA.INV_OBJREF exception is raised. The
alternative to this approach would be to check the types of object references
when they were received, rather than waiting until the first invocation. That
would be inefficient, however, since it is quite possible that a received object
reference will never be used. It may also cause objects to be activated earlier
than expected.
In summary, whenever your code receives an object reference, you should
bear in mind what omniORBpy’s idea of the target type is. You must not as-
sume that the ORB will always correctly figure out a more derived type than
the target. One consequence of this is that you must always narrow a plain
CORBA::Object to a more specific type before invoking on it
2
. You can assume
that the object reference you receive is of the target type, or something derived
from it, although the object it refers to may turn out to be invalid. The fact that
2
Unless you are invoking pseudo operations like _is_a() and _non_existent().