Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] how do you write a pointcut in aop.xml for an inner class?

Your initial pointcut just worked for me.

--- ListenerService.java ---
package p;

public class ListenerService {
  public void doit() {
    new ServiceContext().run();
  }

    private class ServiceContext implements Runnable {
        public void run() {
            System.out.println("hello world");
        }
    }
}
---

--- Abstract.java ---
abstract aspect Abstract {
  abstract pointcut scope();
  before(): scope() {
    System.out.println(thisJoinPoint);
  }
}
---

--- Foo.java ---
import p.*;

public class Foo {
  public static void main(String []argv) {
    new ListenerService().doit();
  }
}
---

--- META-INF\aop.xml ---
<aspectj>
  <aspects>
    <concrete-aspect name="wibble" extends="Abstract">
      <pointcut name="scope" expression="execution(*
p.ListenerService.ServiceContext.run(..))"/>
    </concrete-aspect>
  </aspects>
  <weaver options="-showWeaveInfo"/>
</aspectj>
---

C:\aspectj164-dev\bin>java -javaagent:..\lib\aspectjweaver.jar Foo
[AppClassLoader@9fbe93] weaveinfo Join point 'method-execution(void
p.ListenerService$ServiceContext.run())' in Type
'p.ListenerService$ServiceContext' (ListenerService.java:10) advised
by before advice from 'wibble' (Abstract.java:4)
execution(void p.ListenerService.ServiceContext.run())
hello world

what is different in your setup to mine?

Andy.

2009/4/13 Buck, Robert <rbuck@xxxxxxxxxxxx>:
> Hello,
>
> Given the following:
>
> public class ListenerService {
>     private class ServiceContext implements Runnable {
>         public void run() {
>             System.out.println("hello world");
>         }
>     }
> }
>
> How do I write an pointcut in an aop.xml file for the inner class that is a
> Runnable and only for this Runnable?
>
> I have tried several times and I cannot get this to work at all. For example
> here are two of the many tries I made:
>
> <pointcut name="scope" expression="execution(*
> com.verisign.smq.spi.ListenerService.ServiceContext.run())"/>
> <pointcut name="scope" expression="execution(* *.run()) AND
> within(com.verisign.smq.spi.ListenerService)"/>
> Help would be greatly appreciated. This is a road-blocker for an issue I
> have.
>
> Thanks
>
> Bob
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top