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:
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:
// add your creating of object implementation here
/*servant_class*/ /*servant_variable*/ = new /*servant_class*/();
orb.connect(/*servant_variable*/);
helloworld.HelloApp.HelloImpl servant = new helloworld.HelloApp.HelloImpl(); orb.connect(servant);
To add code that writes the IOR to standard output:
System.out.println(orb.object_to_string (/*servant_variable*/));
System.out.println(orb.object_to_string (servant));
To add code that writes the IOR to a file:
String ior = orb.object_to_string (/*servant_variable*/);
FileWriter file = new java.io.FileWriter("");
...
String ior = orb.object_to_string (servant);
FileWriter file = new java.io.FileWriter("HelloIOR");
...
To add code that specifies the binding name:
To create a new naming context:
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.
// paste code retrieved using the Copy Client/Server Code action // (on the corresponding node in the Naming Service Browser) here
The code you pasted registers an object with the naming service and naming context you selected with the Naming Service browser.
<name of server> variable. Replace it
with the server name, for example, Hello.<kind of server> variable. Replace it with
a server type, for example, demo.nc.bind (aName, /*servant_variable*/);
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 |
|