Top Description Constructors Methods
org.springframework.aop.framework

public abstract Class AopProxyUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.Array, .Method, .Proxy, java.util.ArrayList, .Arrays, .List, org.springframework.aop.SpringProxy, .TargetClassAware, .TargetSource, org.springframework.aop.support.AopUtils, org.springframework.aop.target.SingletonTargetSource, org.springframework.core.DecoratingProxy, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ObjectUtils

Utility methods for AOP proxy factories.

Mainly for internal use within the AOP framework.

See org.springframework.aop.support.AopUtils for a collection of generic AOP utility methods which do not depend on AOP framework internals.

Authors
Rod Johnson, Juergen Hoeller, Sam Brannen
See Also
org.springframework.aop.support.AopUtils

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static Object[]

Returns:

a cloned argument array, or the original if no adaptation is needed
adaptArgumentsIfNecessary
(Method
the target method
method
,
Object[]
the given arguments
arguments
)

Adapt the given arguments to the target signature in the given method, if necessary: in particular, if a given vararg argument array does not match the array type of the declared vararg parameter in the method.

public static Class<?>[]

Returns:

the complete set of interfaces that the proxy should implement
completeJdkProxyInterfaces
(Class<?>...
the set of user-specified interfaces implemented by the component to be proxied
userInterfaces
)

Complete the set of interfaces that are typically required in a JDK dynamic proxy generated by Spring AOP.

public static Class<?>[]

Returns:

the complete set of interfaces to proxy
completeProxiedInterfaces
(AdvisedSupport
the proxy config
advised
)

Determine the complete set of interfaces to proxy for the given AOP configuration.

pack-priv static Class<?>[]

Returns:

the complete set of interfaces to proxy
completeProxiedInterfaces
(AdvisedSupport
the proxy config
advised
,
boolean
whether to expose the DecoratingProxy interface
decoratingProxy
)

Determine the complete set of interfaces to proxy for the given AOP configuration.

public static boolean
equalsAdvisors(AdvisedSupport a, AdvisedSupport b)

Check equality of the advisors behind the given AdvisedSupport objects.

public static boolean
equalsInProxy(AdvisedSupport a, AdvisedSupport b)

Check equality of the proxies behind the given AdvisedSupport objects.

public static boolean
equalsProxiedInterfaces(AdvisedSupport a, AdvisedSupport b)

Check equality of the proxied interfaces behind the given AdvisedSupport objects.

public static Object

Returns:

the singleton target object managed in a SingletonTargetSource, or null in any other case (not a proxy, not an existing singleton target)
getSingletonTarget
(Object
the (potential) proxy to check
candidate
)

Obtain the singleton target object behind the given proxy, if any.

public static Class<?>[]

Returns:

all user-specified interfaces that the proxy implements, in the original order (never null or empty)
proxiedUserInterfaces
(Object
the proxy to analyze (usually a JDK dynamic proxy)
proxy
)

Extract the user-specified interfaces that the given proxy implements, i.e. all non-Advised interfaces that the proxy implements.

public static Class<?>

Returns:

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

Determine the ultimate target class of the given bean instance, traversing not only a top-level proxy but any number of nested proxies as well — as long as possible without side effects, that is, just for singleton targets.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AopProxyUtilsback to summary
public AopProxyUtils()

Method Detail

adaptArgumentsIfNecessaryback to summary
pack-priv static Object[] adaptArgumentsIfNecessary(Method method, Object[] arguments)

Adapt the given arguments to the target signature in the given method, if necessary: in particular, if a given vararg argument array does not match the array type of the declared vararg parameter in the method.

Parameters
method:Method

the target method

arguments:Object[]

the given arguments

Returns:Object[]

a cloned argument array, or the original if no adaptation is needed

Since
4.2.3
completeJdkProxyInterfacesback to summary
public static Class<?>[] completeJdkProxyInterfaces(Class<?>... userInterfaces)

Complete the set of interfaces that are typically required in a JDK dynamic proxy generated by Spring AOP.

Specifically, SpringProxy, Advised, and DecoratingProxy will be appended to the set of user-specified interfaces.

This method can be useful when registering proxy hints for Spring's AOT support, as demonstrated in the following example which uses this method via a static import.

RuntimeHints hints = ...
hints.proxies().registerJdkProxy(completeJdkProxyInterfaces(MyInterface.class));
Parameters
userInterfaces:Class<?>[]

the set of user-specified interfaces implemented by the component to be proxied

Returns:Class<?>[]

the complete set of interfaces that the proxy should implement

Exceptions
IllegalArgumentException:
if a supplied Class is null, is not an interface, or is a sealed interface
Since
6.0
See Also
SpringProxy, Advised, DecoratingProxy, org.springframework.aot.hint.RuntimeHints#proxies(), org.springframework.aot.hint.ProxyHints#registerJdkProxy(Class...)
completeProxiedInterfacesback to summary
public static Class<?>[] completeProxiedInterfaces(AdvisedSupport advised)

Determine the complete set of interfaces to proxy for the given AOP configuration.

This will always add the Advised interface unless the AdvisedSupport's "opaque" flag is on. Always adds the org.springframework.aop.SpringProxy marker interface.

Parameters
advised:AdvisedSupport

the proxy config

Returns:Class<?>[]

the complete set of interfaces to proxy

See Also
SpringProxy, Advised
completeProxiedInterfacesback to summary
pack-priv static Class<?>[] completeProxiedInterfaces(AdvisedSupport advised, boolean decoratingProxy)

Determine the complete set of interfaces to proxy for the given AOP configuration.

This will always add the Advised interface unless the AdvisedSupport's "opaque" flag is on. Always adds the org.springframework.aop.SpringProxy marker interface.

Parameters
advised:AdvisedSupport

the proxy config

decoratingProxy:boolean

whether to expose the DecoratingProxy interface

Returns:Class<?>[]

the complete set of interfaces to proxy

Since
4.3
See Also
SpringProxy, Advised, DecoratingProxy
equalsAdvisorsback to summary
public static boolean equalsAdvisors(AdvisedSupport a, AdvisedSupport b)

Check equality of the advisors behind the given AdvisedSupport objects.

equalsInProxyback to summary
public static boolean equalsInProxy(AdvisedSupport a, AdvisedSupport b)

Check equality of the proxies behind the given AdvisedSupport objects. Not the same as equality of the AdvisedSupport objects: rather, equality of interfaces, advisors and target sources.

equalsProxiedInterfacesback to summary
public static boolean equalsProxiedInterfaces(AdvisedSupport a, AdvisedSupport b)

Check equality of the proxied interfaces behind the given AdvisedSupport objects.

getSingletonTargetback to summary
public static Object getSingletonTarget(Object candidate)

Obtain the singleton target object behind the given proxy, if any.

Parameters
candidate:Object

the (potential) proxy to check

Returns:Object

the singleton target object managed in a SingletonTargetSource, or null in any other case (not a proxy, not an existing singleton target)

Annotations
@Nullable
Since
4.3.8
See Also
Advised#getTargetSource(), SingletonTargetSource#getTarget()
proxiedUserInterfacesback to summary
public static Class<?>[] proxiedUserInterfaces(Object proxy)

Extract the user-specified interfaces that the given proxy implements, i.e. all non-Advised interfaces that the proxy implements.

Parameters
proxy:Object

the proxy to analyze (usually a JDK dynamic proxy)

Returns:Class<?>[]

all user-specified interfaces that the proxy implements, in the original order (never null or empty)

See Also
Advised
ultimateTargetClassback to summary
public static Class<?> ultimateTargetClass(Object candidate)

Determine the ultimate target class of the given bean instance, traversing not only a top-level proxy but any number of nested proxies as well — as long as possible without side effects, that is, just for singleton targets.

Parameters
candidate:Object

the instance to check (might be an AOP proxy)

Returns:Class<?>

the ultimate target class (or the plain class of the given object as fallback; never null)

See Also
org.springframework.aop.TargetClassAware#getTargetClass(), Advised#getTargetSource()