gnu.cajo.utils.extra
Class InterceptorItem

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

public class InterceptorItem
extends java.lang.Object
implements Invoke

This class is used to transparently intercept method invocations on any given object reference. It is typically used to dynamically substitute functionality, without having to change the implementation of the intercepted object. If the interceptor object does not wish to process a particular invocation, it will be automatically passed to the intercepted object for processing.

Version:
1.0, 22-Sep-07 Initial release
Author:
John Catherino
See Also:
Serialized Form

Field Summary
static java.lang.Object CONTINUE
          This object is used a signal from an interceptor object.
 java.lang.Object interceptor
          The interceptor object.
 java.lang.Object item
          This is the object to be intercepted.
 
Constructor Summary
InterceptorItem(java.lang.Object item, java.lang.Object interceptor)
          This creates the object, to intercept the target object's calls.
 
Method Summary
 java.lang.Object invoke(java.lang.String method, java.lang.Object args)
          This method intercepts the incoming calls.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

interceptor

public final java.lang.Object interceptor
The interceptor object. This object will recieve the remote invocation first, on a method of matching signature. The interceptor has the option to process the invocation itself, or pass it on to the intercepted object for processing. It is declared as public to allow the reference of the InterceptorItem, and its interceptor object, from a single instance of InterceptorItem.


item

public final java.lang.Object item
This is the object to be intercepted. Since it has no knowlege of the interception it's structure need not be changed in any way to accomodate it. It is declared as public to allow the reference of the InterceptorItem, and its intercepted object, from a single instance of InterceptorItem.


CONTINUE

public static final java.lang.Object CONTINUE
This object is used a signal from an interceptor object. When it is returned from a method invocation, it means that the interceptor object wants to have the intercepted object process the invocation instead.

Constructor Detail

InterceptorItem

public InterceptorItem(java.lang.Object item,
                       java.lang.Object interceptor)
This creates the object, to intercept the target object's calls. The class is not declared final, to allow no-arg intercepting items to be subclased, if needed.

Parameters:
item - The object to receive the client invocation. It can be local, remote, or even a proxy.
interceptor - The object to receive the calls prior to the intercepted item's operation. It can be local, remote, or even a proxy.
Method Detail

invoke

public java.lang.Object invoke(java.lang.String method,
                               java.lang.Object args)
                        throws java.lang.Exception
This method intercepts the incoming calls. The interceptor object has three options:

Note: if the interceptor object does not have a method comparably matching what is being invoked, it will be automatically passed on to the intercepted object. This allows the interceptor to define only the methods it wishes to potentially override/except.

Specified by:
invoke in interface Invoke
Parameters:
method - The intercepted object's public method being called.
args - The arguments being passed to the intercepted object's method.
Returns:
The actual or intercepted result, if any, from the invocation.
Throws:
java.lang.NoSuchMethodException - If the method/agruments signature cannot be matched to the internal object's public method interface.
java.rmi.RemoteException - For any network realated failures.
java.lang.Exception - If the interceptor object's method rejects the invocation, or if it has been rejected by the intercepted object.