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 ;
@@ -342,11 +340,8 @@ private synchronized Object newPrototypeInstance() {
342
340
// an independent instance of the configuration.
343
341
// In this case, no proxy will have an instance of this object's configuration,
344
342
// but will have an independent copy.
345
- if (logger .isTraceEnabled ()) {
346
- logger .trace ("Creating copy of prototype ProxyFactoryBean config: " + this );
347
- }
348
-
349
343
ProxyCreatorSupport copy = new ProxyCreatorSupport (getAopProxyFactory ());
344
+
350
345
// The copy needs a fresh advisor chain, and a fresh TargetSource.
351
346
TargetSource targetSource = freshTargetSource ();
352
347
copy .copyConfigurationFrom (this , targetSource , freshAdvisorChain ());
@@ -359,9 +354,6 @@ private synchronized Object newPrototypeInstance() {
359
354
}
360
355
copy .setFrozen (this .freezeProxy );
361
356
362
- if (logger .isTraceEnabled ()) {
363
- logger .trace ("Using ProxyCreatorSupport copy: " + copy );
364
- }
365
357
return getProxy (copy .createAopProxy ());
366
358
}
367
359
@@ -447,16 +439,12 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
447
439
448
440
// Materialize interceptor chain from bean names.
449
441
for (String name : this .interceptorNames ) {
450
- if (logger .isTraceEnabled ()) {
451
- logger .trace ("Configuring advisor or advice '" + name + "'" );
452
- }
453
-
454
442
if (name .endsWith (GLOBAL_SUFFIX )) {
455
443
if (!(this .beanFactory instanceof ListableBeanFactory )) {
456
444
throw new AopConfigException (
457
445
"Can only use global advisors or interceptors with a ListableBeanFactory" );
458
446
}
459
- addGlobalAdvisor ((ListableBeanFactory ) this .beanFactory ,
447
+ addGlobalAdvisors ((ListableBeanFactory ) this .beanFactory ,
460
448
name .substring (0 , name .length () - GLOBAL_SUFFIX .length ()));
461
449
}
462
450
@@ -473,7 +461,7 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
473
461
// Avoid unnecessary creation of prototype bean just for advisor chain initialization.
474
462
advice = new PrototypePlaceholderAdvisor (name );
475
463
}
476
- addAdvisorOnChainCreation (advice , name );
464
+ addAdvisorOnChainCreation (advice );
477
465
}
478
466
}
479
467
}
@@ -496,11 +484,10 @@ private List<Advisor> freshAdvisorChain() {
496
484
if (logger .isDebugEnabled ()) {
497
485
logger .debug ("Refreshing bean named '" + pa .getBeanName () + "'" );
498
486
}
499
- // Replace the placeholder with a fresh prototype instance resulting
500
- // from a getBean() lookup
487
+ // Replace the placeholder with a fresh prototype instance resulting from a getBean lookup
501
488
if (this .beanFactory == null ) {
502
- throw new IllegalStateException ("No BeanFactory available anymore (probably due to serialization) " +
503
- "- cannot resolve prototype advisor '" + pa .getBeanName () + "'" );
489
+ throw new IllegalStateException ("No BeanFactory available anymore (probably due to " +
490
+ "serialization) - cannot resolve prototype advisor '" + pa .getBeanName () + "'" );
504
491
}
505
492
Object bean = this .beanFactory .getBean (pa .getBeanName ());
506
493
Advisor refreshedAdvisor = namedBeanToAdvisor (bean );
@@ -517,28 +504,26 @@ private List<Advisor> freshAdvisorChain() {
517
504
/**
518
505
* Add all global interceptors and pointcuts.
519
506
*/
520
- private void addGlobalAdvisor (ListableBeanFactory beanFactory , String prefix ) {
507
+ private void addGlobalAdvisors (ListableBeanFactory beanFactory , String prefix ) {
521
508
String [] globalAdvisorNames =
522
509
BeanFactoryUtils .beanNamesForTypeIncludingAncestors (beanFactory , Advisor .class );
523
510
String [] globalInterceptorNames =
524
511
BeanFactoryUtils .beanNamesForTypeIncludingAncestors (beanFactory , Interceptor .class );
525
- List <Object > beans = new ArrayList <>(globalAdvisorNames .length + globalInterceptorNames .length );
526
- Map <Object , String > names = new HashMap <>(beans .size ());
527
- for (String name : globalAdvisorNames ) {
528
- Object bean = beanFactory .getBean (name );
529
- beans .add (bean );
530
- names .put (bean , name );
531
- }
532
- for (String name : globalInterceptorNames ) {
533
- Object bean = beanFactory .getBean (name );
534
- beans .add (bean );
535
- names .put (bean , name );
536
- }
537
- AnnotationAwareOrderComparator .sort (beans );
538
- for (Object bean : beans ) {
539
- String name = names .get (bean );
540
- if (name .startsWith (prefix )) {
541
- addAdvisorOnChainCreation (bean , name );
512
+ if (globalAdvisorNames .length > 0 || globalInterceptorNames .length > 0 ) {
513
+ List <Object > beans = new ArrayList <>(globalAdvisorNames .length + globalInterceptorNames .length );
514
+ for (String name : globalAdvisorNames ) {
515
+ if (name .startsWith (prefix )) {
516
+ beans .add (beanFactory .getBean (name ));
517
+ }
518
+ }
519
+ for (String name : globalInterceptorNames ) {
520
+ if (name .startsWith (prefix )) {
521
+ beans .add (beanFactory .getBean (name ));
522
+ }
523
+ }
524
+ AnnotationAwareOrderComparator .sort (beans );
525
+ for (Object bean : beans ) {
526
+ addAdvisorOnChainCreation (bean );
542
527
}
543
528
}
544
529
}
@@ -549,17 +534,11 @@ private void addGlobalAdvisor(ListableBeanFactory beanFactory, String prefix) {
549
534
* Because of these three possibilities, we can't type the signature
550
535
* more strongly.
551
536
* @param next advice, advisor or target object
552
- * @param name bean name from which we obtained this object in our owning
553
- * bean factory
554
537
*/
555
- private void addAdvisorOnChainCreation (Object next , String name ) {
538
+ private void addAdvisorOnChainCreation (Object next ) {
556
539
// We need to convert to an Advisor if necessary so that our source reference
557
540
// matches what we find from superclass interceptors.
558
- Advisor advisor = namedBeanToAdvisor (next );
559
- if (logger .isTraceEnabled ()) {
560
- logger .trace ("Adding advisor with name '" + name + "'" );
561
- }
562
- addAdvisor (advisor );
541
+ addAdvisor (namedBeanToAdvisor (next ));
563
542
}
564
543
565
544
/**
@@ -570,9 +549,7 @@ private void addAdvisorOnChainCreation(Object next, String name) {
570
549
*/
571
550
private TargetSource freshTargetSource () {
572
551
if (this .targetName == null ) {
573
- if (logger .isTraceEnabled ()) {
574
- logger .trace ("Not refreshing target: Bean name not specified in 'interceptorNames'." );
575
- }
552
+ // Not refreshing target: bean name not specified in 'interceptorNames'
576
553
return this .targetSource ;
577
554
}
578
555
else {
@@ -612,7 +589,7 @@ private Advisor namedBeanToAdvisor(Object next) {
612
589
protected void adviceChanged () {
613
590
super .adviceChanged ();
614
591
if (this .singleton ) {
615
- logger .debug ("Advice has changed; recaching singleton instance" );
592
+ logger .debug ("Advice has changed; re-caching singleton instance" );
616
593
synchronized (this ) {
617
594
this .singletonInstance = null ;
618
595
}
0 commit comments