Get objects from a class using beanutils

T

The Griz

I have an class, MyClass, that has several objects (which are properties of
the class) which inherit from MyAbstractClass (an abstract class of
course).

Using jakarata commons beanutils I would like to get all the properties
from MyClass that inherit from MyAbstract class. It seems it should be
simple (and probably is) but I can't seem to get it right.

I am using the PropertyUtilsBean to get a list of the properties in
MyClass. After that I need to somehow compare each property type to see if
it is derived from MyAbstractClass like so

PropertyUtilsBean utils = new PropertyUtilsBean();
PropertyDescriptor [] descriptors = utils.getPropertyDescriptors(myClass);
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor descriptor = descriptors;
Class descClass = descriptor.getPropertyType();
if (descClass.isInstance(MyAbstractClass.class) {
// do my stuff
}
}

Instead of getting the derived objects, I get any class. Clearly I am
doing something completely wrong. I have been browsing the javadoc for
beanutils and class but I am not finding any joy.

If someone could point me in the correct direction I would appreciate it
greatly.

Thanks
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top