Class DynamicObject

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

public final class DynamicObject extends 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
See Also:
  • Field Details

    • object

      private transient Object object
  • Constructor Details

    • DynamicObject

      public DynamicObject(Object object)
      The constructor assigns the initial server object reference.
      Parameters:
      object - The initial encapsulated server functionality to be remoted through this object.
  • Method Details

    • invoke

      public Object invoke(String method, Object args) throws 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:
      NoSuchMethodException - If no matching method can be found.
      Exception - If the wrapped object rejected the invocation, for application specific reasons.
    • changeObject

      public void changeObject(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.