gnu.cajo.utils.extra
Class Implements

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

public final class Implements
extends java.lang.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
Author:
John Catherino
See Also:
Serialized Form

Constructor Summary
Implements(java.lang.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
 java.lang.Object invoke(java.lang.String method, java.lang.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
 

Constructor Detail

Implements

public Implements(java.lang.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 Detail

invoke

public java.lang.Object invoke(java.lang.String method,
                               java.lang.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.