Package gnu.cajo.utils.extra
Class InterceptorItem
java.lang.Object
gnu.cajo.utils.extra.InterceptorItem
- All Implemented Interfaces:
Invoke
,Serializable
,Remote
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
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInterceptorItem
(Object item, Object interceptor) This creates the object, to intercept the target object's calls. -
Method Summary
-
Field Details
-
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
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
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 Details
-
InterceptorItem
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 Details
-
invoke
This method intercepts the incoming calls. The interceptor object has three options:- Process the method invocation itself, effectively overriding the functionality of the intercepted object.
- Throw an exception, effectively excepting the method of the intercepted object.
- Return the static final
InterceptorItem.CONTINUE
object, indicating that the intercepted object should process the invocation.
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 interfaceInvoke
- 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:
NoSuchMethodException
- If the method/agruments signature cannot be matched to the internal object's public method interface.RemoteException
- For any network realated failures.Exception
- If the interceptor object's method rejects the invocation, or if it has been rejected by the intercepted object.
-