Index
Symbols
! operator 67
example of 30, 107, 133?134, 153, 160, 162, 187, 190, 304, 321
#error, C/C++ 97
#warning, C/C++ 97
&& operator 67
example of 93, 95, 162, 165, 171, 222?223, 279
misleading interpretation 98
* wildcard 67
use in type signature pattern 159
+ wildcard 67
.. wildcard 67
usage in constructor signature 70
usage in method signature 70
usage in type signature pattern 159
@deprecation
policy enforcement, and 186
|| operator 67
combining pointcuts, example of 199
example of 158, 186?187, 199, 223, 308
A
abstract aspects
code reuse 58
example of 57, 333, 402
restriction on declaration 57
reusability 298
Swing example 298
transaction management, example of 370
weaving 57
abstract pointcuts 56?57
example of 125, 128, 171, 251, 253, 299, 304, 319, 333, 347, 370, 383, 388
providing blank definition 280
use in logging 171
access control
factory pattern, and 188
plain Java, limitations of 187
using AspectJ 187
AccessControlContext
authorization, use of 338
AccessControlException
authorization, use of 338
AccessController
authorization, use of 338
AccessController.check-Permission() 339
authorization, use of 338
AccountJDBCImpl 358
ACID properties
transaction 357
acquire()
concurrency utility library 317
advice 81
anatomy of 82
aspect instance, accessing inside 124
body 83
categories 81
comparison with method 86?87
declaration 82
context information, and 82
exception declaration, and 83
declaring exception thrown, example of 377
definition of 35
exposed join point, restriction 82
inclusion in aspects 56
join point in aspect 277
methods, comparison 86
ordering 114
lexical 119
precedence, and 111
single aspect 119
example of 349
unpredictability 115
passing context to 87
precedence 111
authorization, example of 349
sequence diagram 81
use with pointcut 35
advice execution join points 50
pointcut syntax 74
adviceexecution pointcut 74
after advice 83
example of 53
exceptional return, on 84
successful return, on 84
variation 83
after returning advice 84
context collection, example of 232
efficiency consideration 98
example of 93, 220
after throwing advice 84
capturing exception, example of 269
context collection, example of 269, 377
use in exception logging 164
ajbrowser 60
crosscutting view 60
relation to IDE integration 60
ajc
-1.4 flag, use of 291
-aspectpath option 444
-classpath option 440
compiling source directories
See -sourceroots option, ajc 441
compiling source files 441
creating aspect libraries
See -outjar option, ajc 443
creating JAR files
See -outjars option, ajc 442
-d option 440
-deprecation option 440
existing build system, incorporating into 443
-g option 440
incremental compilation mode
See -incremental option, ajc 444
-injars option
See -injars option, ajc 442
javac, difference from 441
-outjars option
See -outjars option, ajc 442
preventing weaving 444
providing useful warnings
See -Xlint option, ajc 446
-source option 440
example of 233
-sourceroots option
See -sourceroots option, ajc 441
-target option 440
using aspect libraries
See -aspectpath option, ajc 444
weaving into JAR file
See -injars option, ajc 442
weaving, once-only restriction 443
-Xlint option
See -Xlint option, ajc 446
-XnoWeave option 444
ajc ant task
defining in build file 449
iajc ant task, relation 449
ajc compiler
iajc ant task, and 448
amount of code
authorization example, conventional 345
anonymous pointcut 65
using in a pointcut 66
using in an advice 66
Ant
AspectJ compilation task
See iajc ant task 448
AspectJ, using with 448
build file 448
build system
policy enforcement 180
overview 448
projects 448
targets 448
tasks 448
ant command
default settings 449
specifying properties 451
anti-idiom
infinite recursion 277
AOP
anatomy of language 22
benefits 27
code reuse 28
reduced cost 29
time-to-market 29
comparison with EJB 14, 31
definition of 4
development process
See AOP development process 21
difference from OOP 20
effect on modularization 28
effect on system evolution 28
history of 20
implementation of 20
in enterprise applications 31
inventors 20
learning curve 27, 31
mailing list, general discussion 436
methodology 21
myths 29
fixing bad design 4, 29
patching 30
silver bullet 437
object encapsulation 30
obliviousness 20
OOP as the base 6
program flow 29
purpose 4
related methodologies 20
relation to AspectJ 20
relation to design pattern 30
relation to OOP 19, 30
relation to XP 28
separation of concerns 20
separation of responsibility 28
short overview 4
AOP development process
aspects 21
aspectual decomposition 21
decomposing requirements 21
implementing core concerns 21
light-beam/prism analogy 22
AOP language
base programming language 23
implementation of concerns 23
specification 23
weaving rules specification 23
API, reflection
See reflection API 101
application frameworks
policy enforcement, and 181
architect?s dilemma 5, 28
AOP, and 5?6
logging example 167
opposing forces 5
performance example 5, 241
resource pooling, and 207
thread pooling, example of 315
args pointcut 80
context collection 87
example of 233, 402, 408
example of 80, 214, 220
reflection, and 101
type limiting, example of 234
around advice 85
accommodating different return types 91?92, 253, 254
altering context 40
bypassing join point, example of 209, 371, 373
casting, example of 254
detecting failure, use in 369
example of 40, 82, 85, 214
exception declaration 91?92
failure handling example 90
primitive return value 90
proceed(), and 85
returning Object, example of 253, 370
returning value 89
example of 228, 238
throwing exception, example of 214, 238
transaction management, example of 370
try/catch block 267
unwrapping, example of 254
usage of 85
using proceed() 40
worker object creation pattern, and 249
wrapping and unwrapping of 90
aspect libraries 321
creating
iajc ant task 452
See outjar option, ajc 443
using
iajc ant task 453
See -aspectpath option, ajc 444
aspect weaver 4
See weaving 4, 24
AspectJ
adoption 176, 426
policy enforcement, and 179
See AspectJ adoption
applying to new problems 426
browser
See ajbrowser 60
compiler 59
byte-code conformance 59
difference from Java compiler 98
Eclipse, relation to 440
Java byte-code specification, and 440
Java compiler
common compiler options 440
similarity to 439
overview 59, 440
See ajc 440
weaving 59
compiling sources 38
criteria for using 426
crosscutting classification 33
design patterns
exception introduction pattern
See exception introduction pattern 260?269
participant pattern
See participant pattern 270?277
worker object creation pattern
See worker object creation pattern 247?256
wormhole pattern
See wormhole pattern 256?260
design phase 428
development phases, use of 427
development process 427
limiting impact 427
restricting implementation 427
using conventional solution 427
downloading 439
dynamic crosscutting
See dynamic crosscutting 34
evangelizing 434
exposed join point 43
implementation phase 428
incorrect usage 433
individual productivity, for 434
installation
JAR files 439
installing 439
internal details vs. language semantics 42
internals 40
Java, superset of 440
join point model 43
just-in-time weaving 60
legacy project, and 432
mailing list 436
maintenance phase 432
mapping of elements 41
overview 33
relation to Java 33
running programs 38
setting up 439
simple program 37
static crosscutting
See static crosscutting 34
testing phase 431
word of warning 433
XP, and 431
AspectJ-based authentication
enabling access check 339
just-in-time 333
AspectJ-based business rule implementation 394
concern weaving 395
isolation layer 411
obliviousness 411
participating entities 394
participating join points 395
template 394
AspectJ-based caching 237?241
AspectJ-based logging 156
graphical illustration 157
investment 176
overview 146?154
risk 176
AspectJ-based rule engine
graphical illustration
behavioral 416
collaboration 415
AspectJ-based rule implementation
aspect, banking example 421
join point collection, when using rule engine 420
join point, restricting 420
AspectJ-based transaction management 368?378
defining operation 369
JTA, using 388
requirements, high-level 368
aspectjrt.jar
AspectJ runtime library 439
-classpath option, and 441
iajc ant task 448
specifying without modifying CLASSPATH 451
java ant task
specifying without modifying CLASSPATH 451
aspectjtools.jar
AspectJ tools library 439
iajc ant task 448
specifying without modifying CLASSPATH 450
aspectOf() 136
control-flow-based association, and 136
aspect-oriented logging 153, 156
advantages of 156
dependency reversal 156
weaving 156
aspect-oriented programming
See AOP 4
aspect-oriented resource pooling
plug-and-play 208
requirements 208
template aspect
See resource pooling template aspect 208
aspect-oriented thread pooling 226
-aspectpath option, ajc 444
-injars option, combining 444
aspects
abstract
See abstract aspects
access control rule, and 139
access specification 56
association 122?136
categories 122
default association
See default association 123
implicit limiting of join points, and 132
per-control-flow association
See per-control-flow association 128
scope 132
state 122
syntax 122
comparison with classes 56
consistent naming conventions 430
constructor 56
defining subaspect
See subaspect 57
definition of 36
dissimilarity with classes 58
domination
See aspect precedence 116
extending classes 58
extending restrictions 59
general form 55
implementing interfaces 58
inclusion of data members 56
inclusion of methods 56
inheritance
example of 335
precedence and 117
instance, accessing 124
instances
accessing 135
participant pattern, and 380
percflow association
example of 372
transaction management example 372
stateless aspects, and 382
transaction context, as 369
instantiation
capturing join point 375
default association 58
restriction 58
introducing default implementation 283
logging, using for
See logging 146
maintaining state 122
mapping to Java class 41
multiple aspects 111
nested
See nested aspects 56
nested inside a class, example of 361
parent types 56?57
per-object association
See per-object association 125
precedence 111?122, 433
avoiding coupling 116
consistent naming convention 430
explicit 115
indeterminism 113
inheritance, and 117
logging, and 172
member introduction 120
Swing thread safety example 302
usage style 116
privileged 139
See also privileged aspect 59
state, maintaining 122
with data member, example of 333
with method, example of 334
with nested classes, example of 334
aspectual interface
participant pattern 274
aspectual recomposition 21
aspectual refactoring 426, 431
conventional refactoring, comparison with 431
normal usage, differences using 431
assert 230
contract enforcement 230
-ea option 233
Jess, statement 419
asynchronous routing
exception introduction pattern 311
exception listener 311
exception-handling policy 311
atomicity
transaction, and 357
auditing 324
using logging 184
authentication 324
AspectJ-based 333?336
authorization prerequisite 337
avoiding multiple login 334
callback handler 329
concern-specific exception, use of 335
concrete aspect, example of 335
conventional solution 329?333
definition of 324
developing subaspect 333
just-in-time
See just-in-time authentication
login scope 334
property-based pointcut 270
servlet session, as scope 334
up-front login 354
authentication and authorization
banking example 325?329
separating join points 354
fall back 354
authorization 324
AspectJ-based 346?352
authentication, as prerequisite 337
concrete aspect 349
conventional solution 336?345
data-driven 352
definition of 324
enabling in a system 349
multiple subaspects
subject management 353
use of 353
policy file, example of 343
routing of calls 348
subsystem control 353
wormhole pattern, and 256
authorization aspect
dealing with checked exceptions 351
auto-commit mode 365?366
transaction management, JDBC and 359
auxiliary characteristics
participant pattern 270
AWT
EJB programming restrictions, and 191, 193
AWT thread
See event-dispatching thread 288
B
backward-reasoning algorithm
rule engine 412
banking system
authentication and authorization 325
business rule, example of 396
check clearance system, significance of business rule 403
core business logic implementation 396?401
minimum balance rule 401
overdraft protection rule 403
overdrafts accounts 398
persistence
class diagram 358
transaction management subaspect 374
with rule engine 417?423
BasicPermission 338
before advice 83
example of 39, 53, 82, 220
exception throwing and join point execution 83
throwing exception, example of 403
usage of 83
before-and-after
illustrating AspectJ?s power 434
best practices
business rules 420
declare warning, use of 190
policy enforcement, and 189
public members 190
beta testing 432
binary operator 67
type signature 69
bind
Jess, statement 419
blank final variable 296
Blaze Advisor
rule engine 417
blocking the caller, undesirability 298
build configuration 430
correctness consideration 431
deployment consideration 430
development process 427
policy enforcement 184
business rules
airlines booking system, example of 395
aspect
template 395
AspectJ-based mechanisms 394?396
banking system, example of 396
business objects, as facts 412
changing nature 392
context collection, need for 395
current mechanisms 393?394
definition of 392
enterprise applications, and 392?393
enterprise system, need in 392
evaluating
code tangling 392
example of 392
expression 393
implementation
choices 393
overview 393
steps 412
JSR 94, and 393
modularizing using AspectJ 415?417
need for separation 392
rule engine 412
shopping cart, example of 392
using rule engine 411
business-specific checked exceptions
dealing with catching 267
business-specific exceptions
dealing with 261
bypassing execution
around advice, use of 373
C
C++ 183
friend, access specification 188
C/C++ preprocessors 97
caching 235?241
AspectJ-based 235?241
deployment aspect, as 242
development aspect, as 242
feature change, caching example of 240
growth management 241
LinkedHashMap 241
performance, finding bottlenecks 242
per-object association 125
resource pooling, difference from 235
SoftReference, example of 241
stylesheet 235
using aspect 92
validity consideration 240
XSLT 235
call depth
extra argument, using 367
use in logging 170
use in profiling 175
call stack
wormhole pattern 258
call pointcut 74
example of 214, 220, 291, 299, 301, 304
specifying method exception, example of 269
callback handler
LoginContext, and 330
caller context
current solution 257
passing additional parameters 257
thread-specific storage 257
wormhole pattern 257
cflow pointcut 75, 383
comparison with cflowbelow pointcut 76
depiction using sequence diagram 76
example of 75, 306
transaction management, example of 371
use in policy enforcement 192
use in tracing aspects 159
wormhole pattern, use in 404
cflowbelow pointcut 75
comparison with cflow pointcut 76
depiction using sequence diagram 76
example of 75, 93
top-level operation, capturing using 370
usage of 77
use in tracing aspects 159
characteristics-based crosscutting
embedding pointcut in class 272
enumerating join points 272
participant pattern, and 270
checked exception 136, 260
advice, restriction on 260? 261, 264
compiler errors 263
current method 264
dealing with, example of 262
exception introduction pattern 260
restriction, and overridden methods 261
underlying logic, dealing with 261
class initialization join point 48
comparison with object initialization 49
pointcut syntax 74
static blocks 49
CLASSPATH
modification for AspectJ 439
-classpath ajc option 440
code review
EJB programming restrictions 192
policy enforcement, using 182
code scattering 15?16, 426
business rules, example of 394
cause 16
classification of 16
complementary code blocks 17
default interface implementation 282
duplicated code blocks 16
illustration 17
JTA, and 388
policy enforcement 182
puzzle piece analogy 17
resource pooling 206
sign of crosscutting concern 429
transaction management 368
code tangling 15, 426
business rules 392
example of 394
cause 15
code example 16
crosscutting concern, sign of 429
illustration 16
logging 155
policy enforcement 182
resource pooling 206
transaction management 368
collaboration flow
participant pattern 276
commit
database connection 366
common characteristics
sharing of 270
slow operations, example of 270
communicating failure
transaction management 369
compiler warnings
See -Xlint option, ajc 446
compile-time errors
advice checked exception, and 264
compile-time declarations
definition of 36
inclusion in aspects 56
compile-time enforcement 180
example of 180
limitations 183
compiling
source directories
See -sourceroots option, ajc 441
source files 441
concerns
banking example 7
composition of 8
core
See core concerns 4
crosscutting
See crosscutting concern 4
definition of 7
identification 8
implementation 21
process concerns 7
role in software system 7
separation
See separation of concerns 8
tangling 7
concern-specific checked exceptions 260
concern-specific exception
authentication, use in 335
concern-specific runtime exception
generic runtime exception, vs. 266
concrete aspect
authorization example 349
concrete subaspect
participant pattern 274
concurrency utility library 316
conditional check pointcut 80
configuration file
authorization, role in 338
example of 330
java.security.auth.login.config, specifying using 332
connection object
transaction context, as 368
consistency
transaction, and 357
consistent logging
importance of 155
consistent naming convention 98
importance of 429
example of 199
constructor join point 46
call 46
execution 46
execution vs. call 47
pointcut syntax 74
constructor signature 70
example of 72
similarity with method signature 71
use of .. wildcard 70
context 87
context collection
after returning advice 84
example of 220
after throwing advice 84?85
business rules, need in 395
caching, example of 92
collecting field set value 80
collecting return value 84, 89
collection exception object 80, 84?85, 89
example of 40
transaction management, example of 384
using anonymous pointcut 87?88
using args pointcut 80, 87
using named pointcut 88
using target pointcut 78, 87
using this pointcut 78, 87
control-flow
concepts 75
conceptual object 128
thread of execution, and 128
transaction management 368?369
control-flow association
transaction management, example of 370
control-flow-based pointcut 75
example of 75
conventional authorization
issues 345
conventional logging 149
consistency 155
graphical illustration 155
invasiveness 155
issues 154
shortcomings 154
conventional profiling 175
conventional resource pooling
code snippet 212
conventional transaction management
committing at the top level 367
disadvantages of 368
passing the connection around 365
using thread-specific storage 367
convincing
management 435
organization 434
team 436
core business logic
banking system, example of 396
definition of 392
modular nature 392
stable nature 392
core concern 4
capturing functionality 7
consistent naming convention 429
design phase 428
implementation of 30
implementation phase 429
refactored code, importance of 429
relativity 21
coupling
database connection pooling, and 211
credentials
authorization, checking for 336
crosscutting
high-level example 37
implementing using AspectJ 36?37
viewing in ajbrowser 60
viewing in an IDE 61
crosscutting concern
business rules, example of 393
capturing functionality 7
client-side modularization 11
definition of 4
design phase 428
design/implementation mismatch 15
enterprise example 7
implementation 430
designing aspects 430
join point identification 430
underlying technology, choosing 430
logging 154
modularization using AOP 12
modularization using OOP 11
need for additional methods 15
OOP shortcomings 4
pseudo code example 14
recognizing 428
rule of thumb 428
server-side modularization 11
tangling of data members 15
tangling of multiple concerns 15
transaction management, example of 357
weaving 13
cryptography 324
D
-d
ajc option 440
data introduction
example of 121
See member introduction 95
database connection
identifying 216
resource pooling, and 204
database connection pool
capacity 217
implementation of 216
SimpleDBConnectionPool 217
timeout 217
database connection pooling aspect 211?223
changing pool implementation 215
fine tuning 222
registering connection, need for 213
resource creation join point 214
resource destruction join point 214
resource pooling template, mapping to 213
selective enabling 222
DatabaseHelper 358
data-driven authorization 352
EJB, and 325
DBConnectionDescription 216
DBConnectionPool 212
DBConnectionPoolingAspect 214
deadlocks 287
declarative form, EJB
transaction management 357
declare error 97
policy enforcement
example of 186?187, 192, 195
transaction management example 374
declare parents 96
example of 97
Java inheritance rules 97
restrictions 97
declare precedence 115
abstract aspects 115, 119
circular dependency 117
enforcement usage 117
common usage idiom 117
dominating all aspects 116
example of 115, 269
example of multiple types 116
logging, example of 220, 332, 363, 408
subordinating all aspects 116
Swing thread safety, example of 302
syntax 115
use in logging 328
wildcard, using 116
declare soft
example of 319, 371
exception introduction pattern, vs. 335
SQLException, example of 361
syntax 137
declare warning 97
best practices, use in 190
example of 180
policy enforcement
example of 186
transaction management example 374
decorator design pattern 246
default association
instance creation
transaction management example 382
default interface implementation 281?285
overriding 284
partial 284
multiple inheritance 284
providing, idiom 281
DefaultTableModel 196
DelegatingThread 226
implementation of 227
need for 226
delegation pattern 282
deployment
policy enforcement 185
-deprecation
ajc option 440
design
bloat 6
limitations of techniques 6
realization in hindsight 5
design pattern
definition of 246
idiom, difference 246
language specificity, and 246
object-oriented
decorator 246
factory 246
visitor 246
problem scope, and 246
relationship with AOP 30
use in design phase 430
design phase
AspectJ, using 428
core concern implementation 428
crosscutting concern 428
defining roles 428
detecting caller type
call stack, using 406
conventional methods, using 405
wormhole pattern, using 405
development phase
policy enforcement 184
developmental aspect
policy enforcement 179, 184
distributed system
tracing 157
distributed transaction management 387
doAsPrivileged()
authorization, use of 338
documentation
policy enforcement, using 181
domination
See aspect precedence 116
durability
transaction, and 357
dynamic context 101
pointcut vs. reflection 101
dynamic crosscutting 34, 81
definition of 34
runtime policy enforcement, and 184
See also advice 81
static crosscutting, comparison with 95
use of pointcut 35
dynamic information
logging 107
dynamic monitoring 176
dynamic profiling 432
dynamic proxies
using 13?14
dynamic service-level monitoring 176
E
echo server
EchoServer class 224
thread pooling, example of 224
worker class 224
Eclipse
AspectJ compiler, relation to 440
AspectJ integration 61
EJB
2.0 specification 191
authorization, and 325
policy enforcement 191?195
programming restrictions 191
AWT, and 191, 193
native library loading 194
socket creation 194
static fields 194
System.in access 194
threading 191
transactions, and 357
EJB-lite framework 355
Emacs JDEE
AspectJ integration 61, 440
empty pointcut definition
idiom 280?281
enclosing context 102
Enterprise Resource Planning (ERP) 387
EnterpriseBean 192
ERP 387
error recovery aspect
exception handling, and 261
evangelizing AspectJ 434
event-based programming
comparison with weaving 24
event-dispatching thread 287
improving UI responsiveness, exclusion 315
requesting operation 289
Swing 195
Swing policies 198
EventQueue.invokeAndWait() 198, 289
blocking caller 295
InterruptedException 300
InvocationTargetException 300
Swing thread safety, example of 293
synchronous operations, example of 295
worker object creation pattern, and 253
EventQueue.invokeLater() 198, 289
asynchronous operations, example of 295
exception, and 311
Swing thread safety, example of 293
worker object, and 247
EventQueue.isDispatchThread() 199, 300
exception handler join point 48
pointcut syntax 74
exception introduction pattern 260?269
chained exception 265
checked exception 260
wrapping of 265
current solution 261
declare soft, vs. 267, 335
distinguishing concern specific exception 267
exception call stack understandability 266
generic aspects 267
getCause() 269
initCause() 265
need to capture all exception types, example of 372
pattern template 265
preserving exception type 265
preserving exception specification 268
propagating concern-specific exception 265
propagating exception 265
read-write lock pattern, use of 320
runtime exception, use of 265
SoftException 267
propagating business-specific exception 267
summarily captured exception, dealing with 268
Swing thread safety, example of 312
transaction management, example of 377
unchecked exception, issue 265
exception-handling policy
grouping of calls 296
exception-handling strategy
change management, ease of 312
exceptions
handling
combining operation, difficulty with 342
current solution 261
logging 163
using log4j 166
using the standard Java toolkit 165
using System.err 164
softening 136?139
caution 139
effective code 138?139
execution vs. call pointcut 138
under the hood 138
usage of 137
summarily capturing, example of 370
execution object pointcut 78
example of 78
execution pointcut 74
capturing constructor, example of 168, 385
capturing read operations, example of 321
example of 159, 232, 306
existing build system
incorporating AspectJ 443
explicit aspect precedence 115
exposed join point
advice, on 82
Extensible Access Control Markup Language (XACML) 324
Extreme Programming
See XP 431
F
factory pattern 187, 246
field access join point 47
pointcut syntax 74
read access 47
write access 47
field read join point
pointcut syntax 74
field signature 72
example of 72
use of type signature 72
field write join point
pointcut syntax 74
field-get join point
getArgs(), and 104
field-set join point
getArgs(), and 104
final, and local classes 295
flexible access control
factory pattern, and 188
friend (C++) in Java 188
policy enforcement 187
shopping cart example 187
use of 187
Forte
AspectJ integration 61
friend (C++) 188
G
-g
ajc option 440
get pointcut 74
example of 186
getArgs() 104
example of 107, 168
field-get join point 104
field-set join point 104
handler execution join point 104
primitive argument 104
getCause() 269
getConnection() 212
getDeclaringType()
example of 376
getKind() 105
example of 108
getResource() 205
getSignature() 105
example of 108, 199, 291, 328, 332
logging, example of 363, 408
use in logging 158, 168
getSourceLocation() 105
&nb