Completing Client-Side Files

If you created your client file with the CORBA template, ClientMain, instead of generating a client-side file with the CORBA wizard, you must add code to your file. The code you add to your client program depends on the binding method the program uses:

Coding the Naming Service resolve() Method

The CORBA lookup() method uses the NameComponent object to construct the name associated with the object reference. This name is passed to the resolve() method, which returns the CORBA object. If your client class uses Naming Service Binding, the generated code does not include the lookup() method. To code the method, you need to know how the server binds itself to the naming service. The easiest way to generate this code is with the Naming Service browser, which can read the server's IOR from the naming service and generate lookup code for you.

To code the resolve() method:

  1. Start the CORBA server program.
  2. Point the CORBA module's Naming Service browser to the naming service to which the server program bound the servant instance it created.
  3. In the Runtime tab of the Explorer, expand the naming service node to see the subnode that represents the servant instance.
  4. Right-click the node that represents the servant instance and choose Copy Client Code.
  5. Move to the source Editor (your client class should be open in the editing window.)
  6. Locate the following comment in the generated code:
  7.  // resolve names with the Naming Service
     // paste code retrieved using the Copy Client/Server Code action 
     // (on the corresponding node in the Naming Service Browser) here
    
  8. Put your insertion point underneath this line and press CTRL-V. This shortcut pastes the code that was generated by the Naming Service browser. The code looks something like this:
        String[] client_name_hierarchy = new String [] {"JDK", "Naming"};
    

Obtaining the IOR

Whichever binding method your client uses, the result is an object of type org.omg.CORBA.Object, named obj, which represents the IOR. For example, clients that read an IOR from a file contain this

In clients that use naming service binding, the IOR is obtained by the resolve() method. See the for details.

Coding the narrow() Method

To use the IOR, you need to call a narrow() method, which returns the object reference.

To code the narrow() method:

  1. In your generated client file, look for this line of code:
     /*interface_name*/ srv = /*interface_name*/Helper.narrow (obj);
    
  2. Replace the placeholder with the interface name, including the package and class that contains it. For example:
     helloworld.HelloApp.Hello srv = helloworld.HelloApp.HelloHelper.narrow (obj);
    
  3. Adding Client Code

    You can add code at the end of the client file to call server-side methods. Look for the comment:

    // add your client code here
    
    and type in your code below that line.

    Compiling Your Client

    The last step is to compile together all of the classes related to the client, including the IDL file:

    See also
    Completing Server-Side Files
    Generating CORBA Files

    Legal Notices