public abstract class

AbstractAspectJAdvice

extends Object
implements AspectJPrecedenceInformation
java.lang.Object
   ↳ org.springframework.aop.aspectj.AbstractAspectJAdvice
Known Direct Subclasses

Class Overview

Base class for AOP Alliance org.aopalliance.aop.Advice classes wrapping an AspectJ aspect or an AspectJ-annotated advice method.

Summary

[Expand]
Inherited Constants
From interface org.springframework.core.Ordered
Fields
protected static final String JOIN_POINT_KEY Key used in ReflectiveMethodInvocation userAtributes map for the current joinpoint.
protected final Method aspectJAdviceMethod
Public Constructors
AbstractAspectJAdvice(Method aspectJAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aspectInstanceFactory)
Create a new AbstractAspectJAdvice for the given advice method.
Public Methods
final Pointcut buildSafePointcut()
Build a 'safe' pointcut that excludes the AspectJ advice method itself.
synchronized final void calculateArgumentBindings()
Do as much work as we can as part of the set-up so that argument binding on subsequent advice invocations can be as fast as possible.
static JoinPoint currentJoinPoint()
Lazily instantiate joinpoint for the current invocation.
final ClassLoader getAspectClassLoader()
Return the ClassLoader for aspect instances.
final AspectInstanceFactory getAspectInstanceFactory()
Return the factory for aspect instances.
final Method getAspectJAdviceMethod()
Return the AspectJ-style advice method.
String getAspectName()
The name of the aspect (bean) in which the advice was declared.
int getDeclarationOrder()
The declaration order of the advice member within the aspect.
int getOrder()
Return the order value of this object, with a higher value meaning greater in terms of sorting.
final AspectJExpressionPointcut getPointcut()
Return the AspectJ expression pointcut.
void setArgumentNames(String argNames)
Set by creator of this advice object if the argument names are known.
void setArgumentNamesFromStringArray(String[] args)
void setAspectName(String name)
void setDeclarationOrder(int order)
Sets the declaration order of this advice within the aspect
void setReturningName(String name)
void setThrowingName(String name)
String toString()
Protected Methods
Object[] argBinding(JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable ex)
Take the arguments at the method execution join point and output a set of arguments to the advice method
ParameterNameDiscoverer createParameterNameDiscoverer()
Create a ParameterNameDiscoverer to be used for argument binding.
Type getDiscoveredReturningGenericType()
Class getDiscoveredReturningType()
Class getDiscoveredThrowingType()
JoinPoint getJoinPoint()
Overridden in around advice to return proceeding join point.
JoinPointMatch getJoinPointMatch()
Get the current join point match at the join point we are being dispatched on.
JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi)
Object invokeAdviceMethod(JoinPointMatch jpMatch, Object returnValue, Throwable ex)
Invoke the advice method.
Object invokeAdviceMethod(JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable t)
Object invokeAdviceMethodWithGivenArgs(Object[] args)
void setReturningNameNoCheck(String name)
We need to hold the returning name at this level for argument binding calculations, this method allows the afterReturning advice subclass to set the name.
void setThrowingNameNoCheck(String name)
We need to hold the throwing name at this level for argument binding calculations, this method allows the afterThrowing advice subclass to set the name.
boolean supportsProceedingJoinPoint()
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.aop.aspectj.AspectJPrecedenceInformation
From interface org.springframework.core.Ordered

Fields

protected static final String JOIN_POINT_KEY

Key used in ReflectiveMethodInvocation userAtributes map for the current joinpoint.

protected final Method aspectJAdviceMethod

Public Constructors

public AbstractAspectJAdvice (Method aspectJAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aspectInstanceFactory)

Create a new AbstractAspectJAdvice for the given advice method.

Parameters
aspectJAdviceMethod the AspectJ-style advice method
pointcut the AspectJ expression pointcut
aspectInstanceFactory the factory for aspect instances

Public Methods

public final Pointcut buildSafePointcut ()

Build a 'safe' pointcut that excludes the AspectJ advice method itself.

Returns
  • a composable pointcut that builds on the original AspectJ expression pointcut
See Also

public final synchronized void calculateArgumentBindings ()

Do as much work as we can as part of the set-up so that argument binding on subsequent advice invocations can be as fast as possible.

If the first argument is of type JoinPoint or ProceedingJoinPoint then we pass a JoinPoint in that position (ProceedingJoinPoint for around advice).

If the first argument is of type JoinPoint.StaticPart then we pass a JoinPoint.StaticPart in that position.

Remaining arguments have to be bound by pointcut evaluation at a given join point. We will get back a map from argument name to value. We need to calculate which advice parameter needs to be bound to which argument name. There are multiple strategies for determining this binding, which are arranged in a ChainOfResponsibility.

public static JoinPoint currentJoinPoint ()

Lazily instantiate joinpoint for the current invocation. Requires MethodInvocation to be bound with ExposeInvocationInterceptor.

Do not use if access is available to the current ReflectiveMethodInvocation (in an around advice).

Returns
  • current AspectJ joinpoint, or through an exception if we're not in a Spring AOP invocation.

public final ClassLoader getAspectClassLoader ()

Return the ClassLoader for aspect instances.

public final AspectInstanceFactory getAspectInstanceFactory ()

Return the factory for aspect instances.

public final Method getAspectJAdviceMethod ()

Return the AspectJ-style advice method.

public String getAspectName ()

The name of the aspect (bean) in which the advice was declared.

public int getDeclarationOrder ()

The declaration order of the advice member within the aspect.

public int getOrder ()

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).

Returns
  • the order value

public final AspectJExpressionPointcut getPointcut ()

Return the AspectJ expression pointcut.

public void setArgumentNames (String argNames)

Set by creator of this advice object if the argument names are known.

This could be for example because they have been explicitly specified in XML, or in an advice annotation.

Parameters
argNames comma delimited list of arg names

public void setArgumentNamesFromStringArray (String[] args)

public void setAspectName (String name)

public void setDeclarationOrder (int order)

Sets the declaration order of this advice within the aspect

public void setReturningName (String name)

public void setThrowingName (String name)

public String toString ()

Protected Methods

protected Object[] argBinding (JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable ex)

Take the arguments at the method execution join point and output a set of arguments to the advice method

Parameters
jp the current JoinPoint
jpMatch the join point match that matched this execution join point
returnValue the return value from the method execution (may be null)
ex the exception thrown by the method execution (may be null)
Returns
  • the empty array if there are no arguments

protected ParameterNameDiscoverer createParameterNameDiscoverer ()

Create a ParameterNameDiscoverer to be used for argument binding.

The default implementation creates a PrioritizedParameterNameDiscoverer containing a LocalVariableTableParameterNameDiscoverer and an AspectJAdviceParameterNameDiscoverer.

protected Type getDiscoveredReturningGenericType ()

protected Class getDiscoveredReturningType ()

protected Class getDiscoveredThrowingType ()

protected JoinPoint getJoinPoint ()

Overridden in around advice to return proceeding join point.

protected JoinPointMatch getJoinPointMatch ()

Get the current join point match at the join point we are being dispatched on.

protected JoinPointMatch getJoinPointMatch (ProxyMethodInvocation pmi)

protected Object invokeAdviceMethod (JoinPointMatch jpMatch, Object returnValue, Throwable ex)

Invoke the advice method.

Parameters
jpMatch the JoinPointMatch that matched this execution join point
returnValue the return value from the method execution (may be null)
ex the exception thrown by the method execution (may be null)
Returns
  • the invocation result
Throws
Throwable in case of invocation failure

protected Object invokeAdviceMethod (JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable t)

Throws
Throwable

protected Object invokeAdviceMethodWithGivenArgs (Object[] args)

Throws
Throwable

protected void setReturningNameNoCheck (String name)

We need to hold the returning name at this level for argument binding calculations, this method allows the afterReturning advice subclass to set the name.

protected void setThrowingNameNoCheck (String name)

We need to hold the throwing name at this level for argument binding calculations, this method allows the afterThrowing advice subclass to set the name.

protected boolean supportsProceedingJoinPoint ()