@@ -25,26 +25,13 @@ target different advice with the same pointcut.
25
25
The `org.springframework.aop.Pointcut` interface is the central interface, used to
26
26
target advices to particular classes and methods. The complete interface follows:
27
27
28
- [source,java,indent=0,subs="verbatim,quotes",role="primary"]
29
- .Java
28
+ [source,java,indent=0,subs="verbatim,quotes"]
30
29
----
31
30
public interface Pointcut {
32
31
33
32
ClassFilter getClassFilter();
34
33
35
34
MethodMatcher getMethodMatcher();
36
-
37
- }
38
- ----
39
- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
40
- .Kotlin
41
- ----
42
- interface Pointcut {
43
-
44
- fun getClassFilter(): ClassFilter
45
-
46
- fun getMethodMatcher(): MethodMatcher
47
-
48
35
}
49
36
----
50
37
@@ -56,27 +43,17 @@ The `ClassFilter` interface is used to restrict the pointcut to a given set of t
56
43
classes. If the `matches()` method always returns true, all target classes are
57
44
matched. The following listing shows the `ClassFilter` interface definition:
58
45
59
- [source,java,indent=0,subs="verbatim,quotes",role="primary"]
60
- .Java
46
+ [source,java,indent=0,subs="verbatim,quotes"]
61
47
----
62
48
public interface ClassFilter {
63
49
64
50
boolean matches(Class clazz);
65
51
}
66
52
----
67
- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
68
- .Kotlin
69
- ----
70
- interface ClassFilter {
71
-
72
- fun matches(clazz: Class<*>): Boolean
73
- }
74
- ----
75
53
76
54
The `MethodMatcher` interface is normally more important. The complete interface follows:
77
55
78
- [source,java,indent=0,subs="verbatim,quotes",role="primary"]
79
- .Java
56
+ [source,java,indent=0,subs="verbatim,quotes"]
80
57
----
81
58
public interface MethodMatcher {
82
59
@@ -87,18 +64,6 @@ The `MethodMatcher` interface is normally more important. The complete interface
87
64
boolean matches(Method m, Class targetClass, Object[] args);
88
65
}
89
66
----
90
- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
91
- .Kotlin
92
- ----
93
- interface MethodMatcher {
94
-
95
- val isRuntime: Boolean
96
-
97
- fun matches(m: Method, targetClass: Class<*>): Boolean
98
-
99
- fun matches(m: Method, targetClass: Class<*>, args: Array<Any>): Boolean
100
- }
101
- ----
102
67
103
68
The `matches(Method, Class)` method is used to test whether this pointcut ever
104
69
matches a given method on a target class. This evaluation can be performed when an AOP
@@ -335,22 +300,13 @@ Spring is compliant with the AOP `Alliance` interface for around advice that use
335
300
interception. Classes that implement `MethodInterceptor` and that implement around advice should also implement the
336
301
following interface:
337
302
338
- [source,java,indent=0,subs="verbatim,quotes",role="primary"]
339
- .Java
303
+ [source,java,indent=0,subs="verbatim,quotes"]
340
304
----
341
305
public interface MethodInterceptor extends Interceptor {
342
306
343
307
Object invoke(MethodInvocation invocation) throws Throwable;
344
308
}
345
309
----
346
- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
347
- .Kotlin
348
- ----
349
- interface MethodInterceptor : Interceptor {
350
-
351
- fun invoke(invocation: MethodInvocation) : Any
352
- }
353
- ----
354
310
355
311
The `MethodInvocation` argument to the `invoke()` method exposes the method being
356
312
invoked, the target join point, the AOP proxy, and the arguments to the method. The
@@ -413,22 +369,13 @@ interceptor chain.
413
369
414
370
The following listing shows the `MethodBeforeAdvice` interface:
415
371
416
- [source,java,indent=0,subs="verbatim,quotes",role="primary"]
417
- .Java
372
+ [source,java,indent=0,subs="verbatim,quotes"]
418
373
----
419
374
public interface MethodBeforeAdvice extends BeforeAdvice {
420
375
421
376
void before(Method m, Object[] args, Object target) throws Throwable;
422
377
}
423
378
----
424
- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
425
- .Kotlin
426
- ----
427
- interface MethodBeforeAdvice : BeforeAdvice {
428
-
429
- fun before(m: Method, args: Array<Any>, target: Any)
430
- }
431
- ----
432
379
433
380
(Spring's API design would allow for
434
381
field before advice, although the usual objects apply to field interception and it is
@@ -591,23 +538,14 @@ TIP: Throws advice can be used with any pointcut.
591
538
An after returning advice in Spring must implement the
592
539
`org.springframework.aop.AfterReturningAdvice` interface, which the following listing shows:
593
540
594
- [source,java,indent=0,subs="verbatim,quotes",role="primary"]
595
- .Java
541
+ [source,java,indent=0,subs="verbatim,quotes"]
596
542
----
597
543
public interface AfterReturningAdvice extends Advice {
598
544
599
545
void afterReturning(Object returnValue, Method m, Object[] args, Object target)
600
546
throws Throwable;
601
547
}
602
548
----
603
- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
604
- .Kotlin
605
- ----
606
- interface AfterReturningAdvice : Advice {
607
-
608
- fun afterReturning(returnValue: Any, m: Method, args: Array<Any>, target: Any)
609
- }
610
- ----
611
549
612
550
An after returning advice has access to the return value (which it cannot modify),
613
551
the invoked method, the method's arguments, and the target.
@@ -660,22 +598,13 @@ Spring treats introduction advice as a special kind of interception advice.
660
598
Introduction requires an `IntroductionAdvisor` and an `IntroductionInterceptor` that
661
599
implement the following interface:
662
600
663
- [source,java,indent=0,subs="verbatim,quotes",role="primary"]
664
- .Java
601
+ [source,java,indent=0,subs="verbatim,quotes"]
665
602
----
666
603
public interface IntroductionInterceptor extends MethodInterceptor {
667
604
668
605
boolean implementsInterface(Class intf);
669
606
}
670
607
----
671
- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
672
- .Kotlin
673
- ----
674
- interface IntroductionInterceptor : MethodInterceptor {
675
-
676
- fun implementsInterface(intf: Class<*>): Boolean
677
- }
678
- ----
679
608
680
609
The `invoke()` method inherited from the AOP Alliance `MethodInterceptor` interface must
681
610
implement the introduction. That is, if the invoked method is on an introduced
@@ -686,8 +615,7 @@ Introduction advice cannot be used with any pointcut, as it applies only at the
686
615
rather than the method, level. You can only use introduction advice with the
687
616
`IntroductionAdvisor`, which has the following methods:
688
617
689
- [source,java,indent=0,subs="verbatim,quotes",role="primary"]
690
- .Java
618
+ [source,java,indent=0,subs="verbatim,quotes"]
691
619
----
692
620
public interface IntroductionAdvisor extends Advisor, IntroductionInfo {
693
621
@@ -701,22 +629,6 @@ rather than the method, level. You can only use introduction advice with the
701
629
Class<?>[] getInterfaces();
702
630
}
703
631
----
704
- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
705
- .Kotlin
706
- ----
707
- interface IntroductionAdvisor : Advisor, IntroductionInfo {
708
-
709
- val classFilter: ClassFilter
710
-
711
- @Throws(IllegalArgumentException::class)
712
- fun validateInterfaces()
713
- }
714
-
715
- interface IntroductionInfo {
716
-
717
- val interfaces: Array<Class<*>>
718
- }
719
- ----
720
632
721
633
There is no `MethodMatcher` and, hence, no `Pointcut` associated with introduction
722
634
advice. Only class filtering is logical.
0 commit comments