Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] declare parents with delegate

Hi,

That won't work if the methods are not already there, so, if the superclass is abstract or an interface, it does not rescue the developer from writing the abstract methods (even if we can generate them using the corresponding IDE features, this is an ugly / tedious work). It also enforces that all the client classes must be exposed to the weaver.

It also has some others drawbacks, like that it doesn't allow for an easy redefinition of the methods and that it is difficult to pick up all the desired join points with not very complex inheritance hierarchies (from AspectJ 1.2 it is easy to get warnings of the type |"[Xlint:unmatchedSuperTypeInCall]|" if one is not very careful).

I think that using an static-crosscutting structure like the one proposed by Guntis on the first post is the only one complete and robust solution.

If I'm wrong, please, let me know.

Best regards

Hermann Voßeler wrote:

Santi Villalba wrote:

Yes, that is the challenge, generate the methods when needed by delegating them to the delegate member.


Hello,

sorry, if I misunderstood or didn't get the point. But
why can't you do something of this sort:

    pointcut proxyCall(Object myTarget)
        : call(* MyTarget.*(..))
          && target(myTarget)
          && within(my.special.rootpackage..*);

    Object around(Object myTarget)
        : proxyCall(myTarget) {

            Object realTarget =
            this.getTarget(myTarget);
            try {
                Object val=proceed(realTarget);
                return val;
            }
            catch(Throwable T) {
                // do something if necessary
                // maybe package it into a Runtime Exception
            }
        }

    private Object getTarget(Object myTarget) {
        return ServiceLocator.getServiceObject(myTarget.getClass());
        // or something similar
    }



Back to the top