Top Description Inners Fields Constructors Methods
org.springframework.beans.factory.support

pack-priv abstract Class AutowireUtils

extends Object
Class Inheritance
Imports
java.beans.PropertyDescriptor, java.io.Serializable, java.lang.reflect.Constructor, .Executable, .InvocationHandler, .InvocationTargetException, .Method, .Modifier, .ParameterizedType, .Proxy, .Type, .TypeVariable, java.util.Arrays, .Comparator, .Set, org.springframework.beans.BeanMetadataElement, org.springframework.beans.factory.ObjectFactory, org.springframework.beans.factory.config.TypedStringValue, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils

Utility class that contains various methods useful for the implementation of autowire-capable bean factories.
Authors
Juergen Hoeller, Mark Fisher, Sam Brannen
Since
1.1.2
See Also
AbstractAutowireCapableBeanFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AutowireUtils.ObjectFactoryDelegatingInvocationHandler

Reflective InvocationHandler for lazy access to the current target object.

Field Summary

Modifier and TypeField and Description
public static final Comparator<Executable>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

whether the bean property is excluded
isExcludedFromDependencyCheck
(PropertyDescriptor
the PropertyDescriptor of the bean property
pd
)

Determine whether the given bean property is excluded from dependency checks.

public static boolean

Returns:

whether the setter method is defined by an interface
isSetterDefinedInInterface
(PropertyDescriptor
the PropertyDescriptor of the bean property
pd
,
Set<Class<?>>
the Set of interfaces (Class objects)
interfaces
)

Return whether the setter method of the given bean property is defined in any of the given interfaces.

public static Object

Returns:

the resolved value
resolveAutowiringValue
(Object
the value to resolve
autowiringValue
,
Class<?>
the type to assign the result to
requiredType
)

Resolve the given autowiring value against the given required type, e.g. an ObjectFactory value to its actual object result.

public static Class<?>

Returns:

the resolved target return type or the standard method return type
resolveReturnTypeForFactoryMethod
(Method
the method to introspect (never null)
method
,
Object[]
the arguments that will be supplied to the method when it is invoked (never null)
args
,
ClassLoader
the ClassLoader to resolve class names against, if necessary (never null)
classLoader
)

Determine the target type for the generic return type of the given generic factory method, where formal type variables are declared on the given method itself.

public static void
sortConstructors(Constructor<?>[]
the constructor array to sort
constructors
)

Sort the given constructors, preferring public constructors and "greedy" ones with a maximum number of arguments.

public static void
sortFactoryMethods(Method[]
the factory method array to sort
factoryMethods
)

Sort the given factory methods, preferring public methods and "greedy" ones with a maximum of arguments.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EXECUTABLE_COMPARATORback to summary
public static final Comparator<Executable> EXECUTABLE_COMPARATOR

Constructor Detail

AutowireUtilsback to summary
pack-priv AutowireUtils()

Method Detail

isExcludedFromDependencyCheckback to summary
public static boolean isExcludedFromDependencyCheck(PropertyDescriptor pd)

Determine whether the given bean property is excluded from dependency checks.

This implementation excludes properties defined by CGLIB.

Parameters
pd:PropertyDescriptor

the PropertyDescriptor of the bean property

Returns:boolean

whether the bean property is excluded

isSetterDefinedInInterfaceback to summary
public static boolean isSetterDefinedInInterface(PropertyDescriptor pd, Set<Class<?>> interfaces)

Return whether the setter method of the given bean property is defined in any of the given interfaces.

Parameters
pd:PropertyDescriptor

the PropertyDescriptor of the bean property

interfaces:Set<Class<?>>

the Set of interfaces (Class objects)

Returns:boolean

whether the setter method is defined by an interface

resolveAutowiringValueback to summary
public static Object resolveAutowiringValue(Object autowiringValue, Class<?> requiredType)

Resolve the given autowiring value against the given required type, e.g. an ObjectFactory value to its actual object result.

Parameters
autowiringValue:Object

the value to resolve

requiredType:Class<?>

the type to assign the result to

Returns:Object

the resolved value

resolveReturnTypeForFactoryMethodback to summary
public static Class<?> resolveReturnTypeForFactoryMethod(Method method, Object[] args, ClassLoader classLoader)

Determine the target type for the generic return type of the given generic factory method, where formal type variables are declared on the given method itself.

For example, given a factory method with the following signature, if resolveReturnTypeForFactoryMethod() is invoked with the reflected method for createProxy() and an Object[] array containing MyService.class, resolveReturnTypeForFactoryMethod() will infer that the target return type is MyService.

public static <T> T createProxy(Class<T> clazz)

Possible Return Values

Parameters
method:Method

the method to introspect (never null)

args:Object[]

the arguments that will be supplied to the method when it is invoked (never null)

classLoader:ClassLoader

the ClassLoader to resolve class names against, if necessary (never null)

Returns:Class<?>

the resolved target return type or the standard method return type

Since
3.2.5
sortConstructorsback to summary
public static void sortConstructors(Constructor<?>[] constructors)

Sort the given constructors, preferring public constructors and "greedy" ones with a maximum number of arguments. The result will contain public constructors first, with decreasing number of arguments, then non-public constructors, again with decreasing number of arguments.

Parameters
constructors:Constructor<?>[]

the constructor array to sort

sortFactoryMethodsback to summary
public static void sortFactoryMethods(Method[] factoryMethods)

Sort the given factory methods, preferring public methods and "greedy" ones with a maximum of arguments. The result will contain public methods first, with decreasing number of arguments, then non-public methods, again with decreasing number of arguments.

Parameters
factoryMethods:Method[]

the factory method array to sort

org.springframework.beans.factory.support back to summary

private Class AutowireUtils.ObjectFactoryDelegatingInvocationHandler

extends Object
implements InvocationHandler, Serializable
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.support.AutowireUtils.ObjectFactoryDelegatingInvocationHandler
All Implemented Interfaces
java.io.Serializable, java.lang.reflect.InvocationHandler
Annotations
@SuppressWarnings:serial

Reflective InvocationHandler for lazy access to the current target object.

Field Summary

Modifier and TypeField and Description
private final ObjectFactory<?>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

objectFactoryback to summary
private final ObjectFactory<?> objectFactory

Constructor Detail

ObjectFactoryDelegatingInvocationHandlerback to summary
pack-priv ObjectFactoryDelegatingInvocationHandler(ObjectFactory<?> objectFactory)

Method Detail

invokeback to summary
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Annotations
@Override
Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.