1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2020 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.
21
21
import java .io .Serializable ;
22
22
import java .util .ArrayList ;
23
23
import java .util .Arrays ;
24
- import java .util .HashMap ;
25
24
import java .util .List ;
26
- import java .util .Map ;
27
25
28
26
import org .aopalliance .aop .Advice ;
29
27
import org .aopalliance .intercept .Interceptor ;
@@ -334,11 +332,8 @@ private synchronized Object newPrototypeInstance() {
334
332
// an independent instance of the configuration.
335
333
// In this case, no proxy will have an instance of this object's configuration,
336
334
// but will have an independent copy.
337
- if (logger .isTraceEnabled ()) {
338
- logger .trace ("Creating copy of prototype ProxyFactoryBean config: " + this );
339
- }
340
-
341
335
ProxyCreatorSupport copy = new ProxyCreatorSupport (getAopProxyFactory ());
336
+
342
337
// The copy needs a fresh advisor chain, and a fresh TargetSource.
343
338
TargetSource targetSource = freshTargetSource ();
344
339
copy .copyConfigurationFrom (this , targetSource , freshAdvisorChain ());
@@ -349,9 +344,6 @@ private synchronized Object newPrototypeInstance() {
349
344
}
350
345
copy .setFrozen (this .freezeProxy );
351
346
352
- if (logger .isTraceEnabled ()) {
353
- logger .trace ("Using ProxyCreatorSupport copy: " + copy );
354
- }
355
347
return getProxy (copy .createAopProxy ());
356
348
}
357
349
@@ -438,16 +430,12 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
438
430
439
431
// Materialize interceptor chain from bean names.
440
432
for (String name : this .interceptorNames ) {
441
- if (logger .isTraceEnabled ()) {
442
- logger .trace ("Configuring advisor or advice '" + name + "'" );
443
- }
444
-
445
433
if (name .endsWith (GLOBAL_SUFFIX )) {
446
434
if (!(this .beanFactory instanceof ListableBeanFactory )) {
447
435
throw new AopConfigException (
448
436
"Can only use global advisors or interceptors with a ListableBeanFactory" );
449
437
}
450
- addGlobalAdvisor ((ListableBeanFactory ) this .beanFactory ,
438
+ addGlobalAdvisors ((ListableBeanFactory ) this .beanFactory ,
451
439
name .substring (0 , name .length () - GLOBAL_SUFFIX .length ()));
452
440
}
453
441
@@ -464,7 +452,7 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
464
452
// Avoid unnecessary creation of prototype bean just for advisor chain initialization.
465
453
advice = new PrototypePlaceholderAdvisor (name );
466
454
}
467
- addAdvisorOnChainCreation (advice , name );
455
+ addAdvisorOnChainCreation (advice );
468
456
}
469
457
}
470
458
}
@@ -487,11 +475,10 @@ private List<Advisor> freshAdvisorChain() {
487
475
if (logger .isDebugEnabled ()) {
488
476
logger .debug ("Refreshing bean named '" + pa .getBeanName () + "'" );
489
477
}
490
- // Replace the placeholder with a fresh prototype instance resulting
491
- // from a getBean() lookup
478
+ // Replace the placeholder with a fresh prototype instance resulting from a getBean lookup
492
479
if (this .beanFactory == null ) {
493
- throw new IllegalStateException ("No BeanFactory available anymore (probably due to serialization) " +
494
- "- cannot resolve prototype advisor '" + pa .getBeanName () + "'" );
480
+ throw new IllegalStateException ("No BeanFactory available anymore (probably due to " +
481
+ "serialization) - cannot resolve prototype advisor '" + pa .getBeanName () + "'" );
495
482
}
496
483
Object bean = this .beanFactory .getBean (pa .getBeanName ());
497
484
Advisor refreshedAdvisor = namedBeanToAdvisor (bean );
@@ -508,28 +495,26 @@ private List<Advisor> freshAdvisorChain() {
508
495
/**
509
496
* Add all global interceptors and pointcuts.
510
497
*/
511
- private void addGlobalAdvisor (ListableBeanFactory beanFactory , String prefix ) {
498
+ private void addGlobalAdvisors (ListableBeanFactory beanFactory , String prefix ) {
512
499
String [] globalAdvisorNames =
513
500
BeanFactoryUtils .beanNamesForTypeIncludingAncestors (beanFactory , Advisor .class );
514
501
String [] globalInterceptorNames =
515
502
BeanFactoryUtils .beanNamesForTypeIncludingAncestors (beanFactory , Interceptor .class );
516
- List <Object > beans = new ArrayList <Object >(globalAdvisorNames .length + globalInterceptorNames .length );
517
- Map <Object , String > names = new HashMap <Object , String >(beans .size ());
518
- for (String name : globalAdvisorNames ) {
519
- Object bean = beanFactory .getBean (name );
520
- beans .add (bean );
521
- names .put (bean , name );
522
- }
523
- for (String name : globalInterceptorNames ) {
524
- Object bean = beanFactory .getBean (name );
525
- beans .add (bean );
526
- names .put (bean , name );
527
- }
528
- AnnotationAwareOrderComparator .sort (beans );
529
- for (Object bean : beans ) {
530
- String name = names .get (bean );
531
- if (name .startsWith (prefix )) {
532
- addAdvisorOnChainCreation (bean , name );
503
+ if (globalAdvisorNames .length > 0 || globalInterceptorNames .length > 0 ) {
504
+ List <Object > beans = new ArrayList <Object >(globalAdvisorNames .length + globalInterceptorNames .length );
505
+ for (String name : globalAdvisorNames ) {
506
+ if (name .startsWith (prefix )) {
507
+ beans .add (beanFactory .getBean (name ));
508
+ }
509
+ }
510
+ for (String name : globalInterceptorNames ) {
511
+ if (name .startsWith (prefix )) {
512
+ beans .add (beanFactory .getBean (name ));
513
+ }
514
+ }
515
+ AnnotationAwareOrderComparator .sort (beans );
516
+ for (Object bean : beans ) {
517
+ addAdvisorOnChainCreation (bean );
533
518
}
534
519
}
535
520
}
@@ -540,17 +525,11 @@ private void addGlobalAdvisor(ListableBeanFactory beanFactory, String prefix) {
540
525
* Because of these three possibilities, we can't type the signature
541
526
* more strongly.
542
527
* @param next advice, advisor or target object
543
- * @param name bean name from which we obtained this object in our owning
544
- * bean factory
545
528
*/
546
- private void addAdvisorOnChainCreation (Object next , String name ) {
529
+ private void addAdvisorOnChainCreation (Object next ) {
547
530
// We need to convert to an Advisor if necessary so that our source reference
548
531
// matches what we find from superclass interceptors.
549
- Advisor advisor = namedBeanToAdvisor (next );
550
- if (logger .isTraceEnabled ()) {
551
- logger .trace ("Adding advisor with name '" + name + "'" );
552
- }
553
- addAdvisor (advisor );
532
+ addAdvisor (namedBeanToAdvisor (next ));
554
533
}
555
534
556
535
/**
@@ -561,9 +540,7 @@ private void addAdvisorOnChainCreation(Object next, String name) {
561
540
*/
562
541
private TargetSource freshTargetSource () {
563
542
if (this .targetName == null ) {
564
- if (logger .isTraceEnabled ()) {
565
- logger .trace ("Not refreshing target: Bean name not specified in 'interceptorNames'." );
566
- }
543
+ // Not refreshing target: bean name not specified in 'interceptorNames'
567
544
return this .targetSource ;
568
545
}
569
546
else {
@@ -591,8 +568,8 @@ private Advisor namedBeanToAdvisor(Object next) {
591
568
// We expected this to be an Advisor or Advice,
592
569
// but it wasn't. This is a configuration error.
593
570
throw new AopConfigException ("Unknown advisor type " + next .getClass () +
594
- "; Can only include Advisor or Advice type beans in interceptorNames chain except for last entry, " +
595
- "which may also be target or TargetSource" , ex );
571
+ "; can only include Advisor or Advice type beans in interceptorNames chain " +
572
+ "except for last entry which may also be target instance or TargetSource" , ex );
596
573
}
597
574
}
598
575
@@ -603,7 +580,7 @@ private Advisor namedBeanToAdvisor(Object next) {
603
580
protected void adviceChanged () {
604
581
super .adviceChanged ();
605
582
if (this .singleton ) {
606
- logger .debug ("Advice has changed; recaching singleton instance" );
583
+ logger .debug ("Advice has changed; re-caching singleton instance" );
607
584
synchronized (this ) {
608
585
this .singletonInstance = null ;
609
586
}
0 commit comments