Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Aspect association question

Hi,

 

I am trying to associate one aspect per object instantiated the following way following the guidelines of [1]. However I am not obtaining the desired results on the “call” event.

Note: this code does run as expected when I use the “execution” event as in

pointcut captureOnInstance():execution(AccountViewer.new());

 

+ My question is why wouldn’t it run with the “call” event?

 

The aspect I want associated to each new instance of my ‘AccountViewer’ class is the following:

 

 

public aspect LabelAspect perthis(captureOnInstance())

{

public LabelAspect(){

System.out.println("Instantitating aspect itself");

}

pointcut captureOnInstance():call(AccountViewer.new());

before(): captureOnInstance(){

System.out.println("HelloAspectWorld!!!!!!");

}

}

 

There is no output, i.e. it seems as though the advice is not executing.

Also, the message in the constructor is not executing.

When I remove the perthis association, the advice does execute when new instances of the AccountViewer Class are created, however, in this latter case, I don’t fulfill my goal of associating an aspect instance with each new AccountViewer Instance.

Again, if I switch call for execution, the code works.

 

[1]  Raminvas Laddad, “AspectJ in Action”

 


Back to the top