Information Technology Reference
In-Depth Information
1
public class MyAspect {
2
public Object trace(MethodInvocation invocation)
3
throws Throwable {
4
try {
5
System.out.println( "Entering method" );
6
// proceed to next advice or actual call
7
return invocation.invokeNext();
8
} finally {
9
System.out.println( "Leaving method" );
10
}
11
}
12
}
Figure 3.3.
JBoss aspect example.
Reusability. The stable interfaces provided by frameworks define generic compo-
nents that can be reused in new applications.
Extensibility. A framework provides hook methods that can be re-implemented by
subclasses.
Inversion of control. This allows the framework, as opposed to the application, to
decide which application specific methods to invoke in response to external
events.
Frameworks are designed to either be used as a general purpose framework
usable in any environment, such as AspectWerkz [16], or to be used in a specific
environment, such as the JEE framework. Components that have been developed
to a specific framework environment cannot be reused outside that environment,
severely limiting reuse.
3.6.1
The JBoss AOP Framework
The JBoss AOP framework provides a framework that can be used to develop
aspect-oriented applications that are either tightly coupled to the JBoss JEE ap-
plication server or are standalone. To use the framework, the programmer defines
AOP constructs as Java classes and binds them to application code using XML or
Java 1.5 annotations [54].
Aspect classes are defined as normal Java class that define zero or more ad-
vices, pointcuts and/or mixins (a mixin class is a class that is used to implement
multiple unrelated interfaces and is often used as an alternative to multiple inher-
itance [17]).
Figure 3.3 contains an example of an aspect called MyAspect 3 , which contains
an advice, trace (line two), that traces calls to any method. The return statement,
invocation.invokeNext() (line seven) is required in order to ensure that either
3 All examples presented in this section are reproduced from: JBoss AOP - Aspect-Oriented
Framework for Java [54].
 
Search WWH ::




Custom Search