• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get method invocation context

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic