Ramnivas Laddad9781930110939, 1-930110-93-6
It is time to move from AOP theory and toy examples to AOP practice and real applications. With this unique book you can make that move. It teaches you AOP concepts, the AspectJ language, and how to develop industrial-strength systems. It shows you examples which you can reuse. It unleashes the true power of AOP through unique patterns of AOP design. When you are done, you will be eager-and able-to build new systems, and enhance your existing ones, with the help of AOP.
What’s Inside: What is aspect-oriented programming?
How AspectJ works with JAAS, Jess, log4j, Ant, JTA, POJOs Best practices and design patterns How to implement policy enforcement resource pooling and caching thread-safety authentication and authorization transaction management business rules Ramnivas Laddad is an AOP and AspectJ authority. With his writings, he has contributed to the general awareness of AOP and has contributed to features now incorporated in AspectJ Version 1.1. Ramnivas lives in Sunnyvale, California.
Table of contents :
preface……Page 18
how real is AspectJ?……Page 20
into the future!……Page 22
acknowledgments……Page 24
Roadmap……Page 26
Packages and tools used……Page 28
About the author……Page 29
About the cover……Page 30
Part 1 – Understanding AOP and AspectJ……Page 32
Introduction to AOP……Page 34
1.1 The architect’s dilemma……Page 36
1.2 Evolution of programming methodologies……Page 37
1.3 Managing system concerns……Page 38
1.3.1 Identifying system concerns……Page 39
1.3.2 A one-dimensional solution……Page 41
1.3.3 It’s all about modularizing……Page 42
1.4 Implementing crosscutting concerns in nonmodularized systems……Page 45
1.4.1 Symptoms of nonmodularization……Page 46
1.4.2 Implications of nonmodularization……Page 49
1.5 Introducing AOP……Page 50
1.5.1 A bit of history……Page 51
1.5.2 The AOP methodology……Page 52
1.6 Anatomy of an AOP language……Page 53
1.6.1 The AOP language specification……Page 54
1.6.2 The AOP language implementation……Page 55
1.6.3 A weaving example……Page 57
1.7 Benefits of AOP……Page 58
1.8 Myths and realities of AOP……Page 60
1.9 Summary……Page 61
Introducing AspectJ……Page 63
2.1.1 Crosscutting in AspectJ……Page 64
2.1.2 Crosscutting elements……Page 65
2.2 AspectJ Hello World……Page 68
2.3 AspectJ: under the hood……Page 71
2.4 The join point model……Page 74
2.4.1 Exposed join point categories……Page 75
2.4.2 Join point demonstration example……Page 81
2.5 Aspects……Page 86
2.6.1 The AspectJ compiler……Page 90
2.6.2 AspectJ browser……Page 91
2.6.3 IDE integration……Page 92
2.7 Summary……Page 93
AspectJ: syntax basics……Page 95
3.1 Pointcuts……Page 96
3.1.1 Wildcards and pointcut operators……Page 98
3.1.2 Signature syntax……Page 99
3.1.3 Implementing pointcuts……Page 104
3.2 Advice……Page 112
3.2.1 Anatomy of advice……Page 113
3.2.3 The after advice……Page 114
3.2.4 The around advice……Page 116
3.2.5 Comparing advice with methods……Page 117
3.2.6 Passing context from a join point to advice……Page 118
3.2.7 Returning a value from around advice……Page 120
3.2.8 An example using around advice: failure handling……Page 121
3.2.9 Context collection example: caching……Page 123
3.3.1 Member introduction……Page 126
3.3.2 Modifying the class hierarchy……Page 127
3.3.3 Introducing compile-time errors and warning……Page 128
3.4 Tips and tricks……Page 129
3.5 Summary……Page 130
Advanced AspectJ……Page 131
4.1 Accessing join point information via reflection……Page 132
4.1.1 The reflective API……Page 134
4.1.2 Using reflective APIs……Page 137
4.2 Aspect precedence……Page 142
4.2.1 Ordering of advice……Page 145
4.2.2 Explicit aspect precedence……Page 146
4.2.3 Aspect inheritance and precedence……Page 148
4.2.4 Ordering of advice in a single aspect……Page 150
4.2.5 Aspect precedence and member introduction……Page 151
4.3 Aspect association……Page 153
4.3.1 Default association……Page 154
4.3.2 Per-object association……Page 156
4.3.3 Per-control-flow association……Page 159
4.3.4 Implicit limiting of join points……Page 163
4.3.5 Comparing object association with member introduction……Page 165
4.3.6 Accessing aspect instances……Page 166
4.4 Exception softening……Page 167
4.5 Privileged aspects……Page 170
4.6 Summary……Page 172
Part 2 – Basic applications of AspectJ……Page 174
Monitoring techniques: logging, tracing, and profiling……Page 176
5.1 Why use AspectJ for logging?……Page 177
5.1.1 A simple case in point……Page 178
5.1.2 Logging the conventional way……Page 180
5.1.3 Logging the aspect-oriented way……Page 184
5.2 What’s wrong with conventional logging……Page 185
5.4 Developing logging and tracing aspects……Page 187
5.4.1 Method call tracing……Page 188
5.4.2 Exceptions logging……Page 194
5.5 Common logging idioms……Page 198
5.5.1 Logging the method parameters……Page 199
5.5.2 Indenting the log statements……Page 201
5.5.3 Aspect precedence……Page 203
5.5.5 Using logging in a multithreaded environment……Page 204
5.6.1 Testing……Page 205
5.6.2 Profiling……Page 206
5.7 Summary……Page 207
Policy enforcement: system wide contracts……Page 209
6.1 AspectJ-based policy enforcement overview……Page 210
6.2 The current solution and its challenges……Page 212
6.3 Enforcement using AspectJ……Page 213
6.3.1 Policy enforcement implementation choices……Page 214
6.3.2 The role of policy enforcement during the product lifecycle……Page 215
6.4.1 Detecting the violation of a specific call pattern……Page 216
6.4.2 Implementing flexible access control……Page 218
6.4.3 Enforcing the best-practices principles……Page 220
6.5 Example: implementing EJB programming restrictions……Page 222
6.5.1 Implementing “no AWT”……Page 224
6.5.2 Implementing “no nonfinal static field access”……Page 225
6.6 Example: implementing Swing policies……Page 226
6.6.1 Understanding the problem……Page 227
6.6.2 Detecting the violation……Page 229
6.7 Summary……Page 231
Optimization: pooling and caching……Page 233
7.1 The typical case……Page 234
7.1.1 Return, reuse, recycle: The role of resource pooling……Page 236
7.1.2 Resource pooling issues……Page 237
7.2.1 Designing a template aspect……Page 239
7.2.2 Implementing the template aspect……Page 240
7.3 Example 1: database connection pooling……Page 242
7.3.1 Understanding the database connection pool interface……Page 243
7.3.2 AspectJ-based database connection pooling……Page 244
7.3.3 Implementing the connection pool……Page 247
7.3.4 Testing our solution……Page 249
7.3.5 Tweaking the solution……Page 253
7.4 Example 2: thread pooling……Page 254
7.4.1 The echo server……Page 255
7.4.3 AspectJ-based thread pooling……Page 257
7.4.4 Implementing the thread pool……Page 261
7.4.5 Testing our solution……Page 262
7.4.6 Tweaking the solution……Page 265
7.5 Extending pooling concepts to caching……Page 266
7.5.1 AspectJ-based caching: the first version……Page 268
7.5.2 AspectJ-based caching: the second version……Page 270
7.5.3 Ideas for further improvements……Page 271
7.6 Summary……Page 272
Part 3 – Advanced applications of AspectJ……Page 274
Design patterns and idioms……Page 276
8.1 The worker object creation pattern……Page 278
8.1.1 The current solution……Page 279
8.1.3 The pattern template……Page 280
8.2 The wormhole pattern……Page 287
8.2.2 An overview of the wormhole pattern……Page 288
8.2.3 The pattern template……Page 289
8.3 The exception introduction pattern……Page 291
8.3.1 The current solution……Page 292
8.3.3 The pattern template……Page 296
8.3.4 A summary of the exception introduction pattern……Page 300
8.4 The participant pattern……Page 301
8.4.1 Current solutions……Page 302
8.4.2 An overview of the participant pattern……Page 304
8.4.3 The pattern template……Page 305
8.4.4 A summary of the participant pattern……Page 307
8.5.1 Avoiding infinite recursion……Page 308
8.5.2 Nullifying advice……Page 310
8.5.3 Providing empty pointcut definitions……Page 311
8.5.4 Providing a default interface implementation……Page 312
8.6 Summary……Page 316
Implementing thread safety……Page 317
9.1 Swing’s single-thread rule……Page 318
9.1.2 The problem……Page 319
9.1.3 The solution……Page 320
9.2 A test problem……Page 321
9.3 Solution: the conventional way……Page 324
9.4 Solution: the AspectJ way……Page 328
9.4.1 The first version……Page 329
9.4.2 The second version……Page 334
9.4.3 The third version……Page 338
9.5.1 Dealing with exceptions……Page 342
9.5.2 Avoiding the overhead……Page 343
9.6 Improving the responsiveness of UI applications……Page 344
9.7.1 Implementation: the conventional way……Page 347
9.7.2 Implementation: the AspectJ way……Page 349
9.8 Summary……Page 352
Authentication and authorization……Page 354
10.1 Problem overview……Page 355
10.2 A simple banking example……Page 356
10.3.1 Implementing the solution……Page 360
10.3.2 Testing the solution……Page 362
10.4.1 Developing the solution……Page 364
10.5 Authorization: the conventional way……Page 367
10.5.1 Understanding JAAS-based authorization……Page 368
10.5.2 Developing the solution……Page 369
10.5.3 Testing the solution……Page 373
10.5.4 Issues with the conventional solution……Page 376
10.6.1 Developing the solution……Page 377
10.6.2 Testing the solution……Page 381
10.7.1 Using multiple subaspects……Page 384
10.8 Summary……Page 385
Transaction management……Page 387
11.1.1 Implementing the core concern……Page 389
11.1.2 Setting up the test scenario……Page 393
11.2 The conventional solution……Page 395
11.2.1 Using the same connection object……Page 396
11.2.2 Committing at the top level only……Page 398
11.3.1 Implementing the JDBC transaction aspect……Page 399
11.3.2 Handling legacy system issues……Page 404
11.3.3 Enabling transaction management for the banking system……Page 405
11.3.4 Testing the solution……Page 406
11.4 Improving the solution……Page 409
11.4.1 Using the participant pattern……Page 410
11.4.2 Implementing the JDBC transaction aspect: the second version……Page 413
11.4.3 Testing the solution……Page 416
11.5 Using AspectJ with advanced transaction- management systems……Page 418
11.6 Summary……Page 421
Implementing business rules……Page 422
12.1 Using business rules in enterprise applications……Page 423
12.3 Current mechanisms……Page 424
12.4.1 The template……Page 425
12.5.1 Implementing the core business logic……Page 427
12.5.2 Implementing the first business rule……Page 432
12.5.3 Implementing the second business rule……Page 434
12.5.4 Writing a test program……Page 437
12.6 Implementing business rules with a rule engine……Page 442
12.6.2 Using a rule engine……Page 443
12.6.3 Modularizing with AspectJ……Page 446
12.7.1 A brief overview of Jess (Java Expert System Shell)……Page 448
12.7.2 Specifying rules……Page 449
12.7.3 Understanding the rule invocation aspect……Page 451
12.8 Summary……Page 454
The next step……Page 456
13.1.1 Talking the talk……Page 457
13.2 Employing AspectJ in development phases……Page 458
13.2.2 AspectJ in the implementation phase……Page 459
13.2.3 AspectJ in the testing phase……Page 462
13.2.5 AspectJ in legacy projects……Page 463
13.3 A word of warning……Page 464
13.4 Evangelizing AspectJ……Page 465
13.5 Parting thoughts……Page 467
The AspectJ compiler……Page 469
A.1 Downloading and setting up……Page 470
A.2 An overview of the compiler……Page 471
A.4 Compiling source directories……Page 472
A.5 Weaving into JAR files……Page 473
A.6 Creating aspect libraries……Page 474
A.8 Utilizing incremental compilation mode……Page 475
A.9 Producing useful warnings……Page 477
Understanding Ant integration……Page 478
B.1 Compiling source files using an Ant task……Page 479
B.2 Weaving into JAR files using an Ant task……Page 482
B.3 Creating aspect libraries using an Ant task……Page 483
B.5 Utilizing incremental compilation using an Ant task……Page 484
Books……Page 486
Journal articles……Page 487
Libraries and tools you need to complete examples in the book……Page 488
Miscellaneous sites……Page 489
Mailing lists……Page 490
A……Page 492
B……Page 496
C……Page 497
D……Page 499
E……Page 500
I……Page 501
J……Page 502
L……Page 503
M……Page 504
P……Page 505
R……Page 507
S……Page 508
T……Page 510
W……Page 511
X……Page 512
Reviews
There are no reviews yet.