类 AbstractAspectJAdvice
- 所有已实现的接口:
AspectJPrecedenceInformation,infra.core.Ordered,Serializable,Advice
- 直接已知子类:
AspectJAfterAdvice,AspectJAfterReturningAdvice,AspectJAfterThrowingAdvice,AspectJAroundAdvice,AspectJMethodBeforeAdvice
Advice classes
wrapping an AspectJ aspect or an AspectJ-annotated advice method.- 从以下版本开始:
- 4.0
- 作者:
- Rod Johnson, Adrian Colyer, Juergen Hoeller, Ramnivas Laddad, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明private static classMethodMatcher that excludes the specified advice method. -
字段概要
字段修饰符和类型字段说明private String[]This will be non-null if the creator of this advice object knows the argument names and sets them explicitly.private booleanprivate final AspectInstanceFactoryprotected Methodprivate StringThe 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 intThe order of declaration of this advice within the aspect.private final Class<?>private Typeprivate Class<?>private Class<?>protected static final StringKey used in ReflectiveMethodInvocation userAttributes map for the current joinpoint.private intIndex for thisJoinPoint argument (currently only supported at index 0 if present at all).private intIndex for thisJoinPointStaticPart argument (currently only supported at index 0 if present at all).private final Stringprivate final Class<?>[]private final AspectJExpressionPointcutprivate StringNon-null if after returning advice binds the return value.private StringNon-null if after throwing advice binds the thrown value.从接口继承的字段 infra.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器构造器说明AbstractAspectJAdvice(Method aspectJAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aspectInstanceFactory) Create a new AbstractAspectJAdvice for the given advice method. -
方法概要
修饰符和类型方法说明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.private voidbindArgumentsByName(int numArgumentsExpectingToBind) private voidbindExplicitArguments(int numArgumentsLeftToBind) final PointcutBuild a 'safe' pointcut that excludes the AspectJ advice method itself.final voidDo 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 voidconfigurePointcutParameters(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 infra.core.ParameterNameDiscovererCreate a ParameterNameDiscoverer to be used for argument binding.static org.aspectj.lang.JoinPointLazily instantiate joinpoint for the current invocation.final ClassLoaderReturn the ClassLoader for aspect instances.final AspectInstanceFactoryReturn the factory for aspect instances.final MethodReturn the AspectJ-style advice method.Return the name of the aspect (bean) in which the advice was declared.intReturn the declaration order of the advice member within the aspect.protected Typeprotected Class<?>protected Class<?>protected org.aspectj.lang.JoinPointOverridden in around advice to return proceeding join point.protected org.aspectj.weaver.tools.JoinPointMatchGet the current join point match at the join point we are being dispatched on.protected org.aspectj.weaver.tools.JoinPointMatchintgetOrder()Return the AspectJ expression pointcut.protected ObjectinvokeAdviceMethod(org.aspectj.lang.JoinPoint jp, org.aspectj.weaver.tools.JoinPointMatch jpMatch, Object returnValue, Throwable t) protected ObjectinvokeAdviceMethod(org.aspectj.weaver.tools.JoinPointMatch jpMatch, Object returnValue, Throwable ex) Invoke the advice method.protected Objectprivate static booleanisVariableName(String name) private booleanmaybeBindJoinPoint(Class<?> candidateParameterType) private booleanmaybeBindJoinPointStaticPart(Class<?> candidateParameterType) private booleanmaybeBindProceedingJoinPoint(Class<?> candidateParameterType) private voidreadObject(ObjectInputStream inputStream) voidsetArgumentNames(String argNames) Set by creator of this advice object if the argument names are known.voidsetArgumentNamesFromStringArray(String... args) Set by the creator of this advice object if the argument names are known.voidsetAspectName(String name) Set the name of the aspect (bean) in which the advice was declared.voidsetDeclarationOrder(int order) Set the declaration order of this advice within the aspect.voidsetReturningName(String name) protected voidWe need to hold the returning name at this level for argument binding calculations, this method allows the afterReturning advice subclass to set the name.voidsetThrowingName(String name) protected voidsetThrowingNameNoCheck(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 booleantoString()从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait从接口继承的方法 infra.aop.aspectj.AspectJPrecedenceInformation
isAfterAdvice, isBeforeAdvice
-
字段详细资料
-
JOIN_POINT_KEY
Key used in ReflectiveMethodInvocation userAttributes map for the current joinpoint. -
declaringClass
-
methodName
-
parameterTypes
-
aspectJAdviceMethod
-
pointcut
-
aspectInstanceFactory
-
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). -
declarationOrder
private int declarationOrderThe order of declaration of this advice within the aspect. -
argumentNames
This will be non-null if the creator of this advice object knows the argument names and sets them explicitly. -
throwingName
Non-null if after throwing advice binds the thrown value. -
returningName
Non-null if after returning advice binds the return value. -
discoveredReturningType
-
discoveredThrowingType
-
joinPointArgumentIndex
private int joinPointArgumentIndexIndex for thisJoinPoint argument (currently only supported at index 0 if present at all). -
joinPointStaticPartArgumentIndex
private int joinPointStaticPartArgumentIndexIndex for thisJoinPointStaticPart argument (currently only supported at index 0 if present at all). -
argumentBindings
-
argumentsIntrospected
private boolean argumentsIntrospected -
discoveredReturningGenericType
-
-
构造器详细资料
-
AbstractAspectJAdvice
public AbstractAspectJAdvice(Method aspectJAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aspectInstanceFactory) Create a new AbstractAspectJAdvice for the given advice method.- 参数:
aspectJAdviceMethod- the AspectJ-style advice methodpointcut- the AspectJ expression pointcutaspectInstanceFactory- the factory for aspect instances
-
-
方法详细资料
-
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).
- 返回:
- current AspectJ joinpoint, or through an exception if we're not in a Framework AOP invocation.
-
getAspectJAdviceMethod
Return the AspectJ-style advice method. -
getPointcut
Return the AspectJ expression pointcut. -
buildSafePointcut
Build a 'safe' pointcut that excludes the AspectJ advice method itself.- 返回:
- a composable pointcut that builds on the original AspectJ expression pointcut
- 另请参阅:
-
getAspectInstanceFactory
Return the factory for aspect instances. -
getAspectClassLoader
Return the ClassLoader for aspect instances. -
getOrder
public int getOrder()- 指定者:
getOrder在接口中infra.core.Ordered
-
setAspectName
Set the name of the aspect (bean) in which the advice was declared. -
getAspectName
从接口复制的说明:AspectJPrecedenceInformationReturn the name of the aspect (bean) in which the advice was declared.- 指定者:
getAspectName在接口中AspectJPrecedenceInformation
-
setDeclarationOrder
public void setDeclarationOrder(int order) Set the declaration order of this advice within the aspect. -
getDeclarationOrder
public int getDeclarationOrder()从接口复制的说明:AspectJPrecedenceInformationReturn the declaration order of the advice member within the aspect. -
setArgumentNames
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.
- 参数:
argNames- comma delimited list of arg names
-
setArgumentNamesFromStringArray
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.
- 参数:
args- list of argument names
-
setReturningName
-
setReturningNameNoCheck
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
-
getDiscoveredReturningGenericType
-
setThrowingName
-
setThrowingNameNoCheck
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
-
isVariableName
-
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.StaticPartthen we pass aJoinPoint.StaticPartin 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.
-
maybeBindJoinPoint
-
maybeBindProceedingJoinPoint
-
supportsProceedingJoinPoint
protected boolean supportsProceedingJoinPoint() -
maybeBindJoinPointStaticPart
-
bindArgumentsByName
private void bindArgumentsByName(int numArgumentsExpectingToBind) -
createParameterNameDiscoverer
protected infra.core.ParameterNameDiscoverer createParameterNameDiscoverer()Create a ParameterNameDiscoverer to be used for argument binding.The default implementation creates a
DefaultParameterNameDiscovererand adds a specifically configuredAspectJAdviceParameterNameDiscoverer. -
bindExplicitArguments
private void bindExplicitArguments(int numArgumentsLeftToBind) -
configurePointcutParameters
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. -
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.- 参数:
jp- the current JoinPointjpMatch- the join point match that matched this execution join pointreturnValue- the return value from the method execution (may be null)ex- the exception thrown by the method execution (may be null)- 返回:
- the empty array if there are no arguments
-
invokeAdviceMethod
protected Object invokeAdviceMethod(@Nullable org.aspectj.weaver.tools.JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) throws Throwable Invoke the advice method.- 参数:
jpMatch- the JoinPointMatch that matched this execution join pointreturnValue- the return value from the method execution (may be null)ex- the exception thrown by the method execution (may be null)- 返回:
- the invocation result
- 抛出:
Throwable- in case of invocation failure
-
invokeAdviceMethod
protected Object invokeAdviceMethod(org.aspectj.lang.JoinPoint jp, @Nullable org.aspectj.weaver.tools.JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable t) throws Throwable - 抛出:
Throwable
-
invokeAdviceMethodWithGivenArgs
- 抛出:
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
-
readObject
-