File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How force code execute before native method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How force code execute before native method?" Watch "How force code execute before native method?" New topic
Author

How force code execute before native method?

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Let's say I have a native method called "doSomething()" and there is other code written by other people that calls it, which I cannot change. Let's also assume I cannot change the native C code either, so I'm stuck with the name of the native method. How would I "wrap" the call to the native nethod "doSomething()" so that it checked for a security permission first?
Normally (if I could change the name) I'd do:

The above would break only code that uses reflection where it looks for and executes any method flagged as native, but that's a small price. HOWEVER, I cannot change the C code, so I'm unable to do the above. Also, I cannot change the code of the calling classes. What's the solution here? I'm stumped.
[ January 23, 2004: Message edited by: Robert Paris ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

OK, here's what you do. Make exactly the change you show above. Implement the Java_package_doSomething0() function in C. Have it call the existing Java_package_doSomething() function, forwarding all the arguments, and Bob's your uncle!


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How force code execute before native method?