Section 7.4. ASPECTUAL ADAPTIVE PROGRAMMING WITH DAJ


7.4. ASPECTUAL ADAPTIVE PROGRAMMING WITH DAJ

DJ exemplifies how AP is conceptually integrated with Java. DJ makes the concepts of AP available as Java classes: ClassGraph, Strategy, and Visitor. It is interesting to see how AP is integrated with AspectJ. This has been the objective of the DAJ project [33, 37].

DAJ achieves a couple of goals. First, it is easy for AspectJ programmers to use AP. Only two new declarations need to be learned to use DAJ, namely strategy and traversal declarations. Second, it improves the performance of AP. The implementation is an order of magnitude faster than DJ and class dictionaries have been added as an optional feature.

7.4.1. Strategy Graph Intersection

While DJ works with any number of class graph views using a strategy to define each view, DAJ works with only one main class graph. Making the strategy language more expressive, particularly by adding a strategy intersection capability, compensates for this restriction. For example, we can define a strategy eachFile as

 declare strategy: eachFile:     "intersect(from CompoundFile to File, down)"; declare strategy: down:     "from * bypassing -> *,parent,* to *"; 

where strategy down selects only the down links in a recursive data structure by bypassing all parent links. Strategy eachFile reaches all File-objects reachable from a CompoundFile-object, but only following down links.

To get the equivalent of cg.traverse(o, whereToGo, whatAndWhenToDo) in DAJ, a second kind of declaration, called a traversal declaration, is introduced. It defines a new method using the strategy whereToGo and the class of WhatAndWhenToDo:

 WhatAndWhenToDo.   declare traversal:   void someName(): whereToGo (WhatAndWhenToDo);   

7.4.2. Visitor Classes

WhatAndWhenToDo is a Java identifier naming a class (declared elsewhere) containing visitor methods that are invoked during the traversal. Arguments to the traversal will be passed to the constructor of the visitor. There are five kinds of visitor methods:

  • void start() is invoked at the beginning of the traversal.

  • void before(ClassName) is invoked when an object of the given class is encountered during the traversal before its fields are traversed.

  • void after(ClassName) is invoked when an object of the given class is encountered during the traversal after its fields have been traversed.

  • void finish() is invoked at the end of the traversal, that is, after all the fields of the root object have been traversed.

  • Object getReturnValue() is invoked at the end of the traversal, and its value is returned as the result of the traversal (suitably cast to the traversal's return type).

In the future, all the capabilities in DemeterJ [32] will be added to DAJ.

Having added strategy and traversal declarations to AspectJ, it also makes sense to add a new pointcut designator to AspectJ: traversal(s) for a traversal strategy s. It selects all join points in the traversal defined by s and can be freely combined with other pointcut designators.

The implementation of DAJ translates the class dictionary files to class definitions with parsing methods using the ANTLR tools [36], and it translates the strategy and traversal declaration files to AspectJ introductions defining the appropriate traversal methods using the AP Library [21, 22]. It then weaves all the AspectJ files together.

In the current implementation of DAJ, we have the restriction that traversal and strategy declarations must be put into separate files. This is a small inconvenience but has the advantage that the AspectJ compiler does not need modification.



Aspect-Oriented Software Development
Aspect-Oriented Software Development with Use Cases
ISBN: 0321268881
EAN: 2147483647
Year: 2003
Pages: 307

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net