Introduce strategy for BeanInfo creation

Before this commit, the CachedIntrospectionResults was hard-coded to
create ExtendedBeanInfos for bean classes. The ExtendedBeanInfo support
the JavaBeans property contract only.

This commit introduces the BeanInfoFactory, a strategy for creating
BeanInfos. Through this strategy, it is possible to support
beans that do not necessarily implement the JavaBeans contract (i.e.
have a different getter or setter style).

BeanInfoFactories are are instantiated by the
CachedIntrospectionResults, which looks for
'META-INF/spring.beanInfoFactories' files on the class path. These files
contain one or more BeanInfoFactory class names. When a BeanInfo is to
be created, the CachedIntrospectionResults will iterate through the
factories, asking it to create a BeanInfo for the given bean class. If
none of the factories support it, an ExtendedBeanInfo is created as a
default.

This commit also contains a change to Property, allowing BeanWrapperImpl
to specify the property name at construction time (as opposed to using
Property#resolveName(), which supports the JavaBeans contract only).

Issue: SPR-9677
This commit is contained in:
Arjen Poutsma
2012-08-20 12:39:22 +02:00
committed by Chris Beams
parent b95550489b
commit ca017a4880
7 changed files with 208 additions and 10 deletions

View File

@@ -57,11 +57,20 @@ public final class Property {
public Property(Class<?> objectType, Method readMethod, Method writeMethod) {
this(objectType, readMethod, writeMethod, null);
}
public Property(Class<?> objectType, Method readMethod, Method writeMethod, String name) {
this.objectType = objectType;
this.readMethod = readMethod;
this.writeMethod = writeMethod;
this.methodParameter = resolveMethodParameter();
this.name = resolveName();
if (name != null) {
this.name = name;
}
else {
this.name = resolveName();
}
this.annotations = resolveAnnotations();
}