Aspectj in Action: Enterprise AOP with Spring Applications [2 ed.] 9781933988054, 1933988053

To allow the creation of truly modular software, OOP has evolved into aspect-oriented programming. AspectJ is a mature A

369 114 4MB

English Pages 567 Year 2009

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Front cover......Page 1
brief contents......Page 8
contents......Page 10
foreword......Page 20
preface......Page 24
preface to the first edition......Page 26
acknowledgments......Page 28
Roadmap......Page 30
Who should read this book......Page 32
Author online......Page 33
About the author......Page 34
about the title......Page 35
about the cover illustration......Page 36
Mapping AOP onto the hype cycle......Page 38
Peak of inflated expectations......Page 39
Trough of disillusionment......Page 40
Slope of enlightenment......Page 41
Enterprise applications......Page 44
Monitoring tools......Page 45
Compiler and IDE integration......Page 46
Understanding AOP and AspectJ......Page 48
Discovering AOP......Page 50
1.1 Life without AOP......Page 51
1.1.1 Code tangling......Page 52
1.2 Modularizing with AOP......Page 54
1.3.1 The AOP language specification......Page 56
1.3.2 The AOP language implementation......Page 57
1.4 Fundamental concepts in AOP......Page 58
1.5.1 Cascading Style Sheets (CSS)......Page 60
1.5.2 Database systems......Page 61
1.6.1 AspectJ......Page 62
1.6.2 Spring AOP......Page 63
1.7.1 Frameworks......Page 64
1.7.2 Code generation......Page 65
1.7.3 Design patterns......Page 66
1.7.4 Dynamic languages......Page 69
1.8.1 Costs of AOP......Page 70
1.8.2 Benefits of AOP......Page 71
1.9 Summary......Page 72
Introducing AspectJ......Page 74
2.1.1 Setting up the example......Page 75
2.1.2 Adding an aspect......Page 76
2.2.1 Common crosscutting constructs......Page 78
2.2.2 Dynamic crosscutting construct: advice......Page 79
2.2.3 Static crosscutting constructs......Page 81
2.3 AspectJ alternative syntax......Page 84
2.4.2 Binary weaving......Page 86
2.4.3 Load-time weaving......Page 88
2.5 AspectJ weaving: under the hood......Page 89
2.5.2 The woven class......Page 90
2.6 Spring AspectJ integration......Page 91
2.7.1 IDE integration......Page 93
2.7.2 AspectJ documentation tool......Page 95
2.8 Summary......Page 96
Understanding the join point model......Page 98
3.1 Understanding the join point model......Page 99
3.1.1 Join points......Page 100
3.1.2 Pointcuts......Page 101
3.2 Categorizing exposed join points......Page 102
3.2.1 Method join points......Page 103
3.2.2 Constructor join points......Page 104
3.2.3 Field access join points......Page 105
3.2.5 Class-initialization join points......Page 106
3.2.7 Object pre-initialization join points......Page 107
3.3.1 The aspect......Page 108
3.3.2 The result......Page 109
3.4.1 Named and anonymous pointcuts......Page 111
3.5 Signature syntax......Page 112
3.5.1 Type signature patterns......Page 113
3.5.2 Method and constructor signature patterns......Page 116
3.5.3 Field signature patterns......Page 120
3.6.1 Kinded pointcuts......Page 122
3.6.2 Non-kinded pointcuts......Page 124
3.7 Summary......Page 132
Modifying behavior with dynamic crosscutting......Page 134
4.1.2 Advice syntax......Page 135
4.2.1 Similarities between advice and methods......Page 137
4.2.2 Differences between advice and methods......Page 138
4.3.2 After advice......Page 139
4.3.3 Around advice......Page 141
4.4.1 Collecting objects at the join point......Page 146
4.4.2 Implementing simple caching......Page 149
4.5 Accessing join point context via reflection......Page 152
4.5.1 The reflection API......Page 153
4.5.2 Improving caching using reflection APIs......Page 156
4.5.3 Comparing the reflection API to pointcuts......Page 160
4.6 Summary......Page 162
Modifying structure with static crosscutting......Page 163
5.1.1 Scattering and tangling......Page 164
5.1.2 Untangling with aspects......Page 165
5.1.3 Mixing with mixins......Page 168
5.1.4 Member introduction rules......Page 170
5.1.5 Idiom: Providing a default interface implementation......Page 171
5.2 Modifying the type hierarchy......Page 175
5.3 Introducing members to multiple types......Page 176
5.4 Supplying annotations......Page 177
5.5 Declaring weave-time errors and warnings......Page 179
5.6 Softening checked exceptions......Page 180
5.7 Summary......Page 181
Aspects: putting it all together......Page 183
6.1.1 Similarities between aspects and classes......Page 184
6.1.2 Differences between aspects and classes......Page 186
6.2 Aspect association......Page 187
6.2.1 Default singleton association......Page 188
6.2.2 Per-object association......Page 190
6.2.3 Per-control-flow association......Page 192
6.2.4 Per-type association......Page 195
6.2.5 Implicit limiting of join points with aspect associations......Page 197
6.2.6 Accessing aspect instances......Page 198
6.2.7 Comparing per-object association and member introduction......Page 199
6.2.8 Improving the caching aspect......Page 200
6.3 Aspect precedence......Page 206
6.3.1 Ordering of advice......Page 208
6.3.2 Explicit aspect precedence......Page 209
6.3.3 Ordering advice in a single aspect......Page 211
6.4 Privileged aspects......Page 213
6.5 Summary......Page 214
Diving into the @AspectJ syntax......Page 215
7.1 Syntax overview......Page 216
7.1.1 Natural mapping......Page 217
7.1.3 Early error detection......Page 218
7.2 Mapping aspects......Page 219
7.2.3 Declaring aspect precedence......Page 220
7.3.1 Mapping abstract pointcuts......Page 221
7.3.2 Mapping concrete pointcuts......Page 222
7.4 Mapping dynamic crosscutting constructs......Page 226
7.4.1 The before advice......Page 227
7.4.2 The after advice......Page 231
7.4.3 The around advice......Page 234
7.5.1 Mapping weave-time declarations......Page 236
7.5.2 Mapping declare parents......Page 237
7.6.2 Introducing data and methods......Page 241
7.6.3 Softening exceptions......Page 242
7.7 Comparing syntax styles......Page 243
7.8 Summary......Page 244
AspectJ weaving models......Page 246
8.1 Classifying weaving models......Page 247
8.2.1 Build-time source code weaving......Page 248
8.2.2 Build-time binary weaving......Page 249
8.3.1 Load-time weaving overview......Page 253
8.3.2 Configuring the load-time weaver......Page 255
8.4 Load-time weaver in action......Page 260
8.5 Choosing syntax and weaving......Page 262
8.6 Summary......Page 263
Integration with Spring......Page 264
9.1 Spring AOP fundamentals......Page 265
9.1.1 Setting up the application......Page 266
9.1.2 Utilizing the @AspectJ syntax......Page 268
9.2 Spring AOP under the hood......Page 269
9.2.1 A quick introduction to dynamic proxies......Page 270
9.2.2 Proxy-based AOP with Spring......Page 271
9.2.3 Spring AOP internals......Page 272
9.2.4 Proxy-based AOP in DI framework......Page 273
9.2.5 Limitations of Spring AOP......Page 274
9.3 @AspectJ support in depth......Page 276
9.3.1 Dynamic crosscutting......Page 277
9.3.2 Static crosscutting......Page 282
9.4.1 Mapping aspects......Page 283
9.4.2 Mapping pointcuts......Page 284
9.4.3 Mapping advice......Page 285
9.4.4 Mapping static crosscutting......Page 286
9.5.1 Configuring aspects using Spring DI......Page 287
9.5.2 Spring-driven LTW......Page 288
9.6.1 Comparing AspectJ to Spring AOP......Page 292
9.6.3 It’s decision time......Page 293
9.7 Summary......Page 294
Applications of AspectJ with Spring......Page 296
Monitoring techniques......Page 298
10.1 Tracing in action......Page 299
10.1.1 Tracing the aspect-oriented way......Page 300
10.1.2 Tracing the conventional way......Page 302
10.2 Conventional vs. AOP tracing......Page 304
10.3 Selecting join points of interest......Page 305
10.3.1 Selection based on static structure......Page 306
10.3.2 Selection based on dynamic context......Page 310
10.4.1 Indenting trace calls......Page 311
10.4.2 Sharing tracing aspect functionality......Page 313
10.4.3 Tracing intra-method activities......Page 314
10.4.4 Logging the method parameters......Page 315
10.4.5 Choosing a type-specific logger......Page 317
10.5.1 Utilizing load-time weaving......Page 318
10.5.2 Utilizing Spring AOP for tracing......Page 320
10.6 Exception monitoring......Page 322
10.7.1 Modularizing NDC with conventional logging......Page 324
10.7.2 Modularizing MDC with conventional logging......Page 326
10.8 Performance monitoring......Page 328
10.9 Runtime control of monitoring aspects......Page 331
10.10 Summary......Page 333
Policy enforcement: keeping your design intact......Page 335
11.1 AOP-based policy enforcement overview......Page 336
11.3 Enforcement using AOP......Page 341
11.3.1 Compile-time enforcement......Page 342
11.3.2 Runtime enforcement......Page 343
11.4 Comparison with code-analysis tools......Page 344
11.5.1 Restricting exposure......Page 345
11.5.2 Limiting collaboration......Page 346
11.5.3 Enforcing the factory pattern......Page 348
11.6 Enforcement idiom: return-value restriction......Page 350
11.7 Enforcing JPA-JDBC integration policies......Page 351
11.8 Implementing EJB policies......Page 355
11.8.1 Developing a core EJB enforcement aspect......Page 356
11.8.2 Defining EJB pointcuts......Page 357
11.8.4 Implementing a “no EJBs” policy......Page 359
11.9 Detecting Swing concurrency control policy violations......Page 360
11.9.1 Understanding the problem......Page 361
11.9.2 Detecting the violation......Page 362
11.10 Summary......Page 365
Learning design patterns......Page 366
12.1.1 The current solution......Page 367
12.1.3 The worker object pattern template......Page 368
12.1.4 Getting the return value......Page 371
12.1.5 A summary of the worker object pattern......Page 373
12.2.2 An overview of the wormhole pattern......Page 374
12.2.3 The wormhole pattern template......Page 375
12.3 The participant pattern......Page 377
12.3.1 Current solutions......Page 378
12.3.3 The participant pattern template......Page 380
12.4 Annotation-driven participant pattern......Page 383
12.4.2 The annotation-driven participant pattern template......Page 384
12.4.3 Annotation type abstraction......Page 385
12.4.4 Variation: bridged participation pattern......Page 388
12.4.5 Role of ADPP in library aspects......Page 389
12.5 Summary......Page 390
Implementing concurrency control......Page 391
13.1 Modularizing Swing’s single-thread rule......Page 392
13.1.1 A test problem......Page 393
13.1.2 Solution: the conventional way......Page 395
13.1.3 Solution: the AspectJ way......Page 398
13.1.4 Improving the solution......Page 408
13.2 Improving the responsiveness of UI applications......Page 409
13.3.1 Implementation: the conventional way......Page 412
13.3.2 Implementation: the AspectJ way......Page 414
13.4 Summary......Page 418
Managing transactions......Page 420
14.1.1 Conventional implementation......Page 421
14.1.2 AOP implementation......Page 422
14.2.1 Transaction management in architecture......Page 423
14.2.3 Transaction-management abstraction......Page 424
14.3.1 Proxy-based AOP......Page 425
14.4 Transaction-management aspect (almost) from scratch......Page 426
14.4.1 Implementing the aspect......Page 427
14.4.2 Testing the aspect......Page 429
14.4.3 Road test for the aspect......Page 431
14.5 Spring’s transaction management......Page 437
14.5.1 XML-driven transaction management......Page 438
14.5.2 Annotation-driven transaction management......Page 440
14.5.3 AspectJ weaver-based transaction management......Page 441
14.6.1 Base aspect......Page 442
14.6.2 Using the annotation-driven participant pattern......Page 444
14.6.3 Configuring the aspect......Page 445
14.6.4 Testing the fault-tolerance aspect......Page 446
14.6.5 Improving the solution......Page 448
14.7 Summary......Page 449
Securing applications......Page 451
15.1.1 The do-it-yourself approach......Page 452
15.2 Modularizing security using AOP......Page 453
15.3.1 Authentication......Page 454
15.3.2 Authorization......Page 455
15.4 Implementing a security solution from scratch......Page 456
15.4.1 Implementing authentication aspects......Page 457
15.4.2 Implementing authorization aspects......Page 460
15.5 Implementing field-level authorization......Page 468
15.6.2 Service level security......Page 472
15.7 Additional ideas in implementing security......Page 475
15.8 Summary......Page 476
Improving domain logic......Page 478
16.1 Empowering objects......Page 479
16.1.1 Enabling rich behavior......Page 480
16.1.2 Injecting dependencies with Spring and AspectJ......Page 481
16.1.3 Possibilities enabled by domain-object DI......Page 489
16.2.1 Improving inventory management......Page 494
16.2.2 Checking for the order-level constraint......Page 496
16.2.3 Refactoring using aspects......Page 497
16.3.1 Applying specific policies......Page 499
16.3.2 Applying general policies......Page 500
16.4 Summary......Page 505
17.1 The adoption path: technologies......Page 506
17.2.1 Development aspects......Page 507
17.3.1 Talking the talk......Page 509
17.3.2 Walking the walk......Page 510
17.4.2 AOP in the implementation phase......Page 511
17.4.3 AOP in the maintenance phase......Page 513
17.4.4 AOP in legacy projects......Page 514
17.5 Parting thoughts......Page 515
Domain classes......Page 516
Repository layer......Page 522
Service layer......Page 524
Application configuration......Page 526
The web layer......Page 529
Building and running the application......Page 531
Weaving sources......Page 533
Creating an aspect library......Page 534
Weaving into jar files......Page 536
Weaving sources......Page 538
Creating an aspect library......Page 539
Weaving into jar files......Page 540
Symbols......Page 544
A......Page 546
C......Page 550
D......Page 552
E......Page 553
H......Page 554
J......Page 555
L......Page 556
M......Page 557
O......Page 558
P......Page 559
S......Page 561
T......Page 563
W......Page 565
Y......Page 566
Back cover......Page 567

Aspectj in Action: Enterprise AOP with Spring Applications [2 ed.]
 9781933988054, 1933988053

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers