[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] AspectJ and memory management
|
Ok, we're nearly there then. You can be more general than my pointcut
suggests - I was encoding your literal example. The following fragments
should get you there....
If I can assume:
* the interfaces you want to enable delegation for are in some set of
packages org.xyz.interfaces..*
* the classes you want to enable delagation for are in some set of packages
org.xyz.impl..*
* and the target replacement classes are in a different package
then:
pointcut delegatedInvocation(Object obj) : execution(*
org.xyz.interfaces..*(..)) && within(org.xyz.impl..*) && this(obj);
Object around(Object obj) : delegatedInvocation(obj) {
framework.getDispatchTargetFor(obj);
... as before ...
}
There are other variations if you don't have this kind of package
separation, but this is the simplest.
-- Adrian.
adrian_colyer@xxxxxxxxxx
11 August 2004 16:13
To: aspectj-users@xxxxxxxxxxx
cc:
From: Rickard Öberg <rickard@xxxxxxxxxxxxx>
Subject: Re: [aspectj-users] AspectJ and memory management
Adrian Colyer wrote:
> but as I'm sure Wes pointed out, this only works when 'dispatchTarget' is
> an instance of the same concrete class as 'y' (in this case, an instance
> of A, which is not what you want).
Correct.
> You can however write this:
>
> pointcut invocationOfYonA(Y y) : execution(* Y.*(..)) && target(y) &&
> target(A);
Actually, if you can skip "target(A)" that is even better. I don't care
which object Y is added to. If you additionally can skip "target(y)" it
is also even better. I do not want to write this stuff for each
interface, and certainly not for each A. We've got hundreds of
interfaces and about fifty A-type classes!!!
> Object around(Y y) : invocationOfYonA(y) {
> // ask the framework for the real dispatch target, which should
> // create one if necessary...
> Y dispatchTarget = framework.getDispatchTargetFor(y);
> Object ret = dispatch(dispatchTarget,thisJoinPoint);
> return ret;
> // note the absence of a call to proceed in this advice body, which
> prevents the
> // original method on A from executing
> }
>
> // needs suitable exception handling...
> private Object dispatch(Object target, JoinPoint jp) {
> CodeSignature sig = (CodeSignature) jp.getSignature(); // assumes
only
> called from above
> Method m =
> target.getClass().getMethod(sig.getName(),sig.getParameterTypes());
> return m.invoke(target,jp.getArgs());
> }
>
>
> which is not as pretty, but if its part of your framework code it could
be
> optimised etc....
This is ok-ish, as long as I only have to write it once. If the pointcut
can be simplified to be more generic I think it might be workable. If it
is easier if the interfaces extend some marker interface that's ok. I
can also let the A-type classes implement some marker interface if that
helps.
/Rickard
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users