Skip to content

Commit 52c2ca6

Browse files
committed
Polish AOP reference documentation
- fix formatting - fix syntax - use consistent example package name
1 parent 35582de commit 52c2ca6

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

src/docs/asciidoc/core/core-aop.adoc

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ pointcut expressions by name. The following example shows three pointcut express
484484
@Pointcut("execution(public * \*(..))")
485485
private void anyPublicOperation() {} // <1>
486486
487-
@Pointcut("within(com.xyz.someapp.trading..*)")
487+
@Pointcut("within(com.xyz.myapp.trading..*)")
488488
private void inTrading() {} // <2>
489489
490490
@Pointcut("anyPublicOperation() && inTrading()")
@@ -502,7 +502,7 @@ trading module.
502502
@Pointcut("execution(public * \*(..))")
503503
private fun anyPublicOperation() {} // <1>
504504
505-
@Pointcut("within(com.xyz.someapp.trading..*)")
505+
@Pointcut("within(com.xyz.myapp.trading..*)")
506506
private fun inTrading() {} // <2>
507507
508508
@Pointcut("anyPublicOperation() && inTrading()")
@@ -526,13 +526,13 @@ matching.
526526

527527
When working with enterprise applications, developers often want to refer to modules of the
528528
application and particular sets of operations from within several aspects. We recommend
529-
defining a "`SystemArchitecture`" aspect that captures common pointcut expressions for
529+
defining a `SystemArchitecture` aspect that captures common pointcut expressions for
530530
this purpose. Such an aspect typically resembles the following example:
531531

532532
[source,java,indent=0,subs="verbatim",role="primary"]
533533
.Java
534534
----
535-
package com.xyz.someapp;
535+
package com.xyz.myapp;
536536
537537
import org.aspectj.lang.annotation.Aspect;
538538
import org.aspectj.lang.annotation.Pointcut;
@@ -542,26 +542,26 @@ this purpose. Such an aspect typically resembles the following example:
542542
543543
/**
544544
* A join point is in the web layer if the method is defined
545-
* in a type in the com.xyz.someapp.web package or any sub-package
545+
* in a type in the com.xyz.myapp.web package or any sub-package
546546
* under that.
547547
*/
548-
@Pointcut("within(com.xyz.someapp.web..*)")
548+
@Pointcut("within(com.xyz.myapp.web..*)")
549549
public void inWebLayer() {}
550550
551551
/**
552552
* A join point is in the service layer if the method is defined
553-
* in a type in the com.xyz.someapp.service package or any sub-package
553+
* in a type in the com.xyz.myapp.service package or any sub-package
554554
* under that.
555555
*/
556-
@Pointcut("within(com.xyz.someapp.service..*)")
556+
@Pointcut("within(com.xyz.myapp.service..*)")
557557
public void inServiceLayer() {}
558558
559559
/**
560560
* A join point is in the data access layer if the method is defined
561-
* in a type in the com.xyz.someapp.dao package or any sub-package
561+
* in a type in the com.xyz.myapp.dao package or any sub-package
562562
* under that.
563563
*/
564-
@Pointcut("within(com.xyz.someapp.dao..*)")
564+
@Pointcut("within(com.xyz.myapp.dao..*)")
565565
public void inDataAccessLayer() {}
566566
567567
/**
@@ -570,31 +570,31 @@ this purpose. Such an aspect typically resembles the following example:
570570
* "service" package, and that implementation types are in sub-packages.
571571
*
572572
* If you group service interfaces by functional area (for example,
573-
* in packages com.xyz.someapp.abc.service and com.xyz.someapp.def.service) then
574-
* the pointcut expression "execution(* com.xyz.someapp..service.*.*(..))"
573+
* in packages com.xyz.myapp.abc.service and com.xyz.myapp.def.service) then
574+
* the pointcut expression "execution(* com.xyz.myapp..service.*.*(..))"
575575
* could be used instead.
576576
*
577577
* Alternatively, you can write the expression using the 'bean'
578578
* PCD, like so "bean(*Service)". (This assumes that you have
579579
* named your Spring service beans in a consistent fashion.)
580580
*/
581-
@Pointcut("execution(* com.xyz.someapp..service.*.*(..))")
581+
@Pointcut("execution(* com.xyz.myapp..service.*.*(..))")
582582
public void businessService() {}
583583
584584
/**
585585
* A data access operation is the execution of any method defined on a
586586
* dao interface. This definition assumes that interfaces are placed in the
587587
* "dao" package, and that implementation types are in sub-packages.
588588
*/
589-
@Pointcut("execution(* com.xyz.someapp.dao.*.*(..))")
589+
@Pointcut("execution(* com.xyz.myapp.dao.*.*(..))")
590590
public void dataAccessOperation() {}
591591
592592
}
593593
----
594594
[source,kotlin,indent=0,subs="verbatim",role="secondary"]
595595
.Kotlin
596596
----
597-
package com.xyz.someapp
597+
package com.xyz.myapp
598598
599599
import org.aspectj.lang.annotation.Aspect
600600
import org.aspectj.lang.annotation.Pointcut
@@ -606,28 +606,28 @@ this purpose. Such an aspect typically resembles the following example:
606606
607607
/**
608608
* A join point is in the web layer if the method is defined
609-
* in a type in the com.xyz.someapp.web package or any sub-package
609+
* in a type in the com.xyz.myapp.web package or any sub-package
610610
* under that.
611611
*/
612-
@Pointcut("within(com.xyz.someapp.web..*)")
612+
@Pointcut("within(com.xyz.myapp.web..*)")
613613
fun inWebLayer() {
614614
}
615615
616616
/**
617617
* A join point is in the service layer if the method is defined
618-
* in a type in the com.xyz.someapp.service package or any sub-package
618+
* in a type in the com.xyz.myapp.service package or any sub-package
619619
* under that.
620620
*/
621-
@Pointcut("within(com.xyz.someapp.service..*)")
621+
@Pointcut("within(com.xyz.myapp.service..*)")
622622
fun inServiceLayer() {
623623
}
624624
625625
/**
626626
* A join point is in the data access layer if the method is defined
627-
* in a type in the com.xyz.someapp.dao package or any sub-package
627+
* in a type in the com.xyz.myapp.dao package or any sub-package
628628
* under that.
629629
*/
630-
@Pointcut("within(com.xyz.someapp.dao..*)")
630+
@Pointcut("within(com.xyz.myapp.dao..*)")
631631
fun inDataAccessLayer() {
632632
}
633633
@@ -637,15 +637,15 @@ this purpose. Such an aspect typically resembles the following example:
637637
* "service" package, and that implementation types are in sub-packages.
638638
*
639639
* If you group service interfaces by functional area (for example,
640-
* in packages com.xyz.someapp.abc.service and com.xyz.someapp.def.service) then
641-
* the pointcut expression "execution(* com.xyz.someapp..service.*.*(..))"
640+
* in packages com.xyz.myapp.abc.service and com.xyz.myapp.def.service) then
641+
* the pointcut expression "execution(* com.xyz.myapp..service.*.*(..))"
642642
* could be used instead.
643643
*
644644
* Alternatively, you can write the expression using the 'bean'
645645
* PCD, like so "bean(*Service)". (This assumes that you have
646646
* named your Spring service beans in a consistent fashion.)
647647
*/
648-
@Pointcut("execution(* com.xyz.someapp..service.*.*(..))")
648+
@Pointcut("execution(* com.xyz.myapp..service.*.*(..))")
649649
fun businessService() {
650650
}
651651
@@ -654,7 +654,7 @@ this purpose. Such an aspect typically resembles the following example:
654654
* dao interface. This definition assumes that interfaces are placed in the
655655
* "dao" package, and that implementation types are in sub-packages.
656656
*/
657-
@Pointcut("execution(* com.xyz.someapp.dao.*.*(..))")
657+
@Pointcut("execution(* com.xyz.myapp.dao.*.*(..))")
658658
fun dataAccessOperation() {
659659
}
660660
@@ -669,7 +669,7 @@ write the following:
669669
----
670670
<aop:config>
671671
<aop:advisor
672-
pointcut="com.xyz.someapp.SystemArchitecture.businessService()"
672+
pointcut="com.xyz.myapp.SystemArchitecture.businessService()"
673673
advice-ref="tx-advice"/>
674674
</aop:config>
675675
@@ -1057,7 +1057,9 @@ the following example shows:
10571057
@Aspect
10581058
class AfterReturningExample {
10591059
1060-
@AfterReturning(pointcut = "com.xyz.myapp.SystemArchitecture.dataAccessOperation()", returning = "retVal")
1060+
@AfterReturning(
1061+
pointcut = "com.xyz.myapp.SystemArchitecture.dataAccessOperation()",
1062+
returning = "retVal")
10611063
fun doAccessCheck(retVal: Any) {
10621064
// ...
10631065
}
@@ -1148,7 +1150,9 @@ following example shows how to do so:
11481150
@Aspect
11491151
class AfterThrowingExample {
11501152
1151-
@AfterThrowing(pointcut = "com.xyz.myapp.SystemArchitecture.dataAccessOperation()", throwing = "ex")
1153+
@AfterThrowing(
1154+
pointcut = "com.xyz.myapp.SystemArchitecture.dataAccessOperation()",
1155+
throwing = "ex")
11521156
fun doRecoveryActions(ex: DataAccessException) {
11531157
// ...
11541158
}
@@ -1744,8 +1748,8 @@ it until later.
17441748
By default, there is a single instance of each aspect within the application
17451749
context. AspectJ calls this the singleton instantiation model. It is possible to define
17461750
aspects with alternate lifecycles. Spring supports AspectJ's `perthis` and `pertarget`
1747-
instantiation models ( `percflow, percflowbelow,` and `pertypewithin` are not currently
1748-
supported).
1751+
instantiation models; `percflow`, `percflowbelow`, and `pertypewithin` are not currently
1752+
supported.
17491753

17501754
You can declare a `perthis` aspect by specifying a `perthis` clause in the `@Aspect`
17511755
annotation. Consider the following example:
@@ -1758,7 +1762,7 @@ annotation. Consider the following example:
17581762
17591763
private int someState;
17601764
1761-
@Before(com.xyz.myapp.SystemArchitecture.businessService())
1765+
@Before("com.xyz.myapp.SystemArchitecture.businessService()")
17621766
public void recordServiceUsage() {
17631767
// ...
17641768
}
@@ -1773,23 +1777,23 @@ annotation. Consider the following example:
17731777
17741778
private val someState: Int = 0
17751779
1776-
@Before(com.xyz.myapp.SystemArchitecture.businessService())
1780+
@Before("com.xyz.myapp.SystemArchitecture.businessService()")
17771781
fun recordServiceUsage() {
17781782
// ...
17791783
}
17801784
17811785
}
17821786
----
17831787

1784-
In the preceding example, the effect of the `'perthis'` clause is that one aspect instance is created for
1785-
each unique service object that executes a business service (each unique object bound to
1786-
'this' at join points matched by the pointcut expression). The aspect instance is
1787-
created the first time that a method is invoked on the service object. The aspect goes
1788-
out of scope when the service object goes out of scope. Before the aspect instance is
1789-
created, none of the advice within it executes. As soon as the aspect instance has been
1790-
created, the advice declared within it executes at matched join points, but only
1791-
when the service object is the one with which this aspect is associated. See the AspectJ
1792-
Programming Guide for more information on `per` clauses.
1788+
In the preceding example, the effect of the `'perthis'` clause is that one aspect
1789+
instance is created for each unique service object that executes a business service (each
1790+
unique object bound to 'this' at join points matched by the pointcut expression). The
1791+
aspect instance is created the first time that a method is invoked on the service object.
1792+
The aspect goes out of scope when the service object goes out of scope. Before the aspect
1793+
instance is created, none of the advice within it executes. As soon as the aspect
1794+
instance has been created, the advice declared within it executes at matched join points,
1795+
but only when the service object is the one with which this aspect is associated. See the
1796+
AspectJ Programming Guide for more information on `per` clauses.
17931797

17941798
The `pertarget` instantiation model works in exactly the same way as `perthis`, but it
17951799
creates one aspect instance for each unique target object at matched join points.
@@ -1949,7 +1953,8 @@ expression so that only `@Idempotent` operations match, as follows:
19491953
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
19501954
.Kotlin
19511955
----
1952-
@Around("com.xyz.myapp.SystemArchitecture.businessService() && " + "@annotation(com.xyz.myapp.service.Idempotent)")
1956+
@Around("com.xyz.myapp.SystemArchitecture.businessService() && " +
1957+
"@annotation(com.xyz.myapp.service.Idempotent)")
19531958
fun doConcurrentOperation(pjp: ProceedingJoinPoint): Any {
19541959
// ...
19551960
}

0 commit comments

Comments
 (0)