public abstract class AopUtils
extends java.lang.Object
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.
AopProxyUtils
Constructor and Description |
---|
AopUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canApply(Advisor advisor,
java.lang.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 boolean |
canApply(Advisor advisor,
java.lang.Class<?> targetClass,
boolean hasIntroductions)
Can the given advisor apply at all on the given class?
|
static boolean |
canApply(Pointcut pc,
java.lang.Class<?> targetClass)
Can the given pointcut apply at all on the given class?
|
static boolean |
canApply(Pointcut pc,
java.lang.Class<?> targetClass,
boolean hasIntroductions)
Can the given pointcut apply at all on the given class?
|
static java.util.List<Advisor> |
findAdvisorsThatCanApply(java.util.List<Advisor> candidateAdvisors,
java.lang.Class<?> clazz)
Determine the sublist of the
candidateAdvisors list
that is applicable to the given class. |
static java.lang.reflect.Method |
getMostSpecificMethod(java.lang.reflect.Method method,
java.lang.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 java.lang.Class<?> |
getTargetClass(java.lang.Object candidate)
Determine the target class of the given bean instance which might be an AOP proxy.
|
static java.lang.Object |
invokeJoinpointUsingReflection(java.lang.Object target,
java.lang.reflect.Method method,
java.lang.Object[] args)
Invoke the given target via reflection, as part of an AOP method invocation.
|
static boolean |
isAopProxy(java.lang.Object object)
Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.
|
static boolean |
isCglibProxy(java.lang.Object object)
Check whether the given object is a CGLIB proxy.
|
static boolean |
isEqualsMethod(java.lang.reflect.Method method)
Determine whether the given method is an "equals" method.
|
static boolean |
isFinalizeMethod(java.lang.reflect.Method method)
Determine whether the given method is a "finalize" method.
|
static boolean |
isHashCodeMethod(java.lang.reflect.Method method)
Determine whether the given method is a "hashCode" method.
|
static boolean |
isJdkDynamicProxy(java.lang.Object object)
Check whether the given object is a JDK dynamic proxy.
|
static boolean |
isToStringMethod(java.lang.reflect.Method method)
Determine whether the given method is a "toString" method.
|
static java.lang.reflect.Method |
selectInvocableMethod(java.lang.reflect.Method method,
java.lang.Class<?> targetType)
Select an invocable method on the target type: either the given method itself
if actually exposed on the target type, or otherwise a corresponding method
on one of the target type's interfaces or on the target type itself.
|
public static boolean isAopProxy(java.lang.Object object)
This method additionally checks if the given object is an instance
of SpringProxy
.
object
- the object to checkisJdkDynamicProxy(java.lang.Object)
,
isCglibProxy(java.lang.Object)
public static boolean isJdkDynamicProxy(java.lang.Object object)
This method goes beyond the implementation of
Proxy.isProxyClass(Class)
by additionally checking if the
given object is an instance of SpringProxy
.
object
- the object to checkProxy.isProxyClass(java.lang.Class<?>)
public static boolean isCglibProxy(java.lang.Object object)
This method goes beyond the implementation of
ClassUtils.isCglibProxy(Object)
by additionally checking if
the given object is an instance of SpringProxy
.
object
- the object to checkClassUtils.isCglibProxy(Object)
public static java.lang.Class<?> getTargetClass(java.lang.Object candidate)
Returns the target class for an AOP proxy or the plain class otherwise.
candidate
- the instance to check (might be an AOP proxy)null
)TargetClassAware.getTargetClass()
,
AopProxyUtils.ultimateTargetClass(Object)
public static java.lang.reflect.Method selectInvocableMethod(java.lang.reflect.Method method, java.lang.Class<?> targetType)
method
- the method to checktargetType
- the target type to search methods on (typically an AOP proxy)java.lang.IllegalStateException
- if the given method is not invocable on the given
target type (typically due to a proxy mismatch)MethodIntrospector.selectInvocableMethod(Method, Class)
public static boolean isEqualsMethod(java.lang.reflect.Method method)
Object.equals(java.lang.Object)
public static boolean isHashCodeMethod(java.lang.reflect.Method method)
Object.hashCode()
public static boolean isToStringMethod(java.lang.reflect.Method method)
Object.toString()
public static boolean isFinalizeMethod(java.lang.reflect.Method method)
Object.finalize()
public static java.lang.reflect.Method getMostSpecificMethod(java.lang.reflect.Method method, java.lang.Class<?> targetClass)
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 ClassUtils.getMostSpecificMethod(java.lang.reflect.Method, java.lang.Class<?>)
,
this method resolves Java 5 bridge methods in order to retrieve attributes
from the original method definition.
method
- the method to be invoked, which may come from an interfacetargetClass
- the target class for the current invocation.
May be null
or may not even implement the method.targetClass
doesn't implement it or is null
ClassUtils.getMostSpecificMethod(java.lang.reflect.Method, java.lang.Class<?>)
public static boolean canApply(Pointcut pc, java.lang.Class<?> targetClass)
This is an important test as it can be used to optimize out a pointcut for a class.
pc
- the static or dynamic pointcut to checktargetClass
- the class to testpublic static boolean canApply(Pointcut pc, java.lang.Class<?> targetClass, boolean hasIntroductions)
This is an important test as it can be used to optimize out a pointcut for a class.
pc
- the static or dynamic pointcut to checktargetClass
- the class to testhasIntroductions
- whether or not the advisor chain
for this bean includes any introductionspublic static boolean canApply(Advisor advisor, java.lang.Class<?> targetClass)
advisor
- the advisor to checktargetClass
- class we're testingpublic static boolean canApply(Advisor advisor, java.lang.Class<?> targetClass, boolean hasIntroductions)
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).
advisor
- the advisor to checktargetClass
- class we're testinghasIntroductions
- whether or not the advisor chain for this bean includes
any introductionspublic static java.util.List<Advisor> findAdvisorsThatCanApply(java.util.List<Advisor> candidateAdvisors, java.lang.Class<?> clazz)
candidateAdvisors
list
that is applicable to the given class.candidateAdvisors
- the Advisors to evaluateclazz
- the target classpublic static java.lang.Object invokeJoinpointUsingReflection(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
target
- the target objectmethod
- the method to invokeargs
- the arguments for the methodjava.lang.Throwable
- if thrown by the target methodAopInvocationException
- in case of a reflection error