[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] how to intercept joinpoints ...
|
Hello,
Hum, ok, but if you don't have the Aspect1 source-code, that is a little
bit difficult to implement ... Let's suppose you just have the aspect and its
specification, where you can find out everything you need... :-) So you decide
to intercept its joinpoints as you have showed us. Is there any way to do this
as you can do it with a class when you dont have the source? I meant, if the
class documentation tell me that it has a "withdraw" method, it's easy to
write an aspect to intercept it, right?
thanks a lot
> From: "Davi Pires" <inhodpr@xxxxxxxxx>
> Subject: Re: [aspectj-users] how to intercept joinpoints ...
> To: aspectj-users@xxxxxxxxxxx
> Message-ID:
> <29c266b0610201603o2f7d374x30c22eec08604173@xxxxxxxxxxxxxx>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Not very neat...
>
> If you need a way to "name" your advices, I suggest using
> annotations. For example:
>
> public aspect Aspect1 {
> pointcut pc(): execution(* Foo.m1(..));
>
> @BeforeAdvice
> before(): pc() {
> System.out.println("I'm before m1");
> }
>
> @AfterAdvice
> after(): pc() {
> System.out.println("I'm after m1");
> }
>
> }
>
> public aspect Aspect2 {
>
> pointcut beforeM1(): within(Aspect1) && @annotation(BeforeAdvice)
> ; pointcut afterM1(): within(Aspect1) && @annotation(AfterAdvice);
>
> before(): beforeM1() {
> System.out.println("I'm before before m1.");
> }
>
> after(): beforeM1() {
> System.out.println("I'm after before m1.");
> }
>
> before(): afterM1() {
> System.out.println("I'm before after m1.");
> }
>
> after(): afterM1() {
> System.out.println("I'm after after m1.");
> }
>
> }
>
> This works as expected, and generates a correct output.
>
> Davi
>