[aosd-discuss] Accessing context from advices in AspectJ

Alan Cyment acyment at yahoo.com
Tue Aug 15 16:36:15 EST 2006


Hi everyone out there! I'm currently working on an analysis of how context is accessed by advice in AspectJ (i.e. how advice code interacts with active objects either through pointcuts parameters or by using the thisJoinPoint object).  
 
The example I'm working on is the classic Point & Line case: a simplified drawing application that uses a Display object and that offers the user the chance to define both Points and Lines. In the original example, the only existing advice does not need to interact with the Points and Lines, so I decided to change the scenario a little bit: instead of updating the whole screen, we wish to (in Windows terms) invalidate the smallest region that contains the shapes that have changed their position.

This new requirement forces the advice code to retrieve from the shapes the region they take up on the screen. The following is the cleanest solution I could find in AspectJ:

public aspect UpdateSignaling {

    pointcut changePoint(Point P): 
        ((execution(void Point.set*(int))) || 
        (execution(void Point.moveBy(int,int))))
        && target(P);
        
    pointcut changeLine(Line L) :    
        (execution(void Line.moveBy(int,int)))
        && target(L);
    
    after(Point P) returning: changePoint(P){
        Display.update(P.getX(),P.getY(),P.getX(),P.getY());}

    after(Line L) returning: changeLine(L) {
        Display.update(L.getP1().getX(),L.getP1().getY(),
                                        L.getP2().getX(),L.getP2().getY());}

 }

Do you think there's a way of avoiding the need for two advices? And for advices to actually have to know a shape's inner structure?

Cheers,
Alan





More information about the discuss mailing list