1
1
/*
2
- * Copyright 2002-2018 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 ;
@@ -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
@@ -395,9 +387,7 @@ private void checkInterceptorNames() {
395
387
logger .debug ("Bean with name '" + finalName + "' concluding interceptor chain " +
396
388
"is not an advisor class: treating it as a target or TargetSource" );
397
389
}
398
- String [] newNames = new String [this .interceptorNames .length - 1 ];
399
- System .arraycopy (this .interceptorNames , 0 , newNames , 0 , newNames .length );
400
- this .interceptorNames = newNames ;
390
+ this .interceptorNames = Arrays .copyOf (this .interceptorNames , this .interceptorNames .length - 1 );
401
391
}
402
392
}
403
393
}
@@ -449,16 +439,12 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
449
439
450
440
// Materialize interceptor chain from bean names.
451
441
for (String name : this .interceptorNames ) {
452
- if (logger .isTraceEnabled ()) {
453
- logger .trace ("Configuring advisor or advice '" + name + "'" );
454
- }
455
-
456
442
if (name .endsWith (GLOBAL_SUFFIX )) {
457
443
if (!(this .beanFactory instanceof ListableBeanFactory )) {
458
444
throw new AopConfigException (
459
445
"Can only use global advisors or interceptors with a ListableBeanFactory" );
460
446
}
461
- addGlobalAdvisor ((ListableBeanFactory ) this .beanFactory ,
447
+ addGlobalAdvisors ((ListableBeanFactory ) this .beanFactory ,
462
448
name .substring (0 , name .length () - GLOBAL_SUFFIX .length ()));
463
449
}
464
450
@@ -475,7 +461,7 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
475
461
// Avoid unnecessary creation of prototype bean just for advisor chain initialization.
476
462
advice = new PrototypePlaceholderAdvisor (name );
477
463
}
478
- addAdvisorOnChainCreation (advice , name );
464
+ addAdvisorOnChainCreation (advice );
479
465
}
480
466
}
481
467
}
@@ -498,11 +484,10 @@ private List<Advisor> freshAdvisorChain() {
498
484
if (logger .isDebugEnabled ()) {
499
485
logger .debug ("Refreshing bean named '" + pa .getBeanName () + "'" );
500
486
}
501
- // Replace the placeholder with a fresh prototype instance resulting
502
- // from a getBean() lookup
487
+ // Replace the placeholder with a fresh prototype instance resulting from a getBean lookup
503
488
if (this .beanFactory == null ) {
504
- throw new IllegalStateException ("No BeanFactory available anymore (probably due to serialization) " +
505
- "- 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 () + "'" );
506
491
}
507
492
Object bean = this .beanFactory .getBean (pa .getBeanName ());
508
493
Advisor refreshedAdvisor = namedBeanToAdvisor (bean );
@@ -519,28 +504,26 @@ private List<Advisor> freshAdvisorChain() {
519
504
/**
520
505
* Add all global interceptors and pointcuts.
521
506
*/
522
- private void addGlobalAdvisor (ListableBeanFactory beanFactory , String prefix ) {
507
+ private void addGlobalAdvisors (ListableBeanFactory beanFactory , String prefix ) {
523
508
String [] globalAdvisorNames =
524
509
BeanFactoryUtils .beanNamesForTypeIncludingAncestors (beanFactory , Advisor .class );
525
510
String [] globalInterceptorNames =
526
511
BeanFactoryUtils .beanNamesForTypeIncludingAncestors (beanFactory , Interceptor .class );
527
- List <Object > beans = new ArrayList <>(globalAdvisorNames .length + globalInterceptorNames .length );
528
- Map <Object , String > names = new HashMap <>(beans .size ());
529
- for (String name : globalAdvisorNames ) {
530
- Object bean = beanFactory .getBean (name );
531
- beans .add (bean );
532
- names .put (bean , name );
533
- }
534
- for (String name : globalInterceptorNames ) {
535
- Object bean = beanFactory .getBean (name );
536
- beans .add (bean );
537
- names .put (bean , name );
538
- }
539
- AnnotationAwareOrderComparator .sort (beans );
540
- for (Object bean : beans ) {
541
- String name = names .get (bean );
542
- if (name .startsWith (prefix )) {
543
- 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 );
544
527
}
545
528
}
546
529
}
@@ -551,17 +534,11 @@ private void addGlobalAdvisor(ListableBeanFactory beanFactory, String prefix) {
551
534
* Because of these three possibilities, we can't type the signature
552
535
* more strongly.
553
536
* @param next advice, advisor or target object
554
- * @param name bean name from which we obtained this object in our owning
555
- * bean factory
556
537
*/
557
- private void addAdvisorOnChainCreation (Object next , String name ) {
538
+ private void addAdvisorOnChainCreation (Object next ) {
558
539
// We need to convert to an Advisor if necessary so that our source reference
559
540
// matches what we find from superclass interceptors.
560
- Advisor advisor = namedBeanToAdvisor (next );
561
- if (logger .isTraceEnabled ()) {
562
- logger .trace ("Adding advisor with name '" + name + "'" );
563
- }
564
- addAdvisor (advisor );
541
+ addAdvisor (namedBeanToAdvisor (next ));
565
542
}
566
543
567
544
/**
@@ -572,9 +549,7 @@ private void addAdvisorOnChainCreation(Object next, String name) {
572
549
*/
573
550
private TargetSource freshTargetSource () {
574
551
if (this .targetName == null ) {
575
- if (logger .isTraceEnabled ()) {
576
- logger .trace ("Not refreshing target: Bean name not specified in 'interceptorNames'." );
577
- }
552
+ // Not refreshing target: bean name not specified in 'interceptorNames'
578
553
return this .targetSource ;
579
554
}
580
555
else {
@@ -602,8 +577,8 @@ private Advisor namedBeanToAdvisor(Object next) {
602
577
// We expected this to be an Advisor or Advice,
603
578
// but it wasn't. This is a configuration error.
604
579
throw new AopConfigException ("Unknown advisor type " + next .getClass () +
605
- "; Can only include Advisor or Advice type beans in interceptorNames chain except for last entry, " +
606
- "which may also be target or TargetSource" , ex );
580
+ "; can only include Advisor or Advice type beans in interceptorNames chain " +
581
+ "except for last entry which may also be target instance or TargetSource" , ex );
607
582
}
608
583
}
609
584
@@ -614,7 +589,7 @@ private Advisor namedBeanToAdvisor(Object next) {
614
589
protected void adviceChanged () {
615
590
super .adviceChanged ();
616
591
if (this .singleton ) {
617
- logger .debug ("Advice has changed; recaching singleton instance" );
592
+ logger .debug ("Advice has changed; re-caching singleton instance" );
618
593
synchronized (this ) {
619
594
this .singletonInstance = null ;
620
595
}
0 commit comments