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