Java Reference
In-Depth Information
•
java.rmi.NotBoundException
: Thrown if you attempt to look up or unbind an object
that has no associated binding
•
java.rmi.RemoteException
: The common superclass for communications-related
exceptions that may occur during remote method invocation
•
java.rmi.UnexpectedException
: Thrown if the client of a remote method call receives
an exception that is not among the exception types declared in the
throws
clause of
the method in the remote interface
•
java.rmi.registry.Registry
: A remote interface to a remote object registry
It's important to remember that the IXC mechanism lets you invoke the methods of
objects in another Xlet's context, rather than share data in its simplest sense. In other
words, you can't obtain or mutate attributes of an object through IXC and objects that
implement
java.rmi.Remote
; instead, you must make attributes available through meth-
ods. Given that this is good object-oriented practice anyway, it shouldn't be an issue,
but it does mean defining appropriate accessor and mutator methods for any field in
your class that you want to be available to a remote Xlet. That's why
Location
defines
setLocation
,
setForecast
,
getLocation
, and
getForecast
as mutators and accessors to
private fields, rather than simply making those fields public.
Sharing an Object for Other Xlets to Find
Once you define your remotable object(s), you still need to make them available to other
Xlets. Doing this is a two-step process: first, you create the objects your Xlet will share,
and then you add them to the system-wide Xlet registry. The registry, which is an instance
of
javax.microedition.xlet.ixc.IxcRegistry
, keeps a name-object mapping of the objects
registered by all Xlets running on the machine.
■
Caution
Don't confuse the
IxcRegistry
with the
java.rmi.Naming
or
java.rmi.registry.
LocateRegistry
registries; even if RMI is available on the machine, the
IxcRegistry
is a separate
registry of remotable objects.
You can't obtain an instance of
IxcRegistry
directly; instead, you obtain one from
the
XletContext
. Under the hood, the PBP implementation maintains a strict one-to-
one correspondence between
IxcRegistry
instances and
XletContext
s, sharing data
through a system-wide database of IXC exported objects. Using the
IxcRegistry
,you
can do the following: