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

Hi Charles,

The aTrack open source example project also uses AspectJ with Struts. We handle this exact problem by defining an abstract base class that extends Action, and that exposes an operation that uses saveErrors, and then we use declare parents to make all of our Action classes extend Action our base class.(*)

An alternative approach is to weave into the Struts library jar (e.g., by making a privileged aspect that accesses saveErrors directly). aTrack can be found at https://atrack.dev.java.net/

E.g.,

public abstract class AtrackAction extends Action {
    public AtrackAction() {
        super();
    }    

    public boolean isBadTxnToken(ActionMapping mapping, HttpServletRequest request) {
        if (!isTokenValid(request)) {
            ActionErrors errors = new ActionErrors();
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.transaction.token"));
            saveErrors(request, errors);
            saveToken(request);
            return true;
        }
        return false;        
    }
}

public aspect AtrackActionDefinition { 
    declare parents: org.atrack.ui..controller..* && Action+ extends AtrackAction; 
...

 In general, I'd recommend making such a base class expose a minimal set of operations from its parent and let advice or ITD's define behavior for specific cases (that way you aren't stuck in the framework trap of having a single base class that defines all the behavior and prevents you from having alternative implementations).

Ron Bodkin
Chief Technology Officer
New Aspects of Software
o: (415) 824-4690
m: (415) 509-2895


> ------------Original Message------------
> From: "Charles N. Harvey III" <charlieh@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Tue, Nov-16-2004 2:51 PM
> 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
> 
>