in src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java [475:518]
public Object getMappedProperty(final Object bean, final String name, final String key)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Objects.requireNonNull(bean, "bean");
Objects.requireNonNull(name, "name");
Objects.requireNonNull(key, "key");
// Handle DynaBean instances specially
if (bean instanceof DynaBean) {
final DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
if (descriptor == null) {
throw new NoSuchMethodException("Unknown property '" + name + "'+ on bean class '" + bean.getClass() + "'");
}
return ((DynaBean) bean).get(name, key);
}
Object result = null;
// Retrieve the property descriptor for the specified property
final PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
if (descriptor == null) {
throw new NoSuchMethodException("Unknown property '" + name + "'+ on bean class '" + bean.getClass() + "'");
}
if (descriptor instanceof MappedPropertyDescriptor) {
// Call the keyed getter method if there is one
Method readMethod = ((MappedPropertyDescriptor) descriptor).getMappedReadMethod();
readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod);
if (readMethod == null) {
throw new NoSuchMethodException("Property '" + name + "' has no mapped getter method on bean class '" + bean.getClass() + "'");
}
result = invokeMethod(readMethod, bean, key);
} else {
/* means that the result has to be retrieved from a map */
final Method readMethod = getReadMethod(bean.getClass(), descriptor);
if (readMethod == null) {
throw new NoSuchMethodException("Property '" + name + "' has no mapped getter method on bean class '" + bean.getClass() + "'");
}
final Object invokeResult = invokeMethod(readMethod, bean, BeanUtils.EMPTY_OBJECT_ARRAY);
/* test and fetch from the map */
if (invokeResult instanceof Map) {
result = ((Map<?, ?>) invokeResult).get(key);
}
}
return result;
}