1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 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.
@@ -184,10 +184,10 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
184
184
private MethodOverrides methodOverrides = new MethodOverrides ();
185
185
186
186
@ Nullable
187
- private String initMethodName ;
187
+ private String [] initMethodNames ;
188
188
189
189
@ Nullable
190
- private String destroyMethodName ;
190
+ private String [] destroyMethodNames ;
191
191
192
192
private boolean enforceInitMethod = true ;
193
193
@@ -262,9 +262,9 @@ protected AbstractBeanDefinition(BeanDefinition original) {
262
262
setInstanceSupplier (originalAbd .getInstanceSupplier ());
263
263
setNonPublicAccessAllowed (originalAbd .isNonPublicAccessAllowed ());
264
264
setLenientConstructorResolution (originalAbd .isLenientConstructorResolution ());
265
- setInitMethodName (originalAbd .getInitMethodName ());
265
+ setInitMethodNames (originalAbd .getInitMethodNames ());
266
266
setEnforceInitMethod (originalAbd .isEnforceInitMethod ());
267
- setDestroyMethodName (originalAbd .getDestroyMethodName ());
267
+ setDestroyMethodNames (originalAbd .getDestroyMethodNames ());
268
268
setEnforceDestroyMethod (originalAbd .isEnforceDestroyMethod ());
269
269
setSynthetic (originalAbd .isSynthetic ());
270
270
setResource (originalAbd .getResource ());
@@ -338,12 +338,12 @@ public void overrideFrom(BeanDefinition other) {
338
338
setInstanceSupplier (otherAbd .getInstanceSupplier ());
339
339
setNonPublicAccessAllowed (otherAbd .isNonPublicAccessAllowed ());
340
340
setLenientConstructorResolution (otherAbd .isLenientConstructorResolution ());
341
- if (otherAbd .getInitMethodName () != null ) {
342
- setInitMethodName (otherAbd .getInitMethodName ());
341
+ if (otherAbd .getInitMethodNames () != null ) {
342
+ setInitMethodNames (otherAbd .getInitMethodNames ());
343
343
setEnforceInitMethod (otherAbd .isEnforceInitMethod ());
344
344
}
345
- if (otherAbd .getDestroyMethodName () != null ) {
346
- setDestroyMethodName (otherAbd .getDestroyMethodName ());
345
+ if (otherAbd .getDestroyMethodNames () != null ) {
346
+ setDestroyMethodNames (otherAbd .getDestroyMethodNames ());
347
347
setEnforceDestroyMethod (otherAbd .isEnforceDestroyMethod ());
348
348
}
349
349
setSynthetic (otherAbd .isSynthetic ());
@@ -918,22 +918,42 @@ public boolean hasMethodOverrides() {
918
918
return !this .methodOverrides .isEmpty ();
919
919
}
920
920
921
+ /**
922
+ * Specify the names of multiple initializer methods.
923
+ * <p>The default is {@code null} in which case there are no initializer methods.
924
+ * @since 6.0
925
+ * @see #setInitMethodName
926
+ */
927
+ public void setInitMethodNames (@ Nullable String ... initMethodNames ) {
928
+ this .initMethodNames = initMethodNames ;
929
+ }
930
+
931
+ /**
932
+ * Return the names of the initializer methods.
933
+ * @since 6.0
934
+ */
935
+ @ Nullable
936
+ public String [] getInitMethodNames () {
937
+ return this .initMethodNames ;
938
+ }
939
+
921
940
/**
922
941
* Set the name of the initializer method.
923
942
* <p>The default is {@code null} in which case there is no initializer method.
943
+ * @see #setInitMethodNames
924
944
*/
925
945
@ Override
926
946
public void setInitMethodName (@ Nullable String initMethodName ) {
927
- this .initMethodName = initMethodName ;
947
+ this .initMethodNames = ( initMethodName != null ? new String [] { initMethodName } : null ) ;
928
948
}
929
949
930
950
/**
931
- * Return the name of the initializer method.
951
+ * Return the name of the initializer method (the first one in case of multiple methods) .
932
952
*/
933
953
@ Override
934
954
@ Nullable
935
955
public String getInitMethodName () {
936
- return this .initMethodName ;
956
+ return (! ObjectUtils . isEmpty ( this .initMethodNames ) ? this . initMethodNames [ 0 ] : null ) ;
937
957
}
938
958
939
959
/**
@@ -957,22 +977,42 @@ public boolean isEnforceInitMethod() {
957
977
return this .enforceInitMethod ;
958
978
}
959
979
980
+ /**
981
+ * Specify the names of multiple destroy methods.
982
+ * <p>The default is {@code null} in which case there are no destroy methods.
983
+ * @since 6.0
984
+ * @see #setDestroyMethodName
985
+ */
986
+ public void setDestroyMethodNames (@ Nullable String ... destroyMethodNames ) {
987
+ this .destroyMethodNames = destroyMethodNames ;
988
+ }
989
+
990
+ /**
991
+ * Return the names of the destroy methods.
992
+ * @since 6.0
993
+ */
994
+ @ Nullable
995
+ public String [] getDestroyMethodNames () {
996
+ return this .destroyMethodNames ;
997
+ }
998
+
960
999
/**
961
1000
* Set the name of the destroy method.
962
1001
* <p>The default is {@code null} in which case there is no destroy method.
1002
+ * @see #setDestroyMethodNames
963
1003
*/
964
1004
@ Override
965
1005
public void setDestroyMethodName (@ Nullable String destroyMethodName ) {
966
- this .destroyMethodName = destroyMethodName ;
1006
+ this .destroyMethodNames = ( destroyMethodName != null ? new String [] { destroyMethodName } : null ) ;
967
1007
}
968
1008
969
1009
/**
970
- * Return the name of the destroy method.
1010
+ * Return the name of the destroy method (the first one in case of multiple methods) .
971
1011
*/
972
1012
@ Override
973
1013
@ Nullable
974
1014
public String getDestroyMethodName () {
975
- return this .destroyMethodName ;
1015
+ return (! ObjectUtils . isEmpty ( this .destroyMethodNames ) ? this . destroyMethodNames [ 0 ] : null ) ;
976
1016
}
977
1017
978
1018
/**
@@ -1189,9 +1229,9 @@ public boolean equals(@Nullable Object other) {
1189
1229
ObjectUtils .nullSafeEquals (this .methodOverrides , that .methodOverrides ) &&
1190
1230
ObjectUtils .nullSafeEquals (this .factoryBeanName , that .factoryBeanName ) &&
1191
1231
ObjectUtils .nullSafeEquals (this .factoryMethodName , that .factoryMethodName ) &&
1192
- ObjectUtils .nullSafeEquals (this .initMethodName , that .initMethodName ) &&
1232
+ ObjectUtils .nullSafeEquals (this .initMethodNames , that .initMethodNames ) &&
1193
1233
this .enforceInitMethod == that .enforceInitMethod &&
1194
- ObjectUtils .nullSafeEquals (this .destroyMethodName , that .destroyMethodName ) &&
1234
+ ObjectUtils .nullSafeEquals (this .destroyMethodNames , that .destroyMethodNames ) &&
1195
1235
this .enforceDestroyMethod == that .enforceDestroyMethod &&
1196
1236
this .synthetic == that .synthetic &&
1197
1237
this .role == that .role &&
@@ -1241,8 +1281,8 @@ public String toString() {
1241
1281
sb .append ("; primary=" ).append (this .primary );
1242
1282
sb .append ("; factoryBeanName=" ).append (this .factoryBeanName );
1243
1283
sb .append ("; factoryMethodName=" ).append (this .factoryMethodName );
1244
- sb .append ("; initMethodName =" ).append (this .initMethodName );
1245
- sb .append ("; destroyMethodName =" ).append (this .destroyMethodName );
1284
+ sb .append ("; initMethodNames =" ).append (this .initMethodNames );
1285
+ sb .append ("; destroyMethodNames =" ).append (this .destroyMethodNames );
1246
1286
if (this .resource != null ) {
1247
1287
sb .append ("; defined in " ).append (this .resource .getDescription ());
1248
1288
}
0 commit comments