Java Reference
In-Depth Information
class anything we choose, but to be consistent with certain CORBA naming
conventions, we use the filename Cor19Servant.java . Another name one
might see in CORBA examples is Cor19ExampleImpl.java since it is the
implementation of the interface known as Cor19Example .However,wefind
the “servant” nomenclature easier to keep straight in our minds for reasons that
should become clear shortly.
In CORBA terminology, a “servant” is an implementation of an interface. In
Java, we can say that a servant is an instance of the Java object that implements
the operations declared in the IDL interface. Then a “server” is a process that
instantiates the servant objects and makes them available via the CORBA sub-
system. In Java, we create another class to be the CORBA server process for
this example, somewhat like the RMIExampleServer class from Chapter 18,
whose role was to create an instance of the implementation class.
19.4.1 Servant implementation
In order to be a CORBA servant, our class must extend org.omg.
PortableServer.Servant . Actually, this extension is handled by extend-
ing Cor19ExamplePOA ,which itself extends org.omg.PortableServer.
Servant and also adds other features needed by the CORBA subsystem. Thus
our implementation file begins
public class Cor19Servant extends Cor19ExamplePOA {
Our implementation (servant) class must implement each of the methods defined
in the IDL file. Servant methods look just like regular Java methods. The code
to handle all of the CORBA communications is provided by the skeleton class in
Cor19ExamplePOA and its superclasses.
Returning to the IDL file, we first have the attributes huh and hah to imple-
ment. Hah is read-only, so we need only provide a getter method of the appropriate
signature. That signature is a method named hah with no parameters, returning
the type of the attribute, in this case float .Wecreate a private instance variable
named fHah for the value of the hah attribute. The idea is that the attribute hah ,
embodied in the implementation code in a variable named fHah is used for some
purpose within the implementation. Since the IDL file has identified this as an
attribute, we must assume that the client might want to query its value. The client
does so by calling the hah() method. Since hah is read-only, there is no way
for the client to set its value. Our implementation is simply
public float hah () {
return fHah;
}
Next comes the huh attribute, which is not read-only. There must be a getter
method, similar to that for hah , along with a private instance variable to contain
Search WWH ::




Custom Search