org.springframework.aop.support
Class AopUtils

java.lang.Object
  extended byorg.springframework.aop.support.AopUtils

public abstract class AopUtils
extends Object

Utility methods used by the AOP framework and by AOP proxy factories. Not intended to be used directly by applications.

Author:
Rod Johnson, Juergen Hoeller

Constructor Summary
AopUtils()
           
 
Method Summary
static boolean canApply(Advisor advisor, Class targetClass)
          Can the given advisor apply at all on the given class?
static boolean canApply(Pointcut pc, Class targetClass)
          Can the given pointcut apply at all on the given class?
static Class[] getAllInterfaces(Object object)
          Return all interfaces that the given object implements as array, including ones implemented by superclasses.
static List getAllInterfacesAsList(Object object)
          Return all interfaces that the given object implements as List, including ones implemented by superclasses.
static Class[] getAllInterfacesForClass(Class clazz)
          Return all interfaces that the given class implements as array, including ones implemented by superclasses.
static List getAllInterfacesForClassAsList(Class clazz)
          Return all interfaces that the given class implements as List, including ones implemented by superclasses.
static Method getMostSpecificMethod(Method method, Class targetClass)
          Given a method, which may come from an interface, and a targetClass used in the current AOP invocation, find the most specific method if there is one.
static String interfacesString(Collection interfaces)
          Build a String that consists of the names of the interfaces in the given collection.
static Object invokeJoinpointUsingReflection(Object target, Method method, Object[] args)
          Invoke the target directly via reflection.
static boolean isAopProxy(Object object)
          Return whether the given object is either a J2SE dynamic proxy or a CGLIB proxy.
static boolean isCglibProxy(Object object)
          Return whether the given object is a CGLIB proxy.
static boolean isCglibProxyClass(Class clazz)
          Return whether the specified class is a CGLIB-generated class.
static boolean isEqualsMethod(Method method)
          Return whether the given method is an "equals" method.
static boolean isHashCodeMethod(Method method)
          Return whether the given method is a "hashCode" method.
static boolean isJdkDynamicProxy(Object object)
          Return whether the given object is a J2SE dynamic proxy.
static boolean isToStringMethod(Method method)
          Return whether the given method is an "toString" method.
static Class[] toInterfaceArray(String[] interfaceNames)
          Convenience method to convert a string array of interface names to a class array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AopUtils

public AopUtils()
Method Detail

isAopProxy

public static boolean isAopProxy(Object object)
Return whether the given object is either a J2SE dynamic proxy or a CGLIB proxy.

Parameters:
object - the object to check
See Also:
isJdkDynamicProxy(java.lang.Object), isCglibProxy(java.lang.Object)

isJdkDynamicProxy

public static boolean isJdkDynamicProxy(Object object)
Return whether the given object is a J2SE dynamic proxy.

Parameters:
object - the object to check
See Also:
Proxy.isProxyClass(java.lang.Class)

isCglibProxy

public static boolean isCglibProxy(Object object)
Return whether the given object is a CGLIB proxy.

Parameters:
object - the object to check

isCglibProxyClass

public static boolean isCglibProxyClass(Class clazz)
Return whether the specified class is a CGLIB-generated class.

Parameters:
clazz - the class to check

isEqualsMethod

public static boolean isEqualsMethod(Method method)
Return whether the given method is an "equals" method.

See Also:
Object.equals(java.lang.Object)

isHashCodeMethod

public static boolean isHashCodeMethod(Method method)
Return whether the given method is a "hashCode" method.

See Also:
Object.hashCode()

isToStringMethod

public static boolean isToStringMethod(Method method)
Return whether the given method is an "toString" method.

See Also:
Object.toString()

getMostSpecificMethod

public static Method getMostSpecificMethod(Method method,
                                           Class targetClass)
Given a method, which may come from an interface, and a targetClass used in the current AOP invocation, find the most specific 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.

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

toInterfaceArray

public static Class[] toInterfaceArray(String[] interfaceNames)
                                throws IllegalArgumentException,
                                       ClassNotFoundException
Convenience method to convert a string array of interface names to a class array.

Returns:
an array of interface classes
Throws:
IllegalArgumentException - if any of the classes is not an interface
ClassNotFoundException - if any of the classes can't be loaded

interfacesString

public static String interfacesString(Collection interfaces)
Build a String that consists of the names of the interfaces in the given collection.

Parameters:
interfaces - collection of Class objects that represent interfaces.
Returns:
a string of form com.foo.Bar,com.foo.Baz

getAllInterfaces

public static Class[] getAllInterfaces(Object object)
Return all interfaces that the given object implements as array, including ones implemented by superclasses.

Parameters:
object - the object to analyse for interfaces
Returns:
all interfaces that the given object implements as array

getAllInterfacesForClass

public static Class[] getAllInterfacesForClass(Class clazz)
Return all interfaces that the given class implements as array, including ones implemented by superclasses.

Parameters:
clazz - the class to analyse for interfaces
Returns:
all interfaces that the given object implements as array

getAllInterfacesAsList

public static List getAllInterfacesAsList(Object object)
Return all interfaces that the given object implements as List, including ones implemented by superclasses.

Parameters:
object - the object to analyse for interfaces
Returns:
all interfaces that the given object implements as List

getAllInterfacesForClassAsList

public static List getAllInterfacesForClassAsList(Class clazz)
Return all interfaces that the given class implements as List, including ones implemented by superclasses.

Parameters:
clazz - the class to analyse for interfaces
Returns:
all interfaces that the given object implements as List

canApply

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 - pc static or dynamic pointcut to check
targetClass - class we're testing
Returns:
whether the pointcut can apply on any method

canApply

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

invokeJoinpointUsingReflection

public static Object invokeJoinpointUsingReflection(Object target,
                                                    Method method,
                                                    Object[] args)
                                             throws Throwable
Invoke the target directly via reflection.

Parameters:
target - the target object
method - the method to invoke
args - the arguments for the method
Throws:
Throwable - if thrown by the target method
AspectException - if encountering a reflection error


Copyright (C) 2003-2004 The Spring Framework Project.