org.springframework.aop.interceptor
Class ExposeInvocationInterceptor

java.lang.Object
  extended by org.springframework.aop.interceptor.ExposeInvocationInterceptor
All Implemented Interfaces:
java.io.Serializable, Ordered

public class ExposeInvocationInterceptor
extends java.lang.Object
implements Ordered, java.io.Serializable

Interceptor that exposes the current org.aopalliance.intercept.MethodInvocation as a thread-local object. We occasionally need to do this; for example, when a pointcut (e.g. an AspectJ expression pointcut) needs to know the full invocation context.

Don't use this interceptor unless this is really necessary. Target objects should not normally know about Spring AOP, as this creates a dependency on Spring API. Target objects should be plain POJOs as far as possible.

If used, this interceptor will normally be the first in the interceptor chain.

Author:
Rod Johnson, Juergen Hoeller
See Also:
Serialized Form

Field Summary
static Advisor ADVISOR
          Singleton advisor for this class.
static ExposeInvocationInterceptor INSTANCE
          Singleton instance of this class
private static java.lang.ThreadLocal<MethodInvocation> invocation
           
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
private ExposeInvocationInterceptor()
          Ensures that only the canonical instance can be created.
 
Method Summary
static MethodInvocation currentInvocation()
          Return the AOP Alliance MethodInvocation object associated with the current invocation.
 int getOrder()
          Return the order value of this object, with a higher value meaning greater in terms of sorting.
 java.lang.Object invoke(MethodInvocation mi)
           
private  java.lang.Object readResolve()
          Required to support serialization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final ExposeInvocationInterceptor INSTANCE
Singleton instance of this class


ADVISOR

public static final Advisor ADVISOR
Singleton advisor for this class. Use in preference to INSTANCE when using Spring AOP, as it prevents the need to create a new Advisor to wrap the instance.


invocation

private static final java.lang.ThreadLocal<MethodInvocation> invocation
Constructor Detail

ExposeInvocationInterceptor

private ExposeInvocationInterceptor()
Ensures that only the canonical instance can be created.

Method Detail

currentInvocation

public static MethodInvocation currentInvocation()
                                          throws java.lang.IllegalStateException
Return the AOP Alliance MethodInvocation object associated with the current invocation.

Returns:
the invocation object associated with the current invocation
Throws:
java.lang.IllegalStateException - if there is no AOP invocation in progress, or if the ExposeInvocationInterceptor was not added to this interceptor chain

invoke

public java.lang.Object invoke(MethodInvocation mi)
                        throws java.lang.Throwable
Throws:
java.lang.Throwable

getOrder

public int getOrder()
Description copied from interface: Ordered
Return the order value of this object, with a higher value meaning greater in terms of sorting.

Normally starting with 0, with Integer.MAX_VALUE indicating the greatest value. Same order values will result in arbitrary positions for the affected objects.

Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).

Specified by:
getOrder in interface Ordered
Returns:
the order value

readResolve

private java.lang.Object readResolve()
Required to support serialization. Replaces with canonical instance on deserialization, protecting Singleton pattern.

Alternative to overriding the equals method.