Java Reference
In-Depth Information
(v)
Specify the path to the interface
.
NameComponent[] path = (nameComp};
(vi)
Get a reference to the interface
.
This is achieved by passing the above interface path to our naming context's
resolve
method, which returns a CORBA
Object
reference:
org.omg.CORBA.Object objectRef =
namingContext.resolve(path);
(vii)
'Narrow' the interface reference
.
We 'downcast' the reference from the previous step into a
Hello
reference via
static method
narrow
of the
idlj
-generated class
HelloHelper
:
Hello helloRef = HelloHelper.narrow(objectRef);
(viii)
Invoke the required method(s) and display results
.
We use the reference from the preceding step to invoke the required method,
just as though the call were being made to a local object:
System.out.println("Message received: "
+ greeting);
As was the case with the server, our client may then generate CORBA system
exceptions, and so all the executable code will be placed inside a
try
block.
The full program is shown below.
import SimpleCORBAExample.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
public class HelloClient
{
public static void main(String[] args)
{
try
{
ORB orb = ORB.init(args,null);
org.omg.CORBA.Object objectRef =
orb.resolve_initial_references(
"NameService");
NamingContext namingContext =
NamingContextHelper.narrow(objectRef);
NameComponent nameComp =
new NameComponent("Hello", "");
NameComponent[] path = {nameComp};
//Re-use existing object reference…
Search WWH ::
Custom Search