gnu.cajo.utils.extra
Class DynamicObject

java.lang.Object
  extended by gnu.cajo.utils.extra.DynamicObject
All Implemented Interfaces:
Invoke, java.io.Serializable

public final class DynamicObject
extends java.lang.Object
implements Invoke

This is a dynamic server object dispatcher. Its purpose it to provide a client with a single remote object reference, whose functionality can be changed by the server at runtime. A server would remote this object wrapper, then use its changeObject method to redefine the functionality of the client's reference dynamically. Note: the wrapped object can be of any type, and it need not even implement the gnu.cajo.invoke.Invoke interface.

While being only 5 lines of Java source code, its capability is elegantly sophisticated.

Version:
1.0, 03-Nov-05 Initial release
Author:
John Catherino
See Also:
Serialized Form

Constructor Summary
DynamicObject(java.lang.Object object)
          The constructor assigns the initial server object reference.
 
Method Summary
 void changeObject(java.lang.Object object)
          This method is used to dynamically redefine the functionality of this wrapper at runtime.
 java.lang.Object invoke(java.lang.String method, java.lang.Object args)
          This method simply redirects all invocations to the currently wrapped object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicObject

public DynamicObject(java.lang.Object object)
The constructor assigns the initial server object reference.

Parameters:
object - The initial encapsulated server functionality to be remoted through this object.
Method Detail

invoke

public java.lang.Object invoke(java.lang.String method,
                               java.lang.Object args)
                        throws java.lang.Exception
This method simply redirects all invocations to the currently wrapped object.

Specified by:
invoke in interface Invoke
Parameters:
method - The method name to be invoked on the wrapped object.
args - The arguments to provide to the method for its invocation.
Returns:
The resulting data, if any, from the invocation.
Throws:
java.lang.NoSuchMethodException - If no matching method can be found.
java.lang.Exception - If the wrapped object rejected the invocation, for application specific reasons.

changeObject

public void changeObject(java.lang.Object object)
This method is used to dynamically redefine the functionality of this wrapper at runtime. The remote client reference never changes, but what the reference does, can be updated by the server repeatedly.

Parameters:
object - The new encapsulated functionality to be provided to the remote clients.