[aspectwerkz-user] Intercepting parameters with run-time aspect deployment.

"Udo Fritzke Jr." <[email protected]> Thu, 8 Mar 2007 16:53:55 -0300 (BRT)
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <[email protected]>
Hi,

We are trying to intercept the actual parameters and return values
of a class method call, defining "args" pointcuts. It works fine
when the weaving is done statically with a build file. However, it
does not work when we dynamically deploy an aspect. The application
compiles and runs, but the advice does take effect at all.

Does someone could explain if there is some guideline or implementation
detail we are missing?

A sample code follows.

Thanks in advance,
Udo.

******************************
aop.xml
******************************
<aspectwerkz>

<system id="AW.MyAspect">
<package name="AW">
<aspect class="MyAspect">

  <deployment-scope name="response_time">
       within(AW.MyClass)
  </deployment-scope>

<!-- used only for static weaving

     <pointcut name="pc1" expression="execution(* AW.MyClass.Y(..))"/>
     <advice name="advice1(int ret, int arg)" type="after returning(ret)"
bind-to="pc1 AND args(arg)"/>
-->

</aspect>
</package>
</system>
</aspectwerkz>

******************************
MyAspect.class
******************************
package AW;

public class MyAspect
{
   public void advice1(int ret, int arg)
   {
	   //ret eh o retorno do metodo Y
	   System.out.println("Aspect: "+ret);

	   // arg eh o argumento passado em Y
	   System.out.println("Aspect: "+arg);

   }
}

******************************
MyClass.class
******************************
package AW;

public class MyClass
{
   public void X()
   {
	   int arg = 4;
	   int ret = Y(arg);
	   System.out.println("Aplicacao"+ret);
   }

   public int Y(int arg)
   {
	   System.out.println("Aplicacao"+arg);
	   return 2;
   }


   public static void main(String Argumentos[])
   {
	   MyClass obj = new MyClass();

	    String xmlDef = "<aspect class='MyAspect'> " +
	   		    "<pointcut name='pc1' expression='call(* AW.MyClass.Y(..))'/>" +
	                   "<advice name='advice1(int ret, int arg)' type='after
returning(ret)' " +
	                   " bind-to='pc1 AND args(arg)'/> " +
	                   "</aspect>";
	   Deployer.deploy(MyAspect.class, xmlDef);
	   obj.X();
   }
}





---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email