• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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
  • 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.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic