net.openmarkup
Class Interceptor

java.lang.Object
  extended bynet.openmarkup.Interceptor
All Implemented Interfaces:
InvocationHandler
Direct Known Subclasses:
LoggingInterceptor

public abstract class Interceptor
extends Object
implements InvocationHandler

Interceptor

Author:
Ramesh Gupta

Constructor Summary
Interceptor(Object delegate)
           
 
Method Summary
static Class[] getInterceptorClasses()
           
 Object invoke(Object proxy, Method method, Object[] args)
          Heart of the interceptor
protected  void processAfter(Method meth, Object result)
          Called after a method is invoked.
protected  void processBefore(Method meth, Object[] args)
          Called before method is invoked.
protected abstract  void processError(Object delegate, Method meth, Object[] args, Throwable ex)
          Error handling method.
static Object wrap(Object delegate)
          Wrap delegate with default interceptors.
static Object wrap(Object delegate, Class[] interceptorClasses)
          Wrap delegate with explicit interceptors, forming a "chain of responsibility".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interceptor

public Interceptor(Object delegate)
Method Detail

getInterceptorClasses

public static Class[] getInterceptorClasses()

wrap

public static Object wrap(Object delegate)
Wrap delegate with default interceptors.

Parameters:
delegate -
Returns:
dynamic proxy

wrap

public static Object wrap(Object delegate,
                          Class[] interceptorClasses)
Wrap delegate with explicit interceptors, forming a "chain of responsibility".

Parameters:
delegate -
interceptorClasses -
Returns:
dynamic proxy

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Heart of the interceptor

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy -
method -
args -
Returns:
result of invocation
Throws:
Throwable

processBefore

protected void processBefore(Method meth,
                             Object[] args)
Called before method is invoked. May be overridden to provide specific functionality, such as trace logs, auditing, or security checks.

Parameters:
meth -
args -

processAfter

protected void processAfter(Method meth,
                            Object result)
Called after a method is invoked. May be overridden...

Parameters:
meth -
result -

processError

protected abstract void processError(Object delegate,
                                     Method meth,
                                     Object[] args,
                                     Throwable ex)
                              throws Throwable
Error handling method. MUST be implemented by interceptor subclasses. This error handling method may try to invoke the failed method again on the delegate, optionally changing the method arguments, if necessary. It may also choose to handle the error partially, and propagate it along the chain of responsibility, or handle it completely and stop any further processing along the chain.

Parameters:
delegate -
meth -
args -
ex -
Throws:
Throwable


Copyright 2003-2004 eNode, Inc. All rights reserved.