|
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.
|
|
49 | 49 | *
|
50 | 50 | * @author Rod Johnson
|
51 | 51 | * @author Juergen Hoeller
|
| 52 | + * @author Sam Brannen |
52 | 53 | * @see GenericBeanDefinition
|
53 | 54 | * @see ChildBeanDefinition
|
54 | 55 | */
|
@@ -479,6 +480,36 @@ public boolean isExternallyManagedInitMethod(String initMethod) {
|
479 | 480 | }
|
480 | 481 | }
|
481 | 482 |
|
| 483 | + /** |
| 484 | + * Determine if the given method name indicates an externally managed |
| 485 | + * initialization method, regardless of method visibility. |
| 486 | + * <p>In contrast to {@link #isExternallyManagedInitMethod(String)}, this |
| 487 | + * method also returns {@code true} if there is a {@code private} external |
| 488 | + * init method that has been |
| 489 | + * {@linkplain #registerExternallyManagedInitMethod(String) registered} |
| 490 | + * using a fully qualified method name instead of a simple method name. |
| 491 | + * @since 5.3.17 |
| 492 | + */ |
| 493 | + boolean hasAnyExternallyManagedInitMethod(String initMethod) { |
| 494 | + synchronized (this.postProcessingLock) { |
| 495 | + if (isExternallyManagedInitMethod(initMethod)) { |
| 496 | + return true; |
| 497 | + } |
| 498 | + if (this.externallyManagedInitMethods != null) { |
| 499 | + for (String candidate : this.externallyManagedInitMethods) { |
| 500 | + int indexOfDot = candidate.lastIndexOf("."); |
| 501 | + if (indexOfDot >= 0) { |
| 502 | + String methodName = candidate.substring(indexOfDot + 1); |
| 503 | + if (methodName.equals(initMethod)) { |
| 504 | + return true; |
| 505 | + } |
| 506 | + } |
| 507 | + } |
| 508 | + } |
| 509 | + return false; |
| 510 | + } |
| 511 | + } |
| 512 | + |
482 | 513 | /**
|
483 | 514 | * Return all externally managed initialization methods (as an immutable Set).
|
484 | 515 | * @since 5.3.11
|
@@ -513,6 +544,36 @@ public boolean isExternallyManagedDestroyMethod(String destroyMethod) {
|
513 | 544 | }
|
514 | 545 | }
|
515 | 546 |
|
| 547 | + /** |
| 548 | + * Determine if the given method name indicates an externally managed |
| 549 | + * destruction method, regardless of method visibility. |
| 550 | + * <p>In contrast to {@link #isExternallyManagedDestroyMethod(String)}, this |
| 551 | + * method also returns {@code true} if there is a {@code private} external |
| 552 | + * destroy method that has been |
| 553 | + * {@linkplain #registerExternallyManagedDestroyMethod(String) registered} |
| 554 | + * using a fully qualified method name instead of a simple method name. |
| 555 | + * @since 5.3.17 |
| 556 | + */ |
| 557 | + boolean hasAnyExternallyManagedDestroyMethod(String destroyMethod) { |
| 558 | + synchronized (this.postProcessingLock) { |
| 559 | + if (isExternallyManagedDestroyMethod(destroyMethod)) { |
| 560 | + return true; |
| 561 | + } |
| 562 | + if (this.externallyManagedDestroyMethods != null) { |
| 563 | + for (String candidate : this.externallyManagedDestroyMethods) { |
| 564 | + int indexOfDot = candidate.lastIndexOf("."); |
| 565 | + if (indexOfDot >= 0) { |
| 566 | + String methodName = candidate.substring(indexOfDot + 1); |
| 567 | + if (methodName.equals(destroyMethod)) { |
| 568 | + return true; |
| 569 | + } |
| 570 | + } |
| 571 | + } |
| 572 | + } |
| 573 | + return false; |
| 574 | + } |
| 575 | + } |
| 576 | + |
516 | 577 | /**
|
517 | 578 | * Return all externally managed destruction methods (as an immutable Set).
|
518 | 579 | * @since 5.3.11
|
|
0 commit comments