return new RunInInterceptionContext() {
@Override
protected Object doWork(InvocationContext ctx) throws Exception {
int oldCurrentPosition = currentPosition;
try {
InterceptorMethodInvocation nextInterceptorMethodInvocation = interceptorMethodInvocations.get(currentPosition++);
InterceptorLogger.LOG.invokingNextInterceptorInChain(nextInterceptorMethodInvocation);
if (nextInterceptorMethodInvocation.expectsInvocationContext()) {
return nextInterceptorMethodInvocation.invoke(invocationContext);
} else {
nextInterceptorMethodInvocation.invoke(null);
while (hasNextInterceptor()) {
nextInterceptorMethodInvocation = interceptorMethodInvocations.get(currentPosition++);
nextInterceptorMethodInvocation.invoke(null);
}
return null;
}
} finally {
currentPosition = oldCurrentPosition;