in src/main/java/org/apache/bsf/util/ReflectionUtils.java [324:361]
public static Bean getProperty(final Object target, final String propName, final Integer index)
throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
// find the property descriptor
final BeanInfo bi = Introspector.getBeanInfo(target.getClass());
final PropertyDescriptor pd = (PropertyDescriptor) findFeatureByName("property", propName, bi.getPropertyDescriptors());
if (pd == null) {
throw new IllegalArgumentException("property '" + propName + "' is " + "unknown for '" + target + "'");
}
// get read method and type of property
Method rm;
Class propType;
if (index != null) {
// if index != null, then property is indexed - pd better be so too
if (!(pd instanceof IndexedPropertyDescriptor)) {
throw new IllegalArgumentException("attempt to get non-indexed " + "property '" + propName + "' as being indexed");
}
final IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
rm = ipd.getIndexedReadMethod();
propType = ipd.getIndexedPropertyType();
} else {
rm = pd.getReadMethod();
propType = pd.getPropertyType();
}
if (rm == null) {
throw new IllegalArgumentException("property '" + propName + "' is not readable");
}
// now get the value
Object propVal = null;
if (index != null) {
propVal = rm.invoke(target, new Object[] { index });
} else {
propVal = rm.invoke(target, null);
}
return new Bean(propType, propVal);
}