Get objects from a class using beanutils

Discussion in 'Java' started by The Griz, Mar 31, 2005.

  1. The Griz

    The Griz Guest

    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
    --
    The Griz
    The Griz, Mar 31, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Klaus
    Replies:
    2
    Views:
    2,240
    praveentp007
    May 18, 2012
  2. Rahul
    Replies:
    2
    Views:
    8,074
    Roedy Green
    Sep 26, 2005
  3. E11
    Replies:
    1
    Views:
    4,757
    Thomas Weidenfeller
    Oct 12, 2005
  4. Dix
    Replies:
    0
    Views:
    11,903
  5. 7stud
    Replies:
    11
    Views:
    692
    Dennis Lee Bieber
    Mar 20, 2007
Loading...

Share This Page