Chapter 12: CORBA/IDL: An Example
To illustrate the process of developing a CORBA application using IDL, we will implement some of the EU
statistics example from RMI Implementation chapter. The basic steps are (i) writing the IDL interface; (ii)
writing the server; (iii) writing the client; and (iv) compiling and starting up the system. Note that if you are
using a new version of Java, then you will find the default server-side model is different, and I have not yet
migrated the notes to the new version. To get idlj to generate the code below, use the -oldImplBase flag.
12.1. Writing the IDL Interface
We have already done this of course, in the previous chapter. Here it is again, as before, except we have now
made it part of a module
module Stats {
interface EUStats {
string getMainLangs(in string countryname);
long getPopulation(in string countryname);
string getCapital(in string countryname);
};
};
At this point, we can run idlj (or idltojava if you have an old JDK) to generate the various auxilliary files
we need. If we do this, we get six new Java files (in a new directory called Stats, assuming we called our
interface file Stats.idl, which would be good practice). Note that the actual content is not very interesting
(or comprehensible: you're not really supposed to need to look at them and your definitely not supposed to edit
them. The six files are as follows.
·
EUStats.java This is just our IDL Interface turned into Java. However, because it needs to inherit (extend)
from assorted CORBA classes, it uses an `intermediate' interface called EUStatsOperations.java
·
EUStatsOperations.java This is the `real' interface class.
·
StatsImplBase.java This is an abstract class, sometimes called the server skeleton. It implements the
EUStats.java interface, and the servant class, which we are going to have to write and which forms
the core of the server, must extend it. (Note that Steflik and Sridharan actually call this the servant class:
this is a bit confusing as it isn't really - the servant class is something you