[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] accessing protected methods in parent class



Charles,

The "Active.saveErrors()" method is protected which is only visible to
subclasses and types in the same package. You need to make your aspect
"privileged" e.g.

   public privileged aspect MyAspect {
      ...
   }

While there is no restriction on the join points a pointcut can match
advice and methods within an aspect are subject to the normal Java
visibility rules. Looking at you snippet you may wish to expose "this"
through the pointcut rather than using a cast:

   public privileged aspect MyAspect {

      pointcut somePointcut (Action action) :
            ...
            this(action);

      before (Action action) : somePointcut (action) {
            ..
            action.saveErrors(request,errors);
      }

   }

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/

"Charles N. Harvey III" <charlieh@xxxxxxxxx>@eclipse.org on 16/11/2004
22:50:22

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-admin@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    [aspectj-users] accessing protected methods in parent class


Hello.
My aspect cuts into my Struts Action classes.  If there is an error
somewhere I want to be able to do the saveErrors( request, messages );
thing that works out so well in my Action classes.  Thing is,
"saveErrors()"
is protected.  And when I try one of these:

((Action)thisJoinPoint.getThis()).saveErrors( request, errors );

I get the error that "saveErrors()" is not visible.  Which it isn't.
But I thought since my aspect was weaving into a class that extended
Action, I would be able to use that method.

Is this possible?  Is there a way around it?  Thanks a lot.


Charlie

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