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:
-
For all binding methods, you must add code that
instantiates the implementation class and connects it to the ORB.
-
If your server class writes the IOR to standard output, you must add code that
converts the IOR to string form and writes it to standard output.
-
If your server class writes the IOR to a file, you must add code that converts
the IOR to string form and writes it to a file that you specify.
-
If your server class registers the IOR with a naming service, you must
add code that specifies the name to which the IOR will be bound in the naming
service operation.
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:
-
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*/);
-
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:
-
Look for the following line in your generated server class:
System.out.println(orb.object_to_string (/*servant_variable*/));
-
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:
-
Look for the following lines in your generated server class:
String ior = orb.object_to_string (/*servant_variable*/);
FileWriter file = new java.io.FileWriter("");
...
-
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:
-
Start the naming service with which you plan to register your
server.
-
In the IDE, go to the Explorer's Runtime tab.
-
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:
-
Right-click the node for the JDK Naming Service and choose Create New
Context. This opens a dialog box.
-
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.
-
Right-click the node that represents the naming context in which you
are registering the server, and choose Copy Server Binding Code.
-
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
-
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.
-
Complete the pasted code by supplying the name that will be used for your
servant instance, as follows:
-
Look for the
<name of server>
variable. Replace it
with the server name, for example, Hello.
-
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.
-
Locate the following comment:
nc.bind (aName, /*servant_variable*/);
-
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:
- Right-click the node for the package and choose Compile.
Legal Notices