The next thing our client needs to do is to get a reference to a CORBA object implementing Hello World. Recall from "Defining the interface" on page 10 that our IDL defined CORBA objects of a kind called world:
interface world {
string hello();
}
The client needs a reference to a world object. An object reference is just CORBA's way of allowing CORBA objects to be identified and communicated with. Once our client has a reference to a world object it can call the hello operation and get the string it needs to print out.
There is more to say about object references and how they are obtained. For now, all we need to know is one way that clients can obtain object references is by reading them from files, where servers have placed them in a string form -- a so-called stringified object reference. The client can get the string and convert it into a Dylan object that represents object references. To do this, it uses a .Dylan ORB utility called corba/orb/file-to-object.
Thus, given a shared file hello.ior, located as follows:
c:\temp\hello.ior
Our client can get a reference as follows:
let world = as(<world>,
corba/orb/file-to-object(orb, "c:\\temp\\hello.ior")
The corba/orb/file-to-object method could have been implemented as follows using the standard ORB utility corba/orb/string-to-object, but corba/orb/file-to-object is provided as a convenience.
define method corba/orb/file-to-object (orb :: corba/<orb>,
file :: <string>)
=> (object)
with-open-file(stream = file, direction: #"input")
corba/orb/string-to-object(orb, as(<string>,
stream-contents(stream)));
end;
end method;
The let world ... expression takes the name of the shared file, and passes it (and the ORB value we obtained earlier) to the helper method file-to-object. The file-to-object method calls corba/orb/string-to-object to obtain the reference and make a Dylan object representing it. Then the returned Dylan object is coerced into an instance of the class <world>. That class is one of the protocol library classes generated from the IDL, and was intended to represent world objects in Dylan. (In fact the object is coerced to be an instance of an internal concrete subclass of <world> -- <world> is just the public protocol class.)
The extra backslashes in the file name string serve as escape characters.