Class MethodInterceptor

  • All Implemented Interfaces:
    Interceptor

    public final class MethodInterceptor
    extends Object
    implements Interceptor
    A method interceptor. The target method should be non-final and must accept no parameters or a single parameter of type InvocationContext (or any supertype thereof). The method must belong to the given interceptor object's class or one of its supertypes.
    Author:
    David M. Lloyd
    • Constructor Detail

      • MethodInterceptor

        public MethodInterceptor​(Object interceptorInstance,
                                 Method method,
                                 boolean changeMethod)
        Construct a new instance. The given method should be a proper interceptor method; otherwise invocation may fail.
        Parameters:
        interceptorInstance - the interceptor object instance
        method - the interceptor method
        changeMethod - true to change the method on the context to equal the given method, false to leave it as-is
      • MethodInterceptor

        public MethodInterceptor​(Object interceptorInstance,
                                 Method method)
        Construct a new instance. The given method should be a proper interceptor method; otherwise invocation may fail.
        Parameters:
        interceptorInstance - the interceptor object instance
        method - the interceptor method
    • Method Detail

      • processInvocation

        public Object processInvocation​(InterceptorContext context)
                                 throws Exception
        Process an invocation. The invocation can be handled directly, or passed on to the next processor in the chain.
        Specified by:
        processInvocation in interface Interceptor
        Parameters:
        context - the interceptor context
        Returns:
        the result of the invocation
        Throws:
        Exception - If the underlying invocation resulted in some exception