1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import org .springframework .core .GenericTypeResolver ;
29
29
import org .springframework .core .MethodParameter ;
30
30
import org .springframework .util .ClassUtils ;
31
+ import org .springframework .util .ObjectUtils ;
31
32
import org .springframework .util .StringUtils ;
32
33
33
34
/**
38
39
* @author Juergen Hoeller
39
40
* @since 2.5.2
40
41
*/
41
- class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
42
+ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
42
43
43
44
private final Class <?> beanClass ;
44
45
45
46
private final Method readMethod ;
46
47
47
48
private final Method writeMethod ;
48
49
49
- private final Class <?> propertyEditorClass ;
50
-
51
50
private volatile Set <Method > ambiguousWriteMethods ;
52
51
52
+ private MethodParameter writeMethodParameter ;
53
+
53
54
private Class <?> propertyType ;
54
55
55
- private MethodParameter writeMethodParameter ;
56
+ private final Class <?> propertyEditorClass ;
56
57
57
58
58
59
public GenericTypeAwarePropertyDescriptor (Class <?> beanClass , String propertyName ,
59
60
Method readMethod , Method writeMethod , Class <?> propertyEditorClass )
60
61
throws IntrospectionException {
61
62
62
63
super (propertyName , null , null );
64
+
65
+ if (beanClass == null ) {
66
+ throw new IntrospectionException ("Bean class must not be null" );
67
+ }
63
68
this .beanClass = beanClass ;
64
- this .propertyEditorClass = propertyEditorClass ;
65
69
66
70
Method readMethodToUse = BridgeMethodResolver .findBridgedMethod (readMethod );
67
71
Method writeMethodToUse = BridgeMethodResolver .findBridgedMethod (writeMethod );
@@ -93,8 +97,11 @@ public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyNam
93
97
this .ambiguousWriteMethods = ambiguousCandidates ;
94
98
}
95
99
}
100
+
101
+ this .propertyEditorClass = propertyEditorClass ;
96
102
}
97
103
104
+
98
105
public Class <?> getBeanClass () {
99
106
return this .beanClass ;
100
107
}
@@ -120,9 +127,15 @@ public Method getWriteMethodForActualAccess() {
120
127
return this .writeMethod ;
121
128
}
122
129
123
- @ Override
124
- public Class <?> getPropertyEditorClass () {
125
- return this .propertyEditorClass ;
130
+ public synchronized MethodParameter getWriteMethodParameter () {
131
+ if (this .writeMethod == null ) {
132
+ return null ;
133
+ }
134
+ if (this .writeMethodParameter == null ) {
135
+ this .writeMethodParameter = new MethodParameter (this .writeMethod , 0 );
136
+ GenericTypeResolver .resolveParameterType (this .writeMethodParameter , this .beanClass );
137
+ }
138
+ return this .writeMethodParameter ;
126
139
}
127
140
128
141
@ Override
@@ -144,15 +157,34 @@ public synchronized Class<?> getPropertyType() {
144
157
return this .propertyType ;
145
158
}
146
159
147
- public synchronized MethodParameter getWriteMethodParameter () {
148
- if (this .writeMethod == null ) {
149
- return null ;
160
+ @ Override
161
+ public Class <?> getPropertyEditorClass () {
162
+ return this .propertyEditorClass ;
163
+ }
164
+
165
+
166
+ @ Override
167
+ public boolean equals (Object other ) {
168
+ if (this == other ) {
169
+ return true ;
150
170
}
151
- if (this .writeMethodParameter == null ) {
152
- this .writeMethodParameter = new MethodParameter (this .writeMethod , 0 );
153
- GenericTypeResolver .resolveParameterType (this .writeMethodParameter , this .beanClass );
171
+ if (!(other instanceof GenericTypeAwarePropertyDescriptor )) {
172
+ return false ;
154
173
}
155
- return this .writeMethodParameter ;
174
+ GenericTypeAwarePropertyDescriptor otherPd = (GenericTypeAwarePropertyDescriptor ) other ;
175
+ return (getBeanClass ().equals (otherPd .getBeanClass ()) &&
176
+ ObjectUtils .nullSafeEquals (getReadMethod (), otherPd .getReadMethod ()) &&
177
+ ObjectUtils .nullSafeEquals (getWriteMethod (), otherPd .getWriteMethod ()) &&
178
+ ObjectUtils .nullSafeEquals (getPropertyEditorClass (), otherPd .getPropertyEditorClass ()) &&
179
+ isBound () == otherPd .isBound () && isConstrained () == otherPd .isConstrained ());
180
+ }
181
+
182
+ @ Override
183
+ public int hashCode () {
184
+ int hashCode = getBeanClass ().hashCode ();
185
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (getReadMethod ());
186
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (getWriteMethod ());
187
+ return hashCode ;
156
188
}
157
189
158
190
}
0 commit comments