Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ajdt-dev] passing context to advices


Marco,

Yes, every call will be advised with a runtime check to determine whether it is within the desired control flow. The advice markers should indicate this with a "?". Using within() will scope the advice.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx

http://w3.hursley.ibm.com/~websterm/

Please respond to AspectJ Development Tools developer discussions <ajdt-dev@xxxxxxxxxxx>

Sent by:        ajdt-dev-bounces@xxxxxxxxxxx

To:        "AspectJ Development Tools developer discussions" <ajdt-dev@xxxxxxxxxxx>
cc:        
Subject:        Re: [ajdt-dev] passing context to advices


Hello Matthew,
 thanx!!!! worked!
except for some minor issues...

with hte code you sent me, it intercepts not only methods in MyBean, but also all methods in other beans
which calls Bean2.getItems..

i suppose i have to restrict somehow the 'scope', to say  only if the 'caller' is MyBean....
i think what i need to change is this pointcut

pointcut getItems() :

               call (* com.Bean2.getItems(..)) .
               && withincode(* MyBeanX.build)
.
do you foresee any problems? wil it clashes with the other pointcut??

thanx again in advancea nd regars
marco



On 3/15/06, Matthew Webster <matthew_webster@xxxxxxxxxx> wrote:

Marco,


If you want to use the arguments passed to the build() method when intercepting the call to getItems() then you need cflow():


import com.DTO;


public aspect MyAspect {

       pointcut getItems() :

               call (* com.Bean2.getItems(..));

   
   pointcut build(DTO demand) :

     execution(* MyBeanX.build(..,DTO))


       && args(demand);

   
   
   
   Object around(DTO demand) :

            (cflow(build(demand)) && getItems()){
       System.err.println("We are there..." + demand);
       return proceed(demand);


   }

 
}


Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB,
matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/

Please respond to AspectJ Development Tools developer discussions <ajdt-dev@xxxxxxxxxxx>

Sent by:        ajdt-dev-bounces@xxxxxxxxxxx

To:        "AspectJ Development Tools developer discussions" <ajdt-dev@xxxxxxxxxxx>
cc:        
Subject:        
Re: [ajdt-dev] passing context to advices


Ah, thanx Matthew, now i see..
so my code won't work then, because build and getItems have completely different parameters......

so how can i get the arguments of the withincode call? because those are the ones i need......

I assume if i use static JointPOint info to get Arguments,  i will still get argtuments for the pointcut
associated with call...

can you give me some more hints?

regards
marco

On 3/15/06, Matthew Webster <
matthew_webster@xxxxxxxxxx > wrote:

Marco,


Yoy can't use call & execution together because that won't match anything. Using call & withincode is fine but to understand why it doesn't match we need to know the signatures of both getItems() and build(). The pointcut you end up with for your around advice is:


     
call (* com.Manager.getItems(..)) && withincode(* com.ProcessorBean.build(..,DTO)) && args(demand);

So we are looking for a call to getItems() that takes a single argument of type DTO within a method build() that has at least one argument the last of which is also a DTO (because args goes with call not withincode) e.g.

   private void build (DTO dto) {

       Collection items = bean2.getItems(dto);

           

   }


      public Collection getItems (DTO dto) {

              return null;

      }


Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB,
matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/

Please respond to AspectJ Development Tools developer discussions <ajdt-dev@xxxxxxxxxxx >

Sent by:        ajdt-dev-bounces@xxxxxxxxxxx

To:        AspectJ Development Tools developer discussions <ajdt-dev@xxxxxxxxxxx >
cc:        
Subject:        
Re: [ajdt-dev] passing context to advices




Use "call" or "execution" instead of "withincode". Withincode matches join points within the context of the function block, but you want to match on invocations of the function.

Dean

Marco Mistroni wrote:
hello all,
i have following code which shows, in ajdt, no cross references..

pointcut getItems() :
     call (* com.Manager.getItems(..));
 
 pointcut build(DTO demand) :
     withincode(* com.ProcessorBean.build(..,DTO))
     && args(demand);
 
 
 
 Object around(DTO demand) :
         (build(demand) && getItems()){
     System.err.println("We are there...");
     return proceed(demand);
 }





if instead i omit the DTO parameter (menaing, i don't pass as argument of my build pointcut, everything
works fine

anyone can tell me what's wrong? more likely i am using wrong syntax.....

thanx and regards
marco



_______________________________________________
ajdt-dev mailing list

ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev



--
Dean Wampler, Ph.D.
dean at
aspectprogramming.com  
http://www.aspectprogramming.com  
http://www.contract4j.org
I want my tombstone to say:
Unknown Application Error in Dean Wampler.exe.
Application Terminated.
[Okay]    [Cancel]

_______________________________________________
ajdt-dev mailing list

ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev


_______________________________________________
ajdt-dev mailing list

ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev


_______________________________________________
ajdt-dev mailing list

ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev


_______________________________________________
ajdt-dev mailing list

ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev


_______________________________________________
ajdt-dev mailing list
ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev


Back to the top