Java Reference
In-Depth Information
Create a servant .
Easy enough:
HelloServant servant = new HelloServant();
Register the servant with the ORB .
This allows the ORB to pass invocations to the servant and is achieved by
means of the ORB class's connect method:
Get a reference to the root naming context .
Method resolve_initial_references of class ORB is called with the String
argument “NameService” (defi ned for all CORBA ORBs) and returns a
CORBA Object reference that points to the naming context:
org.omg.CORBA.Object objectRef =
'Narrow' the context reference .
In order for the generic Object reference from the previous step to be usable,
it must be 'narrowed' (i.e., typecast 'down' into its appropriate type). This is
achieved by the use of method narrow of class NamingContextHelper (from
package org.omg.CosNaming ):
NamingContext namingContext =
Create a NameComponent object for our interface .
The NameComponent constructor takes two String arguments, the fi rst of which
supplies a name for our service. The second argument can be used to specify a
category (usually referred to as a 'kind') for the fi rst argument, but is typically
left as an empty string. In our example, the service will be called 'Hello':
NameComponent nameComp =
new NameComponent("Hello", "");
Specify the path to the interface .
This is effected by creating an array of NameComponent objects, each of
which is a component of the path (in 'descending' order), with the last com-
ponent specifying the name of the NameComponent reference that points to
the service. For a service in the same directory, the array will contain a single
element, as shown below.
NameComponent[] path = (nameComp};
(viii) Bind the servant to the interface path .
The rebind method of the NamingContext object created earlier is called with
arguments that specify the path and service respectively:
Search WWH ::

Custom Search