2008/12/14 NewWay <[email protected]>

>
> Is it also possible to know who is the calling method?
>

yes. switch from using "execution()  && this()" to "call() && target()".  In
fact that is another way to get the Page instance:

@Before("call(@WorkflowAction * *(..))) && target(f) && this(p)")
public void goo(Page p, Page.Form f) {
  // Calling method available through thisEnclosingJoinPointStaticPart
}


Andy.


>
> Andy Clement wrote:
> >
> > 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
> >
> >
> > 2008/12/12 miro <[email protected]>
> >
> >>
> >> I want to take control  through my aspect for any method which is
> >> annotated
> >> with  @WorkflowAction.
> >> here is my example
> >>
> >>  public class Page(){
> >>        Page(){
> >>            add(new Form());
> >>        }
> >>
> >>        // inner class
> >>         public Class Form  {
> >>                @WorkflowAction()
> >>                void somemethod()
> >>         }
> >>
> >> }
> >> My aspect comes in picture when the somemethod()  is called and I am
> >> wondering is there a way I can pass instance of page to my aspect ?
> >>
> >> here is my aspect
> >>
> >>        @Before("@annotation(gov.hhs.acf.aop.aspects.WorkflowAction)")
> >>        public void transferWorkflowContext(JoinPoint joinPoint){
> >>          //here  I want to access the page instance
> >>        }
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/passing-instance-of-parent-class-to-aspect-tp20976785p20976785.html
> >> Sent from the AspectJ - users mailing list archive at Nabble.com.
> >>
> >> _______________________________________________
> >> aspectj-users mailing list
> >> [email protected]
> >> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >>
> >
> > _______________________________________________
> > aspectj-users mailing list
> > [email protected]
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/passing-instance-of-parent-class-to-aspect-tp20976785p21000732.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
>
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to