[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] passing instance of parent class to aspect
|
I would not use @annotation, I would match statically on your methods:
@Before("execution(@WorkflowAction * *(..)))")
Passing the form instance is straightforward:
@Before("execution(@WorkflowAction * *(..))) && this(f)")
public void goo(Page.Form formInstance) {}
Accessing the outer instance of Page is not so eay. Here are the options:
1) define a getter in Form and call it from the advice
public void getPage() {
return Page.this;
}
2) Write a more complex pointcut that uses a wormhole pattern to pass the enclosing instance through to the advice:
@Before("execution(@WorkflowAction * *(..)) && cflow(this(p))")
public void foo(Page p) { }
3) use an AspectJ code style intertype declaration to add that getter from option (1):
public Page Page.Form.getPage() {
return Page.this;
}
(this could possibly be done in annotation style @DeclareParents, but
just the thought of the messiness of that declaration puts me off
trying it)
4) Rely on how the compiler implements inner classes:
public void goo(Page.Form formInstance) {}
Field f = Page.Form.class.getDeclaredField("this$0");
f.setAccessible(true);
System.out.println("Page is " + formInstance.get(p));
}
Andy