Thanks for the help. Fear not about the naming of the
pointcuts. That was sheer frustration
coming through at the end. I actually
changed the name from it’s original ‘wibble’
for group consumption. But the package advice
is well taken.
alan
-----Original Message-----
From: Ron Bodkin
[mailto:rbodkin@xxxxxxxxxxxxxx]
Sent: Wednesday, February 04, 2004 12:16 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users]
within
Alan,
You are matching
*execution* join points (i.e., execution of setValue). The easiest fix for your
code is to use call join points (since the call is within your aspect,
whereas the execution is NOT):
pointcut subTest(OpsBaseAttribute
attr) : call(public void setValue(String))
&& this(attr)
&& cflow(execution (public void Session.set*(String)))
&& !within(aspects.DateSub);
If you *really* need to use an execution
join point, then you need to exclude any execution in the cflow of your aspect,
e.g.,
pointcut subTest(OpsBaseAttribute
attr) : execution(public void setValue(String))
&& this(attr)
&& cflow(execution (public void Session.set*(String)))
&& !cflowbelow(adviceexecution() && within(aspects.DateSub));
The AspectJ FAQ
describes more about call vs. execution join points (http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/faq.html?rev=HEAD&content-type=text/html#q:comparecallandexecution).
Also, two style points:
1) I'd suggest using a
more descriptive pointcut name; it's considered good style to name what is
happening at a pointcut (i.e., setting a string value), not what your
implementation uses it for. This also enables reuse (and simplifies maintenance).
2) I'd suggest not using
an aspects package. If you want to segregate aspects for build purposes, I'd
prefer using a separate source folder (e.g., aspect/src) but use
"natural" packages. This becomes especially relevant when using
package-level (default) access.
Ron
Ron Bodkin
Chief Technology
Officer
New Aspects of Software
m: (415) 509-2895
------------Original
Message------------
From: "Alan
Brown" <abrown@xxxxxxxxxxxxxxxxx>
To:
<aspectj-users@xxxxxxxxxxx>
Date: Wed, Feb-4-2004 12:07 PM
Subject: [aspectj-users]
within
I must
be misunderstanding what how to use this operator.
I have
the following test code…
pointcut
wibble() : execution (public void Session.set*(String));
pointcut
subTest(OpsBaseAttribute attr) : execution(public void setValue(String))
&& this(attr)
&& cflow(execution (public void Session.set*(String)))
&& !within(aspects.DateSub);
void
around (OpsBaseAttribute attr) : subTest(attr)
{
System.out.println("supposedly calling
set on an attribute in the Session object for name ..." + attr.getName() +
"...");
if
(attr.getName().equals("LastLogin") ||
attr.getName().equals("Created") ||
attr.getName().equals("LastModified")) {
System.out.println("resetting for
" + attr.getName());
attr.setValue("2/02/2004 2:22:22 PM");
}
}
as you
can see I’m making a call in my around advice that will re-trigger the
pointcut. Hence my stating
“!within(DateSub)”, where DateSub is the name of the Aspect that
all this code exists within.
My
question is simple: Why do I get infinte
recursion when ‘within’ should mask out calls to setValue() from
within the pointcut…
Thanks
for your help.
alan