Babel implements SIDL interfaces as Java interfaces in Java. This is a close mapping in general, but it does have the problem that Java interfaces can't hold data. Since we need the correct IOR pointer in order to place that interface in an array or throw it as an Exception, the lack of data becomes a problem. For this reason, we have created Wrapper classes for interfaces and abstract classes.
All interfaces and abstract classes have static inner class named Wrapper. This Wrapper class holds the interface IOR pointer, and also inherits from gov.llnl.babel.BaseClass and implements the outer interface. Therefore, you can call all the interface methods on the wrapper object, as well as gov.llnl.babel.BaseClass methods such as _cast2, and isType.
This wrapper class is what is returned when an interface is gotten out of an array, a method takes or returns an interface, or when an exception implemented as an interface is caught. (There's actually a difference here. While what is gotten out of the Array or returned from a method is a Wrapper object, the programmer doesn't usually need to worry about that, as is shown in the example below. In the case of exceptions, you actually do have to catch the Wrapper. Exceptions are covered in more detail in Subsection 10.9) Because wrapper classes inherit only from an interface, they can be java casted to their enclosing interface, or it's super-interfaces, but must be Babel casted to any classes. In this example, Subclass implements Super-Interface:
SuperInterface.Array1 arry = new SuperInterface.Array1(5, true); SubClass obj = new SubClass(); arry.set(0, (SuperInterface)obj); obj = null; SuperInterface temp = arry.get(0); obj = (SubClass) temp; //INCORRECT Will throw ClassCastException obj = (SubClass) SubClass._cast((SuperInterface.Wrapper)temp); //CORRECT
Sometimes you can get away with not Java casting the interface to the Wrapper class before Babel casting it, but not in general. (Usually you don't have to when the interface was gotten out of an array)
Here's an example of casting an interface on the server side:
public objarg.SubClass toClass_Impl (/*in*/ objarg.Iface ifcy ) { // DO-NOT-DELETE splicer.begin(objarg.SubClass.toClass) objarg.SubClass ret = (objarg.SubClass) ((objarg.Iface.Wrapper)ifcy)._cast2("objarg.SubClass"); return ret; // DO-NOT-DELETE splicer.end(objarg.SubClass.toClass) }