1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.beans;
18
19 import java.beans.PropertyDescriptor;
20 import java.io.Serializable;
21
22 import org.springframework.util.Assert;
23 import org.springframework.util.ObjectUtils;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 @SuppressWarnings("serial")
43 public class PropertyValue extends BeanMetadataAttributeAccessor implements Serializable {
44
45 private final String name;
46
47 private final Object value;
48
49 private Object source;
50
51 private boolean optional = false;
52
53 private boolean converted = false;
54
55 private Object convertedValue;
56
57
58 volatile Boolean conversionNecessary;
59
60
61 transient volatile Object resolvedTokens;
62
63
64 transient volatile PropertyDescriptor resolvedDescriptor;
65
66
67
68
69
70
71
72 public PropertyValue(String name, Object value) {
73 this.name = name;
74 this.value = value;
75 }
76
77
78
79
80
81 public PropertyValue(PropertyValue original) {
82 Assert.notNull(original, "Original must not be null");
83 this.name = original.getName();
84 this.value = original.getValue();
85 this.source = original.getSource();
86 this.optional = original.isOptional();
87 this.converted = original.converted;
88 this.convertedValue = original.convertedValue;
89 this.conversionNecessary = original.conversionNecessary;
90 this.resolvedTokens = original.resolvedTokens;
91 this.resolvedDescriptor = original.resolvedDescriptor;
92 copyAttributesFrom(original);
93 }
94
95
96
97
98
99
100
101 public PropertyValue(PropertyValue original, Object newValue) {
102 Assert.notNull(original, "Original must not be null");
103 this.name = original.getName();
104 this.value = newValue;
105 this.source = original;
106 this.optional = original.isOptional();
107 this.conversionNecessary = original.conversionNecessary;
108 this.resolvedTokens = original.resolvedTokens;
109 this.resolvedDescriptor = original.resolvedDescriptor;
110 copyAttributesFrom(original);
111 }
112
113
114
115
116
117 public String getName() {
118 return this.name;
119 }
120
121
122
123
124
125
126
127 public Object getValue() {
128 return this.value;
129 }
130
131
132
133
134
135
136 public PropertyValue getOriginalPropertyValue() {
137 PropertyValue original = this;
138 while (original.source instanceof PropertyValue && original.source != original) {
139 original = (PropertyValue) original.source;
140 }
141 return original;
142 }
143
144 public void setOptional(boolean optional) {
145 this.optional = optional;
146 }
147
148 public boolean isOptional() {
149 return this.optional;
150 }
151
152
153
154
155
156 public synchronized boolean isConverted() {
157 return this.converted;
158 }
159
160
161
162
163
164 public synchronized void setConvertedValue(Object value) {
165 this.converted = true;
166 this.convertedValue = value;
167 }
168
169
170
171
172
173 public synchronized Object getConvertedValue() {
174 return this.convertedValue;
175 }
176
177
178 @Override
179 public boolean equals(Object other) {
180 if (this == other) {
181 return true;
182 }
183 if (!(other instanceof PropertyValue)) {
184 return false;
185 }
186 PropertyValue otherPv = (PropertyValue) other;
187 return (this.name.equals(otherPv.name) &&
188 ObjectUtils.nullSafeEquals(this.value, otherPv.value) &&
189 ObjectUtils.nullSafeEquals(this.source, otherPv.source));
190 }
191
192 @Override
193 public int hashCode() {
194 return this.name.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.value);
195 }
196
197 @Override
198 public String toString() {
199 return "bean property '" + this.name + "'";
200 }
201
202 }