Skip to content

Introduce strategy for BeanInfo creation #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

poutsma
Copy link
Contributor

@poutsma poutsma commented Aug 20, 2012

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

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
@poutsma
Copy link
Contributor Author

poutsma commented Aug 20, 2012

@cbeams, @jhoeller, please let me know what you think about these changes.

@philwebb
Copy link
Member

Can you foresee any case where the existing BeanInfo needs to be accessed by the BeanInfoFactory? I am thinking perhaps BeanInfo might augment an existing BeanInfo with additional functionality (ie support traditional getters/setters in addition to some other style).

Perhaps:

public interface BeanInfoFactory {
// Can return a new BeanInfo, wrap the existing or simply return the parameter unchanged
BeanInfo getBeanInfo(BeanInfo beanInfo) throws IntrospectionException;
}

Of course this does mean that potentially beanInfo objects are created then immediately discarded.

@poutsma
Copy link
Contributor Author

poutsma commented Aug 22, 2012

@philwebb It's an interesting proposal, but it does require the creation of a BeanInfo for each bean class before the factory is even invoked. Since Introspector#getBeanInfo() is a rather expensive method call, I think it's better to keep things as is, and let the factory choose to either create a new BeanInfo from scratch, or wrap an existing one.

cbeams added a commit that referenced this pull request Aug 24, 2012
* SPR-9677:
  Introduce strategy for BeanInfo creation
@cbeams
Copy link
Contributor

cbeams commented Aug 24, 2012

Thanks, this is now merged. @poutsma and @jhoeller, please see my comments at SPR-9677.

@cbeams cbeams closed this Aug 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants