• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get method invocation context  RSS feed

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

In some methods i need to pass to Audit the invocation context. by invocation context i mean to the class name, method name, arguments values.

I want to create a generic Audit method, something like this:

Class Hotel::
Public void orderRoom(Date start,Date end){

//I need here a code that know how to create invocation context (class name, method name , list of arguments values) in a generic way

Audit.audit(�); //the audit get list of objects

}

By using the �Throwable� (you are more than welcome to say another way to do this, because I don�t love this trick) I can get the class and the method name, but I don�t know how can I get the argument values?

Thank you
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally we used Spring to accomplish this previously. Auditing should be injected like an additional 'aspect', so AOP could also help.
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, AOP does the job.
In AOP i can get InvocationContext that include all the data, but in this enviroment i dont have AOP, so i need to create it by myself.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since Java 5, there is Thread.getStackTrace(). This returns StackTraceElements, which contain method names etc. It doesn't contain argument values, though.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!