Example 4: Hello World with Implementation Inheritance
Ordinarily, servant classes must inherit from the ImplBase
class generated by the idlj compiler. This is
inadequate for servant classes that need to inherit functionality from
another Java class. The Java programming language allows a class only
one superclass and the generated ImplBase class
occupies this position.
Example 4 illustrates how a servant class can inherit (an implementation)
from any Java class. In this example,
the HelloServant class inherits its
entire implementation from another Java class HelloBasic.
At runtime, method requests for HelloServant are delegated to another
idlj-generated class.
Example 4 is identical to Example 1 except for implementation inheritance
enhancements. This page only discusses
the code necessary for these enhancements.
This section contains:
The IDL for a simple "Hello World" program
A server implementation that delegates method requests for
HelloServant to another Java class.
A client program.
Instructions for compiling and running
the example are provided.
The following instructions assume you can use port 1050
for the Java IDL name server. Substitute a different
port if necessary. Note that for ports below 1024,
you need root access on UNIX machines, and administrator
privileges on Windows95 and NT. Note also that the instructions use
a slash (/) for path names. Windows95 and NT users should
subtitute a backslash (\).
Create source code files as shown above.
Run idlj on the IDL file to
create stubs and skeletons:
idlj -fall -ftie Hello.idl
Compile the .java files, including the stubs and skeletons:
javac *.java HelloApp/*.java
Make sure the name server is running:
tnameserv -ORBInitialPort 1050&
Start the Hello server:
java HelloServer -ORBInitialPort 1050
Run the Hello application client from a different shell than the
server: