18
18
19
19
import java .lang .reflect .Member ;
20
20
import java .lang .reflect .Method ;
21
- import java .util .Collections ;
21
+ import java .util .HashSet ;
22
22
import java .util .Set ;
23
- import java .util .concurrent .ConcurrentHashMap ;
24
23
25
24
import org .springframework .beans .MutablePropertyValues ;
26
25
import org .springframework .beans .factory .config .BeanDefinition ;
49
48
@ SuppressWarnings ("serial" )
50
49
public class RootBeanDefinition extends AbstractBeanDefinition {
51
50
52
- private final Set <Member > externallyManagedConfigMembers =
53
- Collections .newSetFromMap (new ConcurrentHashMap <Member , Boolean >(0 ));
54
-
55
- private final Set <String > externallyManagedInitMethods =
56
- Collections .newSetFromMap (new ConcurrentHashMap <String , Boolean >(0 ));
57
-
58
- private final Set <String > externallyManagedDestroyMethods =
59
- Collections .newSetFromMap (new ConcurrentHashMap <String , Boolean >(0 ));
51
+ boolean allowCaching = true ;
60
52
61
53
private BeanDefinitionHolder decoratedDefinition ;
62
54
63
- boolean allowCaching = true ;
64
-
65
55
private volatile Class <?> targetType ;
66
56
67
57
boolean isFactoryMethodUnique = false ;
@@ -91,6 +81,12 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
91
81
/** Package-visible field that indicates a before-instantiation post-processor having kicked in */
92
82
volatile Boolean beforeInstantiationResolved ;
93
83
84
+ private Set <Member > externallyManagedConfigMembers ;
85
+
86
+ private Set <String > externallyManagedInitMethods ;
87
+
88
+ private Set <String > externallyManagedDestroyMethods ;
89
+
94
90
95
91
/**
96
92
* Create a new RootBeanDefinition, to be configured through its bean
@@ -175,8 +171,8 @@ public RootBeanDefinition(String beanClassName, ConstructorArgumentValues cargs,
175
171
*/
176
172
public RootBeanDefinition (RootBeanDefinition original ) {
177
173
super (original );
178
- this .decoratedDefinition = original .decoratedDefinition ;
179
174
this .allowCaching = original .allowCaching ;
175
+ this .decoratedDefinition = original .decoratedDefinition ;
180
176
this .targetType = original .targetType ;
181
177
this .isFactoryMethodUnique = original .isFactoryMethodUnique ;
182
178
}
@@ -203,6 +199,20 @@ public void setParentName(String parentName) {
203
199
}
204
200
}
205
201
202
+ /**
203
+ * Register a target definition that is being decorated by this bean definition.
204
+ */
205
+ public void setDecoratedDefinition (BeanDefinitionHolder decoratedDefinition ) {
206
+ this .decoratedDefinition = decoratedDefinition ;
207
+ }
208
+
209
+ /**
210
+ * Return the target definition that is being decorated by this bean definition, if any.
211
+ */
212
+ public BeanDefinitionHolder getDecoratedDefinition () {
213
+ return this .decoratedDefinition ;
214
+ }
215
+
206
216
/**
207
217
* Specify the target type of this bean definition, if known in advance.
208
218
*/
@@ -245,37 +255,52 @@ public Method getResolvedFactoryMethod() {
245
255
}
246
256
}
247
257
248
-
249
258
public void registerExternallyManagedConfigMember (Member configMember ) {
250
- this .externallyManagedConfigMembers .add (configMember );
259
+ synchronized (this .postProcessingLock ) {
260
+ if (this .externallyManagedConfigMembers == null ) {
261
+ this .externallyManagedConfigMembers = new HashSet <Member >(1 );
262
+ }
263
+ this .externallyManagedConfigMembers .add (configMember );
264
+ }
251
265
}
252
266
253
267
public boolean isExternallyManagedConfigMember (Member configMember ) {
254
- return this .externallyManagedConfigMembers .contains (configMember );
268
+ synchronized (this .postProcessingLock ) {
269
+ return (this .externallyManagedConfigMembers != null &&
270
+ this .externallyManagedConfigMembers .contains (configMember ));
271
+ }
255
272
}
256
273
257
274
public void registerExternallyManagedInitMethod (String initMethod ) {
258
- this .externallyManagedInitMethods .add (initMethod );
275
+ synchronized (this .postProcessingLock ) {
276
+ if (this .externallyManagedInitMethods == null ) {
277
+ this .externallyManagedInitMethods = new HashSet <String >(1 );
278
+ }
279
+ this .externallyManagedInitMethods .add (initMethod );
280
+ }
259
281
}
260
282
261
283
public boolean isExternallyManagedInitMethod (String initMethod ) {
262
- return this .externallyManagedInitMethods .contains (initMethod );
284
+ synchronized (this .postProcessingLock ) {
285
+ return (this .externallyManagedInitMethods != null &&
286
+ this .externallyManagedInitMethods .contains (initMethod ));
287
+ }
263
288
}
264
289
265
290
public void registerExternallyManagedDestroyMethod (String destroyMethod ) {
266
- this .externallyManagedDestroyMethods .add (destroyMethod );
291
+ synchronized (this .postProcessingLock ) {
292
+ if (this .externallyManagedDestroyMethods == null ) {
293
+ this .externallyManagedDestroyMethods = new HashSet <String >(1 );
294
+ }
295
+ this .externallyManagedDestroyMethods .add (destroyMethod );
296
+ }
267
297
}
268
298
269
299
public boolean isExternallyManagedDestroyMethod (String destroyMethod ) {
270
- return this .externallyManagedDestroyMethods .contains (destroyMethod );
271
- }
272
-
273
- public void setDecoratedDefinition (BeanDefinitionHolder decoratedDefinition ) {
274
- this .decoratedDefinition = decoratedDefinition ;
275
- }
276
-
277
- public BeanDefinitionHolder getDecoratedDefinition () {
278
- return this .decoratedDefinition ;
300
+ synchronized (this .postProcessingLock ) {
301
+ return (this .externallyManagedDestroyMethods != null &&
302
+ this .externallyManagedDestroyMethods .contains (destroyMethod ));
303
+ }
279
304
}
280
305
281
306
0 commit comments