commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Extance, Paul" <paul.exta...@spirent.com>
Subject [BeanUtils] Access the size of an array...
Date Wed, 15 Oct 2003 22:59:01 GMT
I can access (using BeanUtils.getProperty) the contents of an array
list[0].part, list[1].part, but I'd also like to access the size of the
array list.size.
 
Looking at v1.6 this does not work, as List.size() is not a 'real' java bean
property.
 
Is there a good way to do this with the bean utils?
 
Currently I have made a change to PropertyUtils to support this...
 
 
public static Object getSimpleProperty(Object bean, String name)
 
    . . .
    . . .
    . . .
 
    // Retrieve the property getter method for the specified property
    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    Method readMethod = null;
    if (descriptor == null) {
        // try other methods...
        try {
            readMethod = bean.getClass().getMethod(name, new Class[] {});
            if (readMethod == null) {
                throw new NoSuchMethodException("Unknown property '" + name
+ "'");
            }
        } catch(Exception e) {
            throw new NoSuchMethodException("Unknown property '" + name +
"'");
        }
    } else 
        readMethod = getReadMethod(descriptor);
    
    if (readMethod == null) {
        throw new NoSuchMethodException("Property '" + name +
                "' has no getter method");
    }
 
    // Call the property getter and return the value
    Object value = readMethod.invoke(bean, new Object[0]);
    return (value);
}
 
 
This seems to work fine, so my question is 
a)       is there a better way to do this?
b)       is there any interest in having beanutils support this feature? I'd
prefer to keep to a core release of the commons jars.
 
Thanks
 
Paul Extance
 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message