Class Interceptors


  • public final class Interceptors
    extends Object
    Interceptor utility and factory methods.
    Author:
    David M. Lloyd
    • Method Detail

      • getInitialInterceptor

        public static Interceptor getInitialInterceptor()
        Get an interceptor that is always invoked first. This interceptor is responsible for correctly handling any initialization and cleanup for the interceptor chain. For example, this interceptor is responsible for handling undeclared checked exceptions.
        Returns:
        the interceptor
      • getInitialInterceptorFactory

        public static InterceptorFactory getInitialInterceptorFactory()
        Get the interceptor factory for the initial interceptor.
        Returns:
        the factory
      • getTerminalInterceptor

        public static Interceptor getTerminalInterceptor()
        Get an interceptor which always returns null.
        Returns:
        the interceptor
      • getTerminalInterceptorFactory

        public static InterceptorFactory getTerminalInterceptorFactory()
        Get a factory which returns the terminal interceptor.
        Returns:
        the factory
      • getInvokingInterceptor

        public static Interceptor getInvokingInterceptor()
        Get an invoking interceptor which always terminates. If the invoked method is null, this interceptor returns null, making it suitable for terminating lifecycle interceptor chains as well as invocation interceptor chains.
        Returns:
        the interceptor
      • getInvokingInterceptorFactory

        public static InterceptorFactory getInvokingInterceptorFactory()
        Get a factory which returns the invoking interceptor.
        Returns:
        the factory
      • getChainedInterceptor

        public static Interceptor getChainedInterceptor​(Interceptor... instances)
        Get a chained interceptor which passes the invocation through the given interceptors.
        Parameters:
        instances - the interceptors to pass through
        Returns:
        the chained interceptor
      • getChainedInterceptor

        public static Interceptor getChainedInterceptor​(Collection<Interceptor> instances)
        Get a chained interceptor which passes the invocation through the given interceptors.
        Parameters:
        instances - the interceptors to pass through
        Returns:
        the chained interceptor
      • getChainedInterceptorFactory

        public static InterceptorFactory getChainedInterceptorFactory​(InterceptorFactory... instances)
        Get a chained interceptor factory which builds a chained interceptor using the given factories.
        Parameters:
        instances - the interceptor factories to use
        Returns:
        the chained interceptor factory
      • getChainedInterceptorFactory

        public static InterceptorFactory getChainedInterceptorFactory​(Collection<InterceptorFactory> instances)
        Get a chained interceptor which passes the invocation through the given interceptors.
        Parameters:
        instances - the interceptors to pass through
        Returns:
        the chained interceptor
      • rethrow

        public static Exception rethrow​(Throwable throwable)
                                 throws Error
        Convenience method to get a Throwable as an Exception.
        Parameters:
        throwable - the throwable
        Returns:
        the exception to throw
        Throws:
        Error - if the throwable is an error type