Top Description Inners Fields Constructors Methods
org.springframework.aop.aspectj

public abstract Class AbstractAspectJAdvice

extends Object
implements Advice, AspectJPrecedenceInformation, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.springframework.aop.aspectj.AspectJPrecedenceInformation, org.springframework.core.Ordered, org.aopalliance.aop.Advice
Known Direct Subclasses
org.springframework.aop.aspectj.AspectJAfterAdvice, org.springframework.aop.aspectj.AspectJAfterReturningAdvice, org.springframework.aop.aspectj.AspectJAfterThrowingAdvice, org.springframework.aop.aspectj.AspectJAroundAdvice, org.springframework.aop.aspectj.AspectJMethodBeforeAdvice
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, .ObjectInputStream, .Serializable, java.lang.reflect.InvocationTargetException, .Method, .Type, java.util.HashMap, .Map, org.aopalliance.aop.Advice, org.aopalliance.intercept.MethodInvocation, org.aspectj.lang.JoinPoint, .ProceedingJoinPoint, org.aspectj.weaver.tools.JoinPointMatch, .PointcutParameter, org.springframework.aop.AopInvocationException, .MethodMatcher, .Pointcut, .ProxyMethodInvocation, org.springframework.aop.interceptor.ExposeInvocationInterceptor, org.springframework.aop.support.ComposablePointcut, .MethodMatchers, .StaticMethodMatcher, org.springframework.core.DefaultParameterNameDiscoverer, .ParameterNameDiscoverer, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .CollectionUtils, .ReflectionUtils, .StringUtils

Base class for AOP Alliance org.aopalliance.aop.Advice classes wrapping an AspectJ aspect or an AspectJ-annotated advice method.
Authors
Rod Johnson, Adrian Colyer, Juergen Hoeller, Ramnivas Laddad
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AbstractAspectJAdvice.AdviceExcludingMethodMatcher

MethodMatcher that excludes the specified advice method.

Field Summary

Modifier and TypeField and Description
private Map<String, Integer>
private String[]
argumentNames

This will be non-null if the creator of this advice object knows the argument names and sets them explicitly.

private boolean
private final AspectInstanceFactory
protected transient Method
private String
aspectName

The name of the aspect (ref bean) in which this advice was defined (used when determining advice precedence so that we can determine whether two pieces of advice come from the same aspect).

private int
declarationOrder

The order of declaration of this advice within the aspect.

private final Class<?>
private Type
private Class<?>
private Class<?>
protected static final String
JOIN_POINT_KEY

Key used in ReflectiveMethodInvocation userAttributes map for the current joinpoint.

private int
joinPointArgumentIndex

Index for thisJoinPoint argument (currently only supported at index 0 if present at all).

private int
joinPointStaticPartArgumentIndex

Index for thisJoinPointStaticPart argument (currently only supported at index 0 if present at all).

private final String
private final Class<?>[]
private final AspectJExpressionPointcut
private String
returningName

Non-null if after returning advice binds the return value.

private String
throwingName

Non-null if after throwing advice binds the thrown value.

Constructor Summary

AccessConstructor and Description
public
AbstractAspectJAdvice(Method
the AspectJ-style advice method
aspectJAdviceMethod
,
AspectJExpressionPointcut
the AspectJ expression pointcut
pointcut
,
AspectInstanceFactory
the factory for aspect instances
aspectInstanceFactory
)

Create a new AbstractAspectJAdvice for the given advice method.

Method Summary

Modifier and TypeMethod and Description
protected Object[]

Returns:

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

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

private void
bindArgumentsByName(int numArgumentsExpectingToBind)

private void
bindExplicitArguments(int numArgumentsLeftToBind)

public final Pointcut

Returns:

a composable pointcut that builds on the original AspectJ expression pointcut
buildSafePointcut
()

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

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.

private void
configurePointcutParameters(String[] argumentNames, int argumentIndexOffset)

All parameters from argumentIndexOffset onwards are candidates for pointcut parameters - but returning and throwing vars are handled differently and must be removed from the list if present.

protected ParameterNameDiscoverer
createParameterNameDiscoverer()

Create a ParameterNameDiscoverer to be used for argument binding.

public static JoinPoint

Returns:

current AspectJ joinpoint, or through an exception if we're not in a Spring AOP invocation.
currentJoinPoint
()

Lazily instantiate joinpoint for the current 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()

Implements org.springframework.aop.aspectj.AspectJPrecedenceInformation.getAspectName.

Return the name of the aspect (bean) in which the advice was declared.
public int
getDeclarationOrder()

Implements org.springframework.aop.aspectj.AspectJPrecedenceInformation.getDeclarationOrder.

Return the declaration order of the advice member within the aspect.
protected Type
protected Class<?>
protected Class<?>
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
public int
getOrder()

Implements org.springframework.core.Ordered.getOrder.

Get the order value of this object.
public final AspectJExpressionPointcut
getPointcut()

Return the AspectJ expression pointcut.

protected Object

Returns:

the invocation result
invokeAdviceMethod
(JoinPointMatch
the JoinPointMatch that matched this execution join point
jpMatch
,
Object
the return value from the method execution (may be null)
returnValue
,
Throwable
the exception thrown by the method execution (may be null)
ex
)

Invoke the advice method.

protected Object
protected Object
private static boolean
private boolean
maybeBindJoinPoint(Class<?> candidateParameterType)

private boolean
maybeBindJoinPointStaticPart(Class<?> candidateParameterType)

private boolean
maybeBindProceedingJoinPoint(Class<?> candidateParameterType)

private void
public void
setArgumentNames(String
comma delimited list of argument names
argumentNames
)

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

public void
setArgumentNamesFromStringArray(String...
list of argument names
argumentNames
)

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

public void
setAspectName(String name)

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

public void
setDeclarationOrder(int order)

Set the declaration order of this advice within the aspect.

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

public void
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
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

argumentBindingsback to summary
private Map<String, Integer> argumentBindings
Annotations
@Nullable
argumentNamesback to summary
private String[] argumentNames

This will be non-null if the creator of this advice object knows the argument names and sets them explicitly.

Annotations
@Nullable
argumentsIntrospectedback to summary
private boolean argumentsIntrospected
aspectInstanceFactoryback to summary
private final AspectInstanceFactory aspectInstanceFactory
aspectJAdviceMethodback to summary
protected transient Method aspectJAdviceMethod
aspectNameback to summary
private String aspectName

The name of the aspect (ref bean) in which this advice was defined (used when determining advice precedence so that we can determine whether two pieces of advice come from the same aspect).

declarationOrderback to summary
private int declarationOrder

The order of declaration of this advice within the aspect.

declaringClassback to summary
private final Class<?> declaringClass
discoveredReturningGenericTypeback to summary
private Type discoveredReturningGenericType
Annotations
@Nullable
discoveredReturningTypeback to summary
private Class<?> discoveredReturningType
discoveredThrowingTypeback to summary
private Class<?> discoveredThrowingType
JOIN_POINT_KEYback to summary
protected static final String JOIN_POINT_KEY

Key used in ReflectiveMethodInvocation userAttributes map for the current joinpoint.

joinPointArgumentIndexback to summary
private int joinPointArgumentIndex

Index for thisJoinPoint argument (currently only supported at index 0 if present at all).

joinPointStaticPartArgumentIndexback to summary
private int joinPointStaticPartArgumentIndex

Index for thisJoinPointStaticPart argument (currently only supported at index 0 if present at all).

methodNameback to summary
private final String methodName
parameterTypesback to summary
private final Class<?>[] parameterTypes
pointcutback to summary
private final AspectJExpressionPointcut pointcut
returningNameback to summary
private String returningName

Non-null if after returning advice binds the return value.

Annotations
@Nullable
throwingNameback to summary
private String throwingName

Non-null if after throwing advice binds the thrown value.

Annotations
@Nullable

Constructor Detail

AbstractAspectJAdviceback to summary
public AbstractAspectJAdvice(Method aspectJAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aspectInstanceFactory)

Create a new AbstractAspectJAdvice for the given advice method.

Parameters
aspectJAdviceMethod:Method

the AspectJ-style advice method

pointcut:AspectJExpressionPointcut

the AspectJ expression pointcut

aspectInstanceFactory:AspectInstanceFactory

the factory for aspect instances

Method Detail

argBindingback to summary
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:JoinPoint

the current JoinPoint

jpMatch:JoinPointMatch

the join point match that matched this execution join point

returnValue:Object

the return value from the method execution (may be null)

ex:Throwable

the exception thrown by the method execution (may be null)

Returns:Object[]

the empty array if there are no arguments

bindArgumentsByNameback to summary
private void bindArgumentsByName(int numArgumentsExpectingToBind)
bindExplicitArgumentsback to summary
private void bindExplicitArguments(int numArgumentsLeftToBind)
buildSafePointcutback to summary
public final Pointcut buildSafePointcut()

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

Returns:Pointcut

a composable pointcut that builds on the original AspectJ expression pointcut

See Also
getPointcut()
calculateArgumentBindingsback to summary
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.

configurePointcutParametersback to summary
private void configurePointcutParameters(String[] argumentNames, int argumentIndexOffset)

All parameters from argumentIndexOffset onwards are candidates for pointcut parameters - but returning and throwing vars are handled differently and must be removed from the list if present.

createParameterNameDiscovererback to summary
protected ParameterNameDiscoverer createParameterNameDiscoverer()

Create a ParameterNameDiscoverer to be used for argument binding.

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

currentJoinPointback to summary
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:JoinPoint

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

getAspectClassLoaderback to summary
public final ClassLoader getAspectClassLoader()

Return the ClassLoader for aspect instances.

Annotations
@Nullable
getAspectInstanceFactoryback to summary
public final AspectInstanceFactory getAspectInstanceFactory()

Return the factory for aspect instances.

getAspectJAdviceMethodback to summary
public final Method getAspectJAdviceMethod()

Return the AspectJ-style advice method.

getAspectNameback to summary
public String getAspectName()

Implements org.springframework.aop.aspectj.AspectJPrecedenceInformation.getAspectName.

Doc from org.springframework.aop.aspectj.AspectJPrecedenceInformation.getAspectName.

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

Annotations
@Override
getDeclarationOrderback to summary
public int getDeclarationOrder()

Implements org.springframework.aop.aspectj.AspectJPrecedenceInformation.getDeclarationOrder.

Doc from org.springframework.aop.aspectj.AspectJPrecedenceInformation.getDeclarationOrder.

Return the declaration order of the advice member within the aspect.

Annotations
@Override
getDiscoveredReturningGenericTypeback to summary
protected Type getDiscoveredReturningGenericType()
Annotations
@Nullable
getDiscoveredReturningTypeback to summary
protected Class<?> getDiscoveredReturningType()
getDiscoveredThrowingTypeback to summary
protected Class<?> getDiscoveredThrowingType()
getJoinPointback to summary
protected JoinPoint getJoinPoint()

Overridden in around advice to return proceeding join point.

getJoinPointMatchback to summary
protected JoinPointMatch getJoinPointMatch()

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

Annotations
@Nullable
getJoinPointMatchback to summary
protected JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi)
Annotations
@Nullable
getOrderback to summary
public int getOrder()

Implements org.springframework.core.Ordered.getOrder.

Doc from org.springframework.core.Ordered.getOrder.

Get the order value of this object.

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

Same order values will result in arbitrary sort positions for the affected objects.

Returns:int

the order value

Annotations
@Override
getPointcutback to summary
public final AspectJExpressionPointcut getPointcut()

Return the AspectJ expression pointcut.

invokeAdviceMethodback to summary
protected Object invokeAdviceMethod(JoinPointMatch jpMatch, Object returnValue, Throwable ex) throws Throwable

Invoke the advice method.

Parameters
jpMatch:JoinPointMatch

the JoinPointMatch that matched this execution join point

returnValue:Object

the return value from the method execution (may be null)

ex:Throwable

the exception thrown by the method execution (may be null)

Returns:Object

the invocation result

Exceptions
Throwable:
in case of invocation failure
invokeAdviceMethodback to summary
protected Object invokeAdviceMethod(JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable t) throws Throwable
invokeAdviceMethodWithGivenArgsback to summary
protected Object invokeAdviceMethodWithGivenArgs(Object[] args) throws Throwable
isVariableNameback to summary
private static boolean isVariableName(String name)
maybeBindJoinPointback to summary
private boolean maybeBindJoinPoint(Class<?> candidateParameterType)
maybeBindJoinPointStaticPartback to summary
private boolean maybeBindJoinPointStaticPart(Class<?> candidateParameterType)
maybeBindProceedingJoinPointback to summary
private boolean maybeBindProceedingJoinPoint(Class<?> candidateParameterType)
readObjectback to summary
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException
setArgumentNamesback to summary
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:String

comma delimited list of argument names

setArgumentNamesFromStringArrayback to summary
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:String[]

list of argument names

setAspectNameback to summary
public void setAspectName(String name)

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

setDeclarationOrderback to summary
public void setDeclarationOrder(int order)

Set the declaration order of this advice within the aspect.

setReturningNameback to summary
public void setReturningName(String name)
setReturningNameNoCheckback to summary
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.

setThrowingNameback to summary
public void setThrowingName(String name)
setThrowingNameNoCheckback to summary
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.

supportsProceedingJoinPointback to summary
protected boolean supportsProceedingJoinPoint()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.springframework.aop.aspectj back to summary

private Class AbstractAspectJAdvice.AdviceExcludingMethodMatcher

extends StaticMethodMatcher
Class Inheritance

MethodMatcher that excludes the specified advice method.
See Also
AbstractAspectJAdvice#buildSafePointcut()

Field Summary

Modifier and TypeField and Description
private final Method

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
matches(Method
the candidate method
method
,
Class<?>
the target class
targetClass
)

Implements org.springframework.aop.MethodMatcher.matches.

Perform static checking to determine whether the given method matches.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.springframework.aop.support.StaticMethodMatcher:
isRuntimematches

Field Detail

adviceMethodback to summary
private final Method adviceMethod

Constructor Detail

AdviceExcludingMethodMatcherback to summary
public AdviceExcludingMethodMatcher(Method adviceMethod)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
matchesback to summary
public boolean matches(Method method, Class<?> targetClass)

Implements org.springframework.aop.MethodMatcher.matches.

Doc from org.springframework.aop.MethodMatcher.matches.

Perform static checking to determine whether the given method matches.

If this method returns false or if isRuntime() returns false, no runtime check (i.e. no matches(Method, Class, Object[]) call) will be made.

Parameters
method:Method

the candidate method

targetClass:Class<?>

the target class

Returns:boolean

whether this method matches statically

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override