OOPortal   Tweet
J2EEOnline RationalDB



Warning: include(../../160By600m.php): failed to open stream: No such file or directory in /home/ooport7/public_html/corba-java-programming/nav.php on line 10

Warning: include(../../160By600m.php): failed to open stream: No such file or directory in /home/ooport7/public_html/corba-java-programming/nav.php on line 10

Warning: include(): Failed opening '../../160By600m.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ooport7/public_html/corba-java-programming/nav.php on line 10
Lesson 11 Helper classes
Objective Use helper classes to narrow object references.
In the previous lessons, you learned that clients "narrow" generic object references from lookups to object references of a desired specific interface type. You also learned about stub classes. We will now discuss helper classes, which are the classes that provide the narrowing functionality, which is what produces stub objects for clients.
Helpers
For every IDL interface X, an XHelper class is generated. This class has a host of utility methods associated with the given interface. Some of these methods offer functionality related to CORBA, which is covered later in the course. The most important helper method, however, is the narrow() method. This is needed to take the generic org.omg.CORBA.Object references typically returned by object lookup methods and turn them into a reference of the appropriate specific interface type, as shown in the client code example earlier in this module. This is somewhat akin to the more familiar mechanism of reference casting.

Weather Service example
To understand better how helpers perform narrowing, let us look at the narrow() method in the WeatherServiceHelper class generated by the standard Weather Service example:
package weather;
public class WeatherServiceHelper
 implements org.omg.CORBA.portable.Helper
{
 public WeatherServiceHelper()
 {
 }

 // Many other methods

 public static weather.WeatherService narrow
  (org.omg.CORBA.Objectobj)
 {
  try
  {
   return (weather.WeatherService)obj;
  }
  catch( ClassCastException c )
  {
   if( obj._is_a("IDL:weather/WeatherService:1.0"))
   {
    weather._WeatherServiceStub stub;
    if( ((org.omg.CORBA.portable.ObjectImpl)obj)
 ._is_local())
    {
     stub = new weather._WeatherServiceLocalStub();
    }
    else
    stub = new weather._WeatherServiceStub();
    stub._set_delegate(((org.omg.CORBA.portable.
 ObjectImpl)obj)._get_delegate());
    return stub;
   }
  }
  return null;
 }
}
Notice in the code for the narrow() method that a stub is instantiated in the helper. This is why you have to narrow generic references--the helper produces the stub object in the client that will connect through the ORB to the remote implementation object.
The next lesson concludes this module.
Helper Classes - Exercise
Click on the Exercise link below to try your hand at writing basic client code, including reference narrowing.
Helper Classes - Exercise