Completing Server-Side Files

If you created a server file with the CORBA template instead of generating one through the CORBA wizard, you must do some coding to complete the implementation class and the server class. The code you must add to your server class depends on the binding method it uses:

Completing the Implementation Class

If you generated your implementation class with the CORBA template, ServerMain, you must add method bodies to the implementation class' business methods (the methods declared in the IDL). Note that implementation classes can also have private methods (not declared in the IDL) that are called by the business methods.

To add code that instantiates the implementation class and connects it to the ORB:

  1. Look for the following comment and code line near the top of your generated server class:
             // add your creating of object implementation here
     /*servant_class*/ /*servant_variable*/ = new /*servant_class*/();
     orb.connect(/*servant_variable*/);
    
  2. Below the comment, replace the placeholder code with a line of code like the following example, which instantiates an implementation class to create a servant instance and below that a name you used for the servant instance, for example:
     helloworld.HelloApp.HelloImpl servant = new helloworld.HelloApp.HelloImpl();
     orb.connect(servant);
    

To add code that writes the IOR to standard output:

  1. Look for the following line in your generated server class:
     System.out.println(orb.object_to_string (/*servant_variable*/));
    
  2. Replace the commented parameter with your servant instance, as in the following example:
     System.out.println(orb.object_to_string (servant));
    

To add code that writes the IOR to a file:

  1. Look for the following lines in your generated server class:
     String ior = orb.object_to_string (/*servant_variable*/);
     FileWriter file = new java.io.FileWriter("");
     ...
    
  2. Replace the commented parameters with your servant instance and the name of the file to which you want to write the IOR, as in the following example:
     String ior = orb.object_to_string (servant);
     FileWriter file = new java.io.FileWriter("HelloIOR");
          ...
    

To add code that specifies the binding name:

  1. Start the naming service with which you plan to register your server.
  2. In the IDE, go to the Explorer's Runtime tab.
  3. Start the CORBA module's Naming Service browser, specifying the naming service. You can register your server in an existing naming context or create a new context for it.

    To create a new naming context:

    1. Right-click the node for the JDK Naming Service and choose Create New Context. This opens a dialog box.
    2. In the Name and Kind fields, type names that describe the context you are creating, and click OK.

      Another new subnode appears underneath the one for the JDK naming service. You have just created a naming context in which you will register your servant instance.

      The names you use in this step are arbitrary--they are chosen to be descriptive.

  4. Right-click the node that represents the naming context in which you are registering the server, and choose Copy Server Binding Code.
  5. Switch back to the editing window, and look for the following comment in your generated server class:
     // paste code retrieved using the Copy Client/Server Code action 
     // (on the corresponding node in the Naming Service Browser) here
    
  6. Click to place the insertion point under this line, and press Ctrl-V.

    The code you pasted registers an object with the naming service and naming context you selected with the Naming Service browser.

  7. Complete the pasted code by supplying the name that will be used for your servant instance, as follows:
    1. Look for the <name of server> variable. Replace it with the server name, for example, Hello.
    2. Look for the <kind of server> variable. Replace it with a server type, for example, demo.
    Reminder: the names you supply for name_of_server and kind_of_server are arbitrary--the examples are chosen to be descriptive.
  8. Locate the following comment:
     nc.bind (aName, /*servant_variable*/);
    
  9. Replace the commented parameter with the servant name (for example, servant) so that the line looks like this:
     nc.bind (aName, servant);
    

Save the changes to the file. The last step in completing the server class is to compile all the classes related to the server, including the IDL file:

To compile your server:

See also
Completing Client-Side Files
Generating CORBA Files

Legal Notices