Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] passing instance of parent class to aspect

Typically code will perform better if you bind parts like the instance (this) directly.  Building joinpoint objects is not free (performance wise) and they are built to answer any question you might ask - so if you can bind the specific thing you want, I would do that.

Andy.

2008/12/15 miro <miroconnect@xxxxxxxxx>

what is the difference retrieving form from jointpoint and passing
retrieving it by this(f)  ?


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 <miroconnect@xxxxxxxxx>
>
>>
>> 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
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>

--
View this message in context: http://www.nabble.com/passing-instance-of-parent-class-to-aspect-tp20976785p21014864.html
Sent from the AspectJ - users mailing list archive at Nabble.com.

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top