Providing Additional BeanInfo Objects
I mentioned near the beginning of this chapter that when explicit
information is provided for a given feature set of the Bean, the base
classes are not examined for that feature set. This creates a problem
when you create a Bean from a subclass that provides only some of the
exposed properties, methods, and events, and the rest come from a
base class. Let’s say you have class AA
that
exposes a property named propA, and class
BB
that extends class AA
and
exposes its own property named propB. If you
were to use low-level reflection to analyze class
BB
, you would find two properties named
propA and propB. Now
let’s say you create a class called
BBBeanInfo
(the BeanInfo class for class
BB
). This class implements the
getPropertyDescriptor()
method by returning a
property descriptor array that contains one element, an instance of
java.beans.PropertyDescriptor
for
propB. The problem here is that the property
named propA that comes from base class
AA
is no longer being exposed. It certainly
isn’t the responsibility of the BBBeanInfo
class to create property descriptors for its base classes. First of
all, if class AA
changes then
BBBeanInfo
would have to be updated to reflect the
change. That doesn’t sound like a good idea. And if you had
class CC
that extends class BB
,
the BeanInfo class for CC
would have to replicate
the property descriptors for AA
and
BB
. This is definitely not the right approach.
The java.beans.BeanInfo
interface includes a method ...
Get Developing Java Beans now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.