Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Weaving advice around methods defined by declare parents

Title: Weaving advice around methods defined by declare parents
Hi Ron,
 
Thanks for your reply.  The problem with your pointcut is that it inserts advice into the client code and I'm trying to avoid that.
 
My example below was a possible solution to a problem I'm trying to solve, but maybe someone has already encountered this problem so I'll quickly sketch it out. 
 
I'm trying to create two different versions of some functionality; one that has been aspected and another that has not.  Ideally I would like to minimize the amount of code I have to maintain.  I plan on creating a Factory which would return either an aspected or unaspected object depending on some flag. 
 
Has anyone found a good solution to this?  One possible way I've though of is to have each aspected method call the corresponding unaspected method.  However that is not ideal considering the number of classes and methods on those classes that I'm going to have to maintain. 
 
I know running the advice all the time does not add too much overhead, but there are some situations where this is not acceptable.  It would be cool if there was some other solution to this problem.
 
Cheers,
 
Mike
-----Original Message-----
From: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx]On Behalf Of Ron Bodkin
Sent: Thursday, November 27, 2003 2:50 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Weaving advice around methods defined by declare parents

Hi Mike,

 

Try either execution(void A.x()) or execution(void A.x()) && this(AImpl)

 

execution(void AImpl.x()) will only match methods named x that are defined on the AImpl type, not on inherited methods from supertypes.

 

Ron

 

Ron Bodkin

Chief Technology Officer

New Aspects of Security

m: (415) 509-2895

 

 

------------Original Message------------

From: "Mike Pettypiece" <Mike.Pettypiece@xxxxxxxxxxxxxxx>

To: <aspectj-users@xxxxxxxxxxx>

Date: Thu, Nov-27-2003 11:13 AM

Subject: [aspectj-users] Weaving advice around methods defined by declare parents

I'm wondering if something like the following is possible:

public aspect AspectA
{
    declare parents: AImpl implements A;  // A has one method, void x();
   
    // Implement A
    public void A.x() { System.out.println( "x()" ); }

    pointcut myPC() : execution( void AImpl.x() );
   
    Object around() : myPC()
    {
        System.out.println( "Before x()" );
        Object result = proceed();
        System.out.println( "After x()");
        return result;  
    }  
}


This is a simplified example of what I'm trying to do but it illustrates my problem.  What I would like to do is implement an interface using an aspect and then add advice around those methods that were implemented.  However AspectJ doesn't seem to be able to add advice in this fashion.

Any ideas how I can accomplish this?

Cheers,

Mike


Back to the top