Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Re: around in cflow

I don't think cflow works.  For the code

  void m() {
    String s = p.getFoo().getBar().{..}.returnString();
  }

the call join point associated with the returnString()
method is not in the control flow of the call or
execution join point for p.getFoo(), because

    p.getFoo().getBar().{..}.returnString();

is not a call chain but a sequence of calls.

You could try the control flow of the  enclosing m()
execution or call join point, but I don't know how
you could distinguish this sequences from others
(with multiple projects?), except perhaps by reliance on
return-value conventions or something like the fact
that only one project is ever being resolved at one
time in a thread.

So the join point model of the example is not
particularly susceptible to the desired pointcut.

Another way might be to put a (weak?) ref to the project
in the objects, and use that to resolve ${..} references
when the String is returned (or when the String is being
read by the XML parser? cflow might work there, and it
seems more efficient to do $-resolution during parsing, but
the aspect might need to know too much about the parser
and the value map might not be completed yet).
Structurally, this way is like the bean example,
where it associates a property support reference with
each bean object for use in bean operations.

Wes

Ron Bodkin wrote:
Is this more of what you wanted?

pointcut gettingString() : call(String *.getAString());
pointcut projectCtx(Project p) : cflow(execution(* Project+.*(..)) && this(p));

String around(Project p) : gettingString() && projectCtx(p) {
       String origString = proceed();
       // do the test for variables
       if (origString.indexOf("$") >= 0) {
             String changedString = p.mapString(origString);
             return changedString;
       }
       return origString;
}

Notes:
1) If you cared about the exact chain of calls, you could either use multiple cflows (e.g., cflow(cflow(cflow(call(* getNM())) && call(* getNM-1())) ...) or do dynamic tests on thisEnclosingJoinPoint at each "level".
2) you could say just cflow(this(p)) instead of limiting it to execution of methods for Project and subtypes, which would be the "most correct". However this would lead to less inefficient code (lots of cflow push and pop operations). Conceivably, the compiler could optimize this code but currently it does a fair bit of extra work for cflow(this(p)).
If you needed to handle constructors, it would be tricky (could you be sure your map was initialized?)

Ron

Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895


------------Original Message-------------
From: Jason van Zyl <jason@xxxxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Tue, Jun-17-2003 6:56 AM
Subject: Re: [aspectj-users] (no subject)

On Tue, 2003-06-17 at 06:44, Ken Horn wrote:

How about something like (untested syntax):

String around() : call(* *.getAString()) {
     String origString = proceed();
     // do the test for variables
     if (origString.indexOf("$") >= 0) {
           String changedString = ... // eval vars
           return changedString;
     }
     return origString;
}

Not sure if the getAString was a specific method or an example signature.

I have tried variants of the above but I'm not getting quite what I
want. I actually need to know when the call starts with the Project
(shown below) because it is the object which contains the Map of values
I would like to interpolate into the String.

I figured I would need a flow construct of some sort. I'll keep
experimenting!

Hi,

Say I have the following:

Project p = createProject( f );
String s =  p.getN0().getN1().getN2()...getNM().getAString()
          ^
          ^
               I

What is the best way to intercept the String returned by this call chain
to perform some transformation?

Specifically p is an object that is created by unmarshalling an XML
document which may contain ${foo} references. I would like to check I
for any of these references and interpolate the real value of foo into
the String before returning it to the caller.

--
jvz.

Jason van Zyl
jason@xxxxxxxxxxx
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.

 -- Jacques Ellul, The Technological Society

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





--

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


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

--
jvz.

Jason van Zyl
jason@xxxxxxxxxxx
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
-- Jacques Ellul, The Technological Society

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


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




Back to the top