1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils;
18
19 import java.util.Map;
20 import java.beans.PropertyDescriptor;
21 import java.lang.reflect.InvocationTargetException;
22
23 /***
24 * A PropertyUtilsBean which customises the behaviour of the
25 * setNestedProperty and getNestedProperty methods to look for
26 * simple properties in preference to map entries.
27 */
28 public class PropsFirstPropertyUtilsBean extends PropertyUtilsBean {
29
30 public PropsFirstPropertyUtilsBean() {
31 super();
32 }
33
34 /***
35 * Note: this is a *very rough* override of this method. In particular,
36 * it does not handle MAPPED_DELIM and INDEXED_DELIM chars in the
37 * propertyName, so propertyNames like "a(b)" or "a[3]" will not
38 * be correctly handled.
39 */
40 protected Object getPropertyOfMapBean(Map bean, String propertyName)
41 throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
42
43 PropertyDescriptor descriptor = getPropertyDescriptor(bean, propertyName);
44 if (descriptor == null) {
45
46 return bean.get(propertyName);
47 } else {
48
49 return getSimpleProperty(bean, propertyName);
50 }
51 }
52
53 /***
54 * Note: this is a *very rough* override of this method. In particular,
55 * it does not handle MAPPED_DELIM and INDEXED_DELIM chars in the
56 * propertyName, so propertyNames like "a(b)" or "a[3]" will not
57 * be correctly handled.
58 */
59 protected void setPropertyOfMapBean(Map bean, String propertyName, Object value)
60 throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
61 PropertyDescriptor descriptor = getPropertyDescriptor(bean, propertyName);
62 if (descriptor == null) {
63
64 bean.put(propertyName, value);
65 } else {
66
67 setSimpleProperty(bean, propertyName, value);
68 }
69 }
70 }