BeanInfo: partially overriding default property discovery

O

Olaf Klischat

When providing a BeanInfo for a Java bean, is it possible to only
provide a single custom PropertyDescriptor for one of the (dozens of)
properties of the bean, and fall back to the JRE's default reflection
discovery for all other properties?

When looking at the BeanInfo spec, it seems to me that you can only
either use the default discovery for all the properties or provide
custom descriptors for all the properties; there appears to be no API to
explicitly invoke the JRE's reflective property discovery and then
replace just one of the resulting PropertyDescriptors with your own one.
 
E

EJP

Olaf said:
When providing a BeanInfo for a Java bean, is it possible to only
provide a single custom PropertyDescriptor for one of the (dozens of)
properties of the bean, and fall back to the JRE's default reflection
discovery for all other properties?


Yes. You can call the Introspector again with a different argument that
tells it to ignore the BeanInfo so you don't recurse.
 
O

Olaf Klischat

EJP said:
Yes. You can call the Introspector again with a different argument that
tells it to ignore the BeanInfo so you don't recurse.

Yeah, I found Introspector.getBeanInfo(Bean.class,
IGNORE_IMMEDIATE_BEANINFO). Did you mean that? Unfortunately, this is
available in 1.7 only, which I can't use. I think I got it to work (more
or less) by calling Introspector.getBeanInfo() from
getPropertyDescriptors() and returning null in the resulting recursive
call to getPropertyDescriptors(), and then appropriately modifying the
PropertyDescriptor[] array returned to the "outer"
getPropertyDescriptors() invocation.
 
E

EJP

Olaf said:
Yeah, I found Introspector.getBeanInfo(Bean.class,
IGNORE_IMMEDIATE_BEANINFO). Did you mean that? Unfortunately, this is
available in 1.7 only, which I can't use.

That's strange, it was available in 1.6 when I used it last June, and
it's in the Javadoc for 1.5 and 1.4 and 1.3. So you are at least nine
years out with that statement.
 
O

Olaf Klischat

EJP said:
That's strange, it was available in 1.6 when I used it last June, and
it's in the Javadoc for 1.5 and 1.4 and 1.3. So you are at least nine
years out with that statement.

Wow. You're right. I guess I was only looking at the
getBeanInfo(Class,Class,int) method (which was introduced in 1.7) but
failed to notice the getBeanInfo(Class,int) one. I'm sorry if I'm
looking a bit like an idiot right now :-|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top