Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Get objects from a class using beanutils

Reply
Thread Tools

Get objects from a class using beanutils

 
 
The Griz
Guest
Posts: n/a
 
      03-31-2005

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[i];
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
--
The Griz
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catch error from BeanUtils.populate Klaus Java 2 05-18-2012 08:47 AM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Struts help - javax.servlet.ServletException: BeanUtils.populate Dix Java 0 01-11-2006 06:44 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
problem in Beanutils.copyProperties() Rahul Java 2 09-26-2005 08:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57