Pierce, Howard,

Thanks for the responses.  I back up and running (on this part!) - code is
more concise if a little less intuitive initially.  Thanks.

Regards,
Jim.

-----Original Message-----
From: Pierce Wetter [mailto:pie...@paceap.com] 
Sent: 27 May 2010 01:28
To: Tapestry users
Subject: Re: ClassTransformation API change for 5.2.0


On May 26, 2010, at 10:13 AM, Howard Lewis Ship wrote:

> You now getOrCreateMethod()  to create an empty placeholder (that
> calls the super implementation, if there is one). You then use the
> TransformMethod to addAdvice() to get it to do what you want.  It
> seems more complicated, but it has the advantage of being in purely
> Java code ... no Javassist psuedo-code is involved at all, and you can
> also add multiple bits of advice.  It's really about weaving a
> Tapestry of method invocations together :-)

  I had a hard time with this too, so I'll expand:

    The old way was to have hard coded strings of java that then javaassist
would compile. You often had to fuss about and add new instance variables,
then set the instance variable values, etc. You could have strings to run
before the method, after the method, and instead of the method. 

    The new way is to make an "advice" object, which you can do inline as an
inner class. That object only has one method, which is called to invoke the
method. So you generally don't need to add any instance variables or any of
the other mucking about, and the java compiler compiles plain old java code.
so no run-time syntax errors! 

    To run stuff before, the method in your advice object does:

   {

      stuff before

      invoke();
   }

   To run stuff after, the method does:

  {
      invoke();
  
      stuff after
  }

  To run stuff instead:

  {

     stuff
     //   invoke();  
   }

   To run stuff before and after:
   {

       stuff before

       invoke();

       stuff after
   }


  So the new approach becomes:

      TransformMethod method = getOrCreateMethod()

      advice = new MyAdviseObject();

      method.addAdvice(advice);

 Pierce




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to