1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.enspire.gemini.updaters;
25
26 import com.enspire.gemini.RelationshipUpdater;
27 import com.enspire.reflection.PropertyReflection;
28
29 /***
30 * Updates one end of a relationship, that have the upper multiplicity 1,
31 * and is represented as a simple Java property, not including primitive Java
32 * types.
33 *
34 * @author Dragan Djuric <dragand@dev.java.net>
35 * @since 1.0
36 **/
37 public class SimplePropertyRelationshipUpdater implements RelationshipUpdater {
38
39 private PropertyReflection propertyReflection;
40
41 /***
42 * Constructs an object leaving its dependencies unset.
43 */
44 public SimplePropertyRelationshipUpdater() {
45 super();
46 }
47
48 /***
49 * Constructs an object and sets the propertyReflection dependency.
50 * @param reflection the object that is used to manipulate JavaBean properties.
51 */
52 public SimplePropertyRelationshipUpdater(PropertyReflection reflection) {
53 super();
54 this.propertyReflection = reflection;
55 }
56
57 /***
58 * Gets propertyReflection - the object that is used to manipulate
59 * JavaBean properties.
60 * @return propertyReflection the object that is used to manipulate
61 * JavaBean properties
62 */
63 public PropertyReflection getPropertyReflection() {
64 return this.propertyReflection;
65 }
66
67 /***
68 * Sets propertyReflection - the object that is used to manipulate
69 * JavaBean properties.
70 * @param propertyReflection the propertyReflection to set.
71 */
72 public void setPropertyReflection(PropertyReflection propertyReflection) {
73 this.propertyReflection = propertyReflection;
74 }
75
76 /***
77 * Sets the the property to new value if it is diferent from the old value.
78 *
79 * @see com.enspire.gemini.RelationshipUpdater#set(java.lang.Object, java.lang.String, java.lang.Object)
80 */
81 public Object set(Object owner, String propertyName, Object value) {
82 if (owner == null) {
83 return null;
84 }
85 Object oldValue = getPropertyReflection().
86 getSimpleProperty(owner, propertyName);
87 if (oldValue != value) {
88 getPropertyReflection().setSimpleProperty(owner, propertyName, value);
89 }
90 return oldValue;
91 }
92
93 /***
94 * Sets the property to <code>null</code>.
95 *
96 * @see com.enspire.gemini.RelationshipUpdater#unset(java.lang.Object, java.lang.String, java.lang.Object)
97 */
98 public Object unset(Object owner, String propertyName, Object value) {
99 return set(owner, propertyName, null);
100 }
101
102 }