Class Implements

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

public final class Implements extends Object implements Invoke
This class takes any service object, and allows its methods to be tested for existence, without having to invoke them. This is particularly important to enable Type Substitution. In other words; a client could check if a service object implemented its specific interface.

When a service is remoted, wrapped in this object; clients can invoke the methods they assume this object implements. Instead of the normal method return; it will return a boolean. True will indicate that the service supports the method, otherwise it will return false. No side effects to the wrapped object will be incurred by this service. In fact; the service object will be completely unaware of the testing.

One suggested protocol: A service object could provide a public getImplements(); method, which would return a remote reference to the service object, wrapped by an Implements instance. A new reference needn't be created for each call, and in fact, the reference can even be instantiated lazily, i.e. if needed.

As a template:

 private Remote myImplements;
 public RemoteInvoke getImplements() throws java.rmi.RemoteException {
    return myImplements == null ?
       myImplements = new Remote(new Implements(this)) : myImplements;
 }
Version:
1.0, 03-Apr-07
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Object
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Implements(Object service)
    The constructor takes any service object, and allows it to be remotely tested for method existence, without having to invoke it.
  • Method Summary

    Modifier and Type
    Method
    Description
    invoke(String method, Object args)
    Instead of actually invoking the method on the target object, this object will test for the existence of the method on the target object, either and return true or false.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • service

      private final Object service
  • Constructor Details

    • Implements

      public Implements(Object service)
      The constructor takes any service object, and allows it to be remotely tested for method existence, without having to invoke it.
      Parameters:
      service - The service object to make remotely testable for method callability.
  • Method Details

    • invoke

      public Object invoke(String method, Object args)
      Instead of actually invoking the method on the target object, this object will test for the existence of the method on the target object, either and return true or false.
      Specified by:
      invoke in interface Invoke
      Parameters:
      method - The method to check for existence
      args - The signature of the particular method would accept, the arguments can be null, or subclasses of the expected arguments. Typically these are represented by class, but they also can be passed in by instance.
      Returns:
      Instead of the method's normal return, if any, it will be true if the service supports this method and signature, otherwise false.