18
18
19
19
import java .lang .reflect .Member ;
20
20
import java .lang .reflect .Method ;
21
- import java .util .Map ;
22
- import java .util .concurrent . ConcurrentHashMap ;
21
+ import java .util .HashSet ;
22
+ import java .util .Set ;
23
23
24
24
import org .springframework .beans .MutablePropertyValues ;
25
25
import org .springframework .beans .factory .config .BeanDefinition ;
48
48
@ SuppressWarnings ("serial" )
49
49
public class RootBeanDefinition extends AbstractBeanDefinition {
50
50
51
- // using a ConcurrentHashMap as a Set
52
- private final Map <Member , Boolean > externallyManagedConfigMembers = new ConcurrentHashMap <Member , Boolean >(0 );
53
-
54
- // using a ConcurrentHashMap as a Set
55
- private final Map <String , Boolean > externallyManagedInitMethods = new ConcurrentHashMap <String , Boolean >(0 );
56
-
57
- // using a ConcurrentHashMap as a Set
58
- private final Map <String , Boolean > externallyManagedDestroyMethods = new ConcurrentHashMap <String , Boolean >(0 );
51
+ boolean allowCaching = true ;
59
52
60
53
private BeanDefinitionHolder decoratedDefinition ;
61
54
62
- boolean allowCaching = true ;
63
-
64
55
private volatile Class <?> targetType ;
65
56
66
57
boolean isFactoryMethodUnique = false ;
@@ -87,6 +78,12 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
87
78
/** Package-visible field that indicates a before-instantiation post-processor having kicked in */
88
79
volatile Boolean beforeInstantiationResolved ;
89
80
81
+ private Set <Member > externallyManagedConfigMembers ;
82
+
83
+ private Set <String > externallyManagedInitMethods ;
84
+
85
+ private Set <String > externallyManagedDestroyMethods ;
86
+
90
87
91
88
/**
92
89
* Create a new RootBeanDefinition, to be configured through its bean
@@ -225,9 +222,9 @@ public RootBeanDefinition(String beanClassName, ConstructorArgumentValues cargs,
225
222
* @param original the original bean definition to copy from
226
223
*/
227
224
public RootBeanDefinition (RootBeanDefinition original ) {
228
- super (original );
229
- this .decoratedDefinition = original .decoratedDefinition ;
225
+ super ((BeanDefinition ) original );
230
226
this .allowCaching = original .allowCaching ;
227
+ this .decoratedDefinition = original .decoratedDefinition ;
231
228
this .targetType = original .targetType ;
232
229
this .isFactoryMethodUnique = original .isFactoryMethodUnique ;
233
230
}
@@ -252,6 +249,20 @@ public void setParentName(String parentName) {
252
249
}
253
250
}
254
251
252
+ /**
253
+ * Register a target definition that is being decorated by this bean definition.
254
+ */
255
+ public void setDecoratedDefinition (BeanDefinitionHolder decoratedDefinition ) {
256
+ this .decoratedDefinition = decoratedDefinition ;
257
+ }
258
+
259
+ /**
260
+ * Return the target definition that is being decorated by this bean definition, if any.
261
+ */
262
+ public BeanDefinitionHolder getDecoratedDefinition () {
263
+ return this .decoratedDefinition ;
264
+ }
265
+
255
266
/**
256
267
* Specify the target type of this bean definition, if known in advance.
257
268
*/
@@ -294,37 +305,52 @@ public Method getResolvedFactoryMethod() {
294
305
}
295
306
}
296
307
297
-
298
308
public void registerExternallyManagedConfigMember (Member configMember ) {
299
- this .externallyManagedConfigMembers .put (configMember , Boolean .TRUE );
309
+ synchronized (this .postProcessingLock ) {
310
+ if (this .externallyManagedConfigMembers == null ) {
311
+ this .externallyManagedConfigMembers = new HashSet <Member >(1 );
312
+ }
313
+ this .externallyManagedConfigMembers .add (configMember );
314
+ }
300
315
}
301
316
302
317
public boolean isExternallyManagedConfigMember (Member configMember ) {
303
- return this .externallyManagedConfigMembers .containsKey (configMember );
318
+ synchronized (this .postProcessingLock ) {
319
+ return (this .externallyManagedConfigMembers != null &&
320
+ this .externallyManagedConfigMembers .contains (configMember ));
321
+ }
304
322
}
305
323
306
324
public void registerExternallyManagedInitMethod (String initMethod ) {
307
- this .externallyManagedInitMethods .put (initMethod , Boolean .TRUE );
325
+ synchronized (this .postProcessingLock ) {
326
+ if (this .externallyManagedInitMethods == null ) {
327
+ this .externallyManagedInitMethods = new HashSet <String >(1 );
328
+ }
329
+ this .externallyManagedInitMethods .add (initMethod );
330
+ }
308
331
}
309
332
310
333
public boolean isExternallyManagedInitMethod (String initMethod ) {
311
- return this .externallyManagedInitMethods .containsKey (initMethod );
334
+ synchronized (this .postProcessingLock ) {
335
+ return (this .externallyManagedInitMethods != null &&
336
+ this .externallyManagedInitMethods .contains (initMethod ));
337
+ }
312
338
}
313
339
314
340
public void registerExternallyManagedDestroyMethod (String destroyMethod ) {
315
- this .externallyManagedDestroyMethods .put (destroyMethod , Boolean .TRUE );
341
+ synchronized (this .postProcessingLock ) {
342
+ if (this .externallyManagedDestroyMethods == null ) {
343
+ this .externallyManagedDestroyMethods = new HashSet <String >(1 );
344
+ }
345
+ this .externallyManagedDestroyMethods .add (destroyMethod );
346
+ }
316
347
}
317
348
318
349
public boolean isExternallyManagedDestroyMethod (String destroyMethod ) {
319
- return this .externallyManagedDestroyMethods .containsKey (destroyMethod );
320
- }
321
-
322
- public void setDecoratedDefinition (BeanDefinitionHolder decoratedDefinition ) {
323
- this .decoratedDefinition = decoratedDefinition ;
324
- }
325
-
326
- public BeanDefinitionHolder getDecoratedDefinition () {
327
- return this .decoratedDefinition ;
350
+ synchronized (this .postProcessingLock ) {
351
+ return (this .externallyManagedDestroyMethods != null &&
352
+ this .externallyManagedDestroyMethods .contains (destroyMethod ));
353
+ }
328
354
}
329
355
330
356
0 commit comments