1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.sail.core.beans.assembly;
24
25 import java.beans.DefaultPersistenceDelegate;
26 import java.lang.reflect.InvocationTargetException;
27
28 import org.apache.commons.beanutils.PropertyUtils;
29
30 /***
31 * Reference to a bean's property that maintains over long-term persistance.
32 *
33 * @author turadg
34 */
35 public class PropertyRef {
36
37 final static DefaultPersistenceDelegate PR_DELEGATE = new DefaultPersistenceDelegate(
38 new String[] { "target", "propertyName" });
39
40 Object target;
41
42 String propertyName;
43
44 /***
45 * @param target the target bean
46 * @param propertyName the name of the property of target bean that this references
47 */
48 public PropertyRef(Object target, String propertyName) {
49 this.target = target;
50 this.propertyName = propertyName;
51 }
52
53 public Object getTarget() {
54 return target;
55 }
56
57 public String getPropertyName() {
58 return propertyName;
59 }
60
61 public void set(Object value) throws IllegalAccessException,
62 InvocationTargetException, NoSuchMethodException {
63 PropertyUtils.setSimpleProperty(target, propertyName, value);
64 }
65
66 public Object getCurrentValue() throws IllegalAccessException,
67 InvocationTargetException, NoSuchMethodException {
68 return PropertyUtils.getSimpleProperty(target, propertyName);
69 }
70
71 }