The Spring Framework

org.springframework.aop.aspectj
Class AbstractAspectJAdvice

java.lang.Object
  extended by org.springframework.aop.aspectj.AbstractAspectJAdvice
All Implemented Interfaces:
Advice, AspectJPrecedenceInformation, InitializingBean, Ordered
Direct Known Subclasses:
AspectJAfterAdvice, AspectJAfterReturningAdvice, AspectJAfterThrowingAdvice, AspectJAroundAdvice, AspectJMethodBeforeAdvice

public abstract class AbstractAspectJAdvice
extends Object
implements Advice, AspectJPrecedenceInformation, InitializingBean

Superclass for Spring Advices wrapping an AspectJ aspect or annotated advice method.

Since:
2.0
Author:
Rod Johnson, Adrian Colyer, Juergen Hoeller

Field Summary
protected  Method aspectJAdviceMethod
           
protected static String JOIN_POINT_KEY
          Key used in ReflectiveMethodInvocation userAtributes map for the current joinpoint.
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
AbstractAspectJAdvice(Method aspectJAdviceMethod, AspectJExpressionPointcut pointcutExpression, AspectInstanceFactory aif)
           
 
Method Summary
 void afterPropertiesSet()
          Argument names have to be discovered and set on the associated pointcut expression, and we also calculate argument bindings for advice invocation so that actual dispatch can be as fast as possible.
protected  Object[] argBinding(org.aspectj.lang.JoinPoint jp, org.aspectj.weaver.tools.JoinPointMatch jpMatch, Object returnValue, Throwable t)
          Take the arguments at the method execution join point and output a set of arguments to the advice method
static org.aspectj.lang.JoinPoint currentJoinPoint()
          Lazily instantiate joinpoint for the current invocation.
 AspectInstanceFactory getAspectInstanceFactory()
           
 Method getAspectJAdviceMethod()
           
 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.
protected  Class getDiscoveredReturningType()
           
protected  Class getDiscoveredThrowingType()
           
protected  org.aspectj.lang.JoinPoint getJoinPoint()
           
protected  org.aspectj.weaver.tools.JoinPointMatch getJoinPointMatch()
           
protected  org.aspectj.weaver.tools.JoinPointMatch getJoinPointMatch(ReflectiveMethodInvocation rmi)
           
 int getOrder()
          Return the order value of this object, with a higher value meaning greater in terms of sorting.
 AspectJExpressionPointcut getPointcut()
           
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 t)
          Invoke the advice method.
protected  Object invokeAdviceMethodWithGivenArgs(Object[] args)
           
 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)
           
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.
 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 Detail

JOIN_POINT_KEY

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


aspectJAdviceMethod

protected final Method aspectJAdviceMethod
Constructor Detail

AbstractAspectJAdvice

public AbstractAspectJAdvice(Method aspectJAdviceMethod,
                             AspectJExpressionPointcut pointcutExpression,
                             AspectInstanceFactory aif)
Method Detail

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

getPointcut

public final AspectJExpressionPointcut getPointcut()

getAspectInstanceFactory

public final AspectInstanceFactory getAspectInstanceFactory()

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 or 1, with Ordered.LOWEST_PRECEDENCE indicating greatest. Same order values will result in arbitrary positions for the affected objects.

Higher value can be interpreted as lower priority, consequently the first object has highest priority (somewhat analogous to Servlet "load-on-startup" values).

Note that order values below 0 are reserved for framework purposes. Application-specified values should always be 0 or greater, with only framework components (internal or third-party) supposed to use lower values.

Specified by:
getOrder in interface Ordered
Returns:
the order value
See Also:
Ordered.LOWEST_PRECEDENCE

setAspectName

public void setAspectName(String name)

getAspectName

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

Specified by:
getAspectName in interface AspectJPrecedenceInformation

setDeclarationOrder

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


getDeclarationOrder

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

Specified by:
getDeclarationOrder in interface AspectJPrecedenceInformation

setArgumentNames

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

setArgumentNamesFromStringArray

public void setArgumentNamesFromStringArray(String[] args)

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

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

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Argument names have to be discovered and set on the associated pointcut expression, and we also calculate argument bindings for advice invocation so that actual dispatch can be as fast as possible.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.

argBinding

protected Object[] argBinding(org.aspectj.lang.JoinPoint jp,
                              org.aspectj.weaver.tools.JoinPointMatch jpMatch,
                              Object returnValue,
                              Throwable t)
Take the arguments at the method execution join point and output a set of arguments to the advice method

Parameters:
jpMatch - the join point match that matched this execution join point
returnValue - the return value from the method execution (may be null)
t - the exception thrown by the method execution (may be null)
Returns:
the empty array if there are no arguments

getJoinPoint

protected org.aspectj.lang.JoinPoint getJoinPoint()

getJoinPointMatch

protected org.aspectj.weaver.tools.JoinPointMatch getJoinPointMatch()

getJoinPointMatch

protected org.aspectj.weaver.tools.JoinPointMatch getJoinPointMatch(ReflectiveMethodInvocation rmi)

invokeAdviceMethod

protected Object invokeAdviceMethod(org.aspectj.weaver.tools.JoinPointMatch jpMatch,
                                    Object returnValue,
                                    Throwable t)
                             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)
t - the exception thrown by the method execution (may be null)
Throws:
Throwable

invokeAdviceMethod

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

invokeAdviceMethodWithGivenArgs

protected Object invokeAdviceMethodWithGivenArgs(Object[] args)
                                          throws Throwable
Throws:
Throwable

toString

public String toString()
Overrides:
toString in class Object

The Spring Framework

Copyright © 2002-2006 The Spring Framework.