public abstract class

AopUtils

extends Object
java.lang.Object
   ↳ org.springframework.aop.support.AopUtils

Class Overview

Utility methods for AOP support code. Mainly for internal use within Spring's AOP support.

See AopProxyUtils for a collection of framework-specific AOP utility methods which depend on internals of Spring's AOP framework implementation.

See Also

Summary

Public Constructors
AopUtils()
Public Methods
static boolean canApply(Advisor advisor, Class<?> targetClass, boolean hasIntroductions)
Can the given advisor apply at all on the given class?

This is an important test as it can be used to optimize out a advisor for a class.

static boolean canApply(Pointcut pc, Class<?> targetClass)
Can the given pointcut apply at all on the given class?

This is an important test as it can be used to optimize out a pointcut for a class.

static boolean canApply(Pointcut pc, Class<?> targetClass, boolean hasIntroductions)
Can the given pointcut apply at all on the given class?

This is an important test as it can be used to optimize out a pointcut for a class.

static boolean canApply(Advisor advisor, Class<?> targetClass)
Can the given advisor apply at all on the given class? This is an important test as it can be used to optimize out a advisor for a class.
static List<Advisor> findAdvisorsThatCanApply(List<Advisor> candidateAdvisors, Class<?> clazz)
Determine the sublist of the candidateAdvisors list that is applicable to the given class.
static Method getMostSpecificMethod(Method method, Class<?> targetClass)
Given a method, which may come from an interface, and a target class used in the current AOP invocation, find the corresponding target method if there is one.
static Class<?> getTargetClass(Object candidate)
Determine the target class of the given bean instance which might be an AOP proxy.
static Object invokeJoinpointUsingReflection(Object target, Method method, Object[] args)
Invoke the given target via reflection, as part of an AOP method invocation.
static boolean isAopProxy(Object object)
Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.
static boolean isCglibProxy(Object object)
Check whether the given object is a CGLIB proxy.
static boolean isCglibProxyClass(Class<?> clazz)
Check whether the specified class is a CGLIB-generated class.
static boolean isCglibProxyClassName(String className)
Check whether the specified class name is a CGLIB-generated class.
static boolean isEqualsMethod(Method method)
Determine whether the given method is an "equals" method.
static boolean isFinalizeMethod(Method method)
Determine whether the given method is a "finalize" method.
static boolean isHashCodeMethod(Method method)
Determine whether the given method is a "hashCode" method.
static boolean isJdkDynamicProxy(Object object)
Check whether the given object is a JDK dynamic proxy.
static boolean isToStringMethod(Method method)
Determine whether the given method is a "toString" method.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public AopUtils ()

Public Methods

public static boolean canApply (Advisor advisor, Class<?> targetClass, boolean hasIntroductions)

Can the given advisor apply at all on the given class?

This is an important test as it can be used to optimize out a advisor for a class. This version also takes into account introductions (for IntroductionAwareMethodMatchers).

Parameters
advisor the advisor to check
targetClass class we're testing
hasIntroductions whether or not the advisor chain for this bean includes any introductions
Returns
  • whether the pointcut can apply on any method

public static boolean canApply (Pointcut pc, Class<?> targetClass)

Can the given pointcut apply at all on the given class?

This is an important test as it can be used to optimize out a pointcut for a class.

Parameters
pc the static or dynamic pointcut to check
targetClass the class to test
Returns
  • whether the pointcut can apply on any method

public static boolean canApply (Pointcut pc, Class<?> targetClass, boolean hasIntroductions)

Can the given pointcut apply at all on the given class?

This is an important test as it can be used to optimize out a pointcut for a class.

Parameters
pc the static or dynamic pointcut to check
targetClass the class to test
hasIntroductions whether or not the advisor chain for this bean includes any introductions
Returns
  • whether the pointcut can apply on any method

public static boolean canApply (Advisor advisor, Class<?> targetClass)

Can the given advisor apply at all on the given class? This is an important test as it can be used to optimize out a advisor for a class.

Parameters
advisor the advisor to check
targetClass class we're testing
Returns
  • whether the pointcut can apply on any method

public static List<Advisor> findAdvisorsThatCanApply (List<Advisor> candidateAdvisors, Class<?> clazz)

Determine the sublist of the candidateAdvisors list that is applicable to the given class.

Parameters
candidateAdvisors the Advisors to evaluate
clazz the target class
Returns
  • sublist of Advisors that can apply to an object of the given class (may be the incoming List as-is)

public static Method getMostSpecificMethod (Method method, Class<?> targetClass)

Given a method, which may come from an interface, and a target class used in the current AOP invocation, find the corresponding target method if there is one. E.g. the method may be IFoo.bar() and the target class may be DefaultFoo. In this case, the method may be DefaultFoo.bar(). This enables attributes on that method to be found.

NOTE: In contrast to getMostSpecificMethod(Method, Class), this method resolves Java 5 bridge methods in order to retrieve attributes from the original method definition.

Parameters
method the method to be invoked, which may come from an interface
targetClass the target class for the current invocation. May be null or may not even implement the method.
Returns
  • the specific target method, or the original method if the targetClass doesn't implement it or is null

public static Class<?> getTargetClass (Object candidate)

Determine the target class of the given bean instance which might be an AOP proxy.

Returns the target class for an AOP proxy and the plain class else.

Parameters
candidate the instance to check (might be an AOP proxy)
Returns
  • the target class (or the plain class of the given object as fallback; never null)

public static Object invokeJoinpointUsingReflection (Object target, Method method, Object[] args)

Invoke the given target via reflection, as part of an AOP method invocation.

Parameters
target the target object
method the method to invoke
args the arguments for the method
Returns
  • the invocation result, if any
Throws
Throwable if thrown by the target method
AopInvocationException in case of a reflection error

public static boolean isAopProxy (Object object)

Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.

Parameters
object the object to check

public static boolean isCglibProxy (Object object)

Check whether the given object is a CGLIB proxy.

Parameters
object the object to check

public static boolean isCglibProxyClass (Class<?> clazz)

Check whether the specified class is a CGLIB-generated class.

Parameters
clazz the class to check

public static boolean isCglibProxyClassName (String className)

Check whether the specified class name is a CGLIB-generated class.

Parameters
className the class name to check

public static boolean isEqualsMethod (Method method)

Determine whether the given method is an "equals" method.

See Also

public static boolean isFinalizeMethod (Method method)

Determine whether the given method is a "finalize" method.

See Also

public static boolean isHashCodeMethod (Method method)

Determine whether the given method is a "hashCode" method.

See Also

public static boolean isJdkDynamicProxy (Object object)

Check whether the given object is a JDK dynamic proxy.

Parameters
object the object to check

public static boolean isToStringMethod (Method method)

Determine whether the given method is a "toString" method.

See Also