|
Helping ordinary people create extraordinary websites! |
Using Aspects to Autonomic-Enable Legacy ApplicationsBy Brian Temple2005-05-13
Incorporating Aspects Although there are currently several different flavors of AOP available for Java™ applications, in this article I use AspectJ™, which is available from eclipse.org. (See Resources for download information.) From the AspectJ FAQ: "AspectJ is a simple and practical extension to the Java programming language that adds to Java aspect-oriented programming (AOP) capabilities. AOP allows developers to reap the benefits of modularity for concerns that cut across the natural units of modularity. In object-oriented programs like Java, the natural unit of modularity is the class. In AspectJ, aspects modularize concerns that affect more than one class." After you've decided which internal actions of the legacy application are interesting, you can create Aspect pointcuts. Generally, an Aspect pointcut can define most Java execution points, such as method entry and exit, object creation or modification, and when Exceptions are thrown. After you've defined a pointcut, a set of arbitrary code can be set to be executed before, after, or instead of the action the pointcut defines. Conceptually, this approach can be thought of as weaving in functionality at generically described locations throughout a defined application. Aspects can be abstract and they can use inheritance to subclass, just like Java objects. To compile a Java program that uses Aspects: 1. Download the AspectJ package from eclipse (see Resources). 2. Place the AspectJ Java Archive (JAR) files in your system or build environment classpath. 3. Modify your build environment, as shown in Listing 3, to include required AspectJ properties. 4. Replace instances of the javac task with the iajc task. Listing 3. Modified Ant Build Script <!-- Properties for aspect building -->If you use eclipse as your IDE, all you need to do is install the AJDT plug-in and add an AspectJ nature to your project. Now that the ant build.xml has been set up to compile Aspect code, you are ready to include the Aspect framework. Add the framework code to the source directory of the project and, if necessary, modify the build.xml file to include the Aspect source in the build path. Tutorial Pages: » Using Aspects to autonomic-enable legacy applications » Introduction » Example legacy application » Incorporating Aspects » An example Aspect framework to generate Common Base Events » How to use and extend the example Aspect framework » Next steps » Resources First published by IBM DeveloperWorks |
|