Java Reference
In-Depth Information
Notice that the type of obj - ref is the fully qualified org.omg.CORBA.
Object . Whenever we refer to a CORBA Object ,wemust fully specify the
type to distinguish it from java.lang.Object .
Now we have a generic CORBA object reference, but not a reference to
the required Cor19Example interface that is needed by the naming ser-
vice and, eventually, the client. To obtain the specific type from the generic
CORBA Object type,
we
must
narrow
the
object
reference
using
the
Cor19ExampleHelper class:
Cor19Example cor19 = Cor19ExampleHelper.narrow (obj - ref);
19.4.2.4 Get a reference to the naming service
The naming service in CORBA is known as COSNaming and is implemented in
the org.omg.CosNaming package. COSNaming provides functions somewhat
like the RMI naming service in that server-side objects (servants) are bound into
the naming service under a specific name and clients perform a lookup on that
name to gain access to the servant's operations. An object reference to the naming
service is found with the ORB.resolve - initial - references() method
using the well-known name NameService , which is required to be defined
for all CORBA ORB implementations. As usual, this call returns a generic
CORBA object which must be narrowed to the type desired using the appro-
priate Helper class. For the case of the naming service, the desired type is a
NamingContextExt object:
org.omg.CORBA.Object ns - ref =
orb.resolve - initial - references ( " NameService " );
NamingContextExt ncRef =
NamingContextExtHelper.narrow (ns - ref);
19.4.2.5 Bind the servant into the naming service
Now we can register our servant with the naming service under a specific
name. The name given to NamingContextExt is not quite as simple as
a plain Java String ,again a complication owing to the generality and
language-neutrality of CORBA. Instead of a plain String ,wemust pass
in an org.omg.CosNaming.NameComponent array. Fortunately, the Nam-
ingContextExt class provides a to - name() method to translate a plain Java
String name into a NameComponent array:
NameComponent[] path = ncRef.to - name ("Cor19");
Then, to bind into the naming service, we use
ncRef.rebind (path, cor19);
Recall that cor19 is a reference to the Cor19Example interface that corre-
sponds to the Cor19ExampleServant object that was instantiated above. Now,
Search WWH ::




Custom Search