Package org.springframework.aop.aspectj

# Class AbstractAspectJAdvice

java.lang.Object
org.springframework.aop.aspectj.AbstractAspectJAdvice

All Implemented Interfaces:
  `Serializable`, `Advice`, `AspectJPrecedenceInformation`, `org.springframework.core.Ordered`

Direct Known Subclasses:
  `AspectJAfterAdvice`, `AspectJAfterReturningAdvice`, `AspectJAfterThrowingAdvice`, `AspectJAroundAdvice`, `AspectJMethodBeforeAdvice`

public abstract class AbstractAspectJAdvice extends Object implements Advice, AspectJPrecedenceInformation, Serializable
Base class for AOP Alliance `Advice` classes wrapping an AspectJ aspect or an AspectJ-annotated advice method.

Since:
  2.0
Author:
  Rod Johnson, Adrian Colyer, Juergen Hoeller, Ramnivas Laddad
See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Method`
`aspectJAdviceMethod`
`protected static final String`
`JOIN_POINT_KEY`
Key used in ReflectiveMethodInvocation userAttributes map for the current joinpoint.

### Fields inherited from interface org.springframework.core.Ordered

`HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

## Constructor Summary

Constructors
Constructor
Description
`AbstractAspectJAdvice(Method aspectJAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aspectInstanceFactory)`
Create a new AbstractAspectJAdvice for the given advice method.

## Method Summary

Modifier and Type
Method
Description
`protected Object[]`
`argBinding(org.aspectj.lang.JoinPoint jp, org.aspectj.weaver.tools.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.
`final Pointcut`
`buildSafePointcut()`
Build a 'safe' pointcut that excludes the AspectJ advice method itself.
`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.
`protected org.springframework.core.ParameterNameDiscoverer`
`createParameterNameDiscoverer()`
Create a ParameterNameDiscoverer to be used for argument binding.
`static org.aspectj.lang.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()`
Return the name of the aspect (bean) in which the advice was declared.
`int`
`getDeclarationOrder()`
Return the declaration order of the advice member within the aspect.
`protected Type`
`getDiscoveredReturningGenericType()`
`protected Class<?>`
`getDiscoveredReturningType()`
`protected Class<?>`
`getDiscoveredThrowingType()`
`protected org.aspectj.lang.JoinPoint`
`getJoinPoint()`
Overridden in around advice to return proceeding join point.
`protected org.aspectj.weaver.tools.JoinPointMatch`
`getJoinPointMatch()`
Get the current join point match at the join point we are being dispatched on.
`protected org.aspectj.weaver.tools.JoinPointMatch`
`getJoinPointMatch(ProxyMethodInvocation pmi)`
`int`
`getOrder()`
`final AspectJExpressionPointcut`
`getPointcut()`
Return the AspectJ expression pointcut.
`protected Object`
`invokeAdviceMethod(org.aspectj.lang.JoinPoint jp, org.aspectj.weaver.tools.JoinPointMatch jpMatch, Object returnValue, Throwable t)`
`protected Object`
`invokeAdviceMethod(org.aspectj.weaver.tools.JoinPointMatch jpMatch, Object returnValue, Throwable ex)`
Invoke the advice method.
`protected Object`
`invokeAdviceMethodWithGivenArgs(Object[] args)`
`void`
`setArgumentNames(String argumentNames)`
Set by the creator of this advice object if the argument names are known.
`void`
`setArgumentNamesFromStringArray(String... argumentNames)`
Set by the creator of this advice object if the argument names are known.
`void`
`setAspectName(String name)`
Set the name of the aspect (bean) in which the advice was declared.
`void`
`setDeclarationOrder(int order)`
Set the declaration order of this advice within the aspect.
`void`
`setReturningName(String name)`
`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.
`void`
`setThrowingName(String 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()`
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.aop.aspectj.AspectJPrecedenceInformation

`isAfterAdvice, isBeforeAdvice`

## Field Details

### JOIN_POINT_KEY

protected static final String JOIN_POINT_KEY
Key used in ReflectiveMethodInvocation userAttributes map for the current joinpoint.

### aspectJAdviceMethod

protected transient Method aspectJAdviceMethod

## Constructor Details

### AbstractAspectJAdvice

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

## Method Details

### currentJoinPoint

public static org.aspectj.lang.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.

### getAspectJAdviceMethod

public final Method getAspectJAdviceMethod()
Return the AspectJ-style advice method.

### getPointcut

public final AspectJExpressionPointcut getPointcut()
Return the AspectJ expression pointcut.

### buildSafePointcut

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:
  - `getPointcut()`

### getAspectInstanceFactory

public final AspectInstanceFactory getAspectInstanceFactory()
Return the factory for aspect instances.

### getAspectClassLoader

@Nullable public final ClassLoader getAspectClassLoader()
Return the ClassLoader for aspect instances.

### getOrder

public int getOrder()

Specified by:
  `getOrder` in interface `org.springframework.core.Ordered`

### setAspectName

public void setAspectName(String name)
Set the name of the aspect (bean) in which the advice was declared.

### getAspectName

public String getAspectName()
Description copied from interface: `AspectJPrecedenceInformation`
Return the name of the aspect (bean) in which the advice was declared.

Specified by:
  `getAspectName` in interface `AspectJPrecedenceInformation`

### setDeclarationOrder

public void setDeclarationOrder(int order)
Set the declaration order of this advice within the aspect.

### getDeclarationOrder

public int getDeclarationOrder()
Description copied from interface: `AspectJPrecedenceInformation`
Return the declaration order of the advice member within the aspect.

Specified by:
  `getDeclarationOrder` in interface `AspectJPrecedenceInformation`

### setArgumentNames

public void setArgumentNames(String argumentNames)
Set by the 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:
  `argumentNames` - comma delimited list of argument names

### setArgumentNamesFromStringArray

public void setArgumentNamesFromStringArray(String... argumentNames)
Set by the 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:
  `argumentNames` - list of argument names

### setReturningName

public void setReturningName(String name)

### setReturningNameNoCheck

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.

### getDiscoveredReturningType

protected Class<?> getDiscoveredReturningType()

### getDiscoveredReturningGenericType

@Nullable protected Type getDiscoveredReturningGenericType()

### setThrowingName

public void setThrowingName(String name)

### setThrowingNameNoCheck

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.

### getDiscoveredThrowingType

protected Class<?> getDiscoveredThrowingType()

### calculateArgumentBindings

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

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.

### supportsProceedingJoinPoint

protected boolean supportsProceedingJoinPoint()

### createParameterNameDiscoverer

protected org.springframework.core.ParameterNameDiscoverer createParameterNameDiscoverer()
Create a ParameterNameDiscoverer to be used for argument binding.

The default implementation creates a `DefaultParameterNameDiscoverer` and adds a specifically configured `AspectJAdviceParameterNameDiscoverer`.

### argBinding

protected Object[] argBinding(org.aspectj.lang.JoinPoint jp, @Nullable org.aspectj.weaver.tools.JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable 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

### invokeAdviceMethod

@Nullable protected Object invokeAdviceMethod(@Nullable org.aspectj.weaver.tools.JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) throws Throwable
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

### invokeAdviceMethod

@Nullable protected Object invokeAdviceMethod(org.aspectj.lang.JoinPoint jp, @Nullable org.aspectj.weaver.tools.JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable t) throws Throwable

Throws:
  `Throwable`

### invokeAdviceMethodWithGivenArgs

@Nullable protected Object invokeAdviceMethodWithGivenArgs(Object[] args) throws Throwable

Throws:
  `Throwable`

### getJoinPoint

protected org.aspectj.lang.JoinPoint getJoinPoint()
Overridden in around advice to return proceeding join point.

### getJoinPointMatch

@Nullable protected org.aspectj.weaver.tools.JoinPointMatch getJoinPointMatch()
Get the current join point match at the join point we are being dispatched on.

### getJoinPointMatch

@Nullable protected org.aspectj.weaver.tools.JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi)

### toString

public String toString()

Overrides:
  `toString` in class `Object`