1 16 17 package org.springframework.aop.interceptor; 18 19 import java.io.Serializable ; 20 21 import org.aopalliance.intercept.MethodInterceptor; 22 import org.aopalliance.intercept.MethodInvocation; 23 24 import org.springframework.aop.Advisor; 25 import org.springframework.aop.support.DefaultPointcutAdvisor; 26 27 42 public class ExposeInvocationInterceptor implements MethodInterceptor, Serializable { 43 44 45 public static final ExposeInvocationInterceptor INSTANCE = new ExposeInvocationInterceptor(); 46 47 51 public static final Advisor ADVISOR = new DefaultPointcutAdvisor(INSTANCE) { 52 public int getOrder() { 53 return Integer.MIN_VALUE; 54 } 55 public String toString() { 56 return ExposeInvocationInterceptor.class.getName() +".ADVISOR"; 57 } 58 }; 59 60 private static final ThreadLocal invocation = new ThreadLocal (); 61 62 63 69 public static MethodInvocation currentInvocation() throws IllegalStateException { 70 MethodInvocation mi = (MethodInvocation) invocation.get(); 71 if (mi == null) 72 throw new IllegalStateException ( 73 "No MethodInvocation found: Check that an AOP invocation is in progress, " + 74 "and that the ExposeInvocationInterceptor is in the interceptor chain."); 75 return mi; 76 } 77 78 79 82 private ExposeInvocationInterceptor() { 83 } 84 85 public Object invoke(MethodInvocation mi) throws Throwable { 86 Object old = invocation.get(); 87 invocation.set(mi); 88 try { 89 return mi.proceed(); 90 } 91 finally { 92 invocation.set(old); 93 } 94 } 95 96 101 private Object readResolve() { 102 return INSTANCE; 103 } 104 105 } 106 | Popular Tags |