1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.expression;
18
19 import org.apache.commons.beanutils.DynaBean;
20 import org.apache.commons.beanutils.DynaProperty;
21
22 /***
23 * Updates <code>DynaBean</code>'s.
24 * @since 0.7
25 * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
26 */
27 public class DynaBeanUpdater extends TypedUpdater {
28
29 /*** The name of the dyna property to be updated */
30 private final String propertyName;
31
32 /***
33 * Constructs a <code>DynaBeanUpdater</code>
34 * for given <code>DynaProperty</code>.
35 * @param dynaProperty <code>DyanProperty</code>, not null
36 */
37 public DynaBeanUpdater(DynaProperty dynaProperty) {
38 this(dynaProperty.getName(), dynaProperty.getType());
39 }
40
41 /***
42 * Constructs a <code>DynaBeanUpdater</code>
43 * for the given type and property name.
44 * @param propertyName name of the dyan property
45 * @param type type of the dyna property
46 */
47 public DynaBeanUpdater(String propertyName, Class type) {
48 this.propertyName = propertyName;
49 setValueType(type);
50 }
51
52
53 /***
54 * Executes the update on the given code>DynaBean</code>
55 * @see org.apache.commons.betwixt.expression.TypedUpdater#executeUpdate(Context, java.lang.Object, java.lang.Object)
56 */
57 protected void executeUpdate(Context context, Object bean, Object value) throws Exception {
58 if (bean instanceof DynaBean)
59 {
60 DynaBean dynaBean = (DynaBean) bean;
61 dynaBean.set(propertyName, value);
62 }
63 else
64 {
65 handleException(context, new IllegalArgumentException("DynaBean required."));
66 }
67 }
68
69 /***
70 * Outputs something suitable for logging.
71 */
72 public String toString() {
73 return "DynaBeanUpdater [property=" + propertyName + "]";
74 }
75
76 }