Class DynamicObject

  • All Implemented Interfaces:
    Invoke, java.io.Serializable, java.rmi.Remote

    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
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object object  
    • Constructor Summary

      Constructors 
      Constructor Description
      DynamicObject​(java.lang.Object object)
      The constructor assigns the initial server object reference.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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
    • Field Detail

      • object

        private transient java.lang.Object object
    • 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.