aspose file tools *
The moose likes Java in General and the fly likes How  To execute a function call 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  To execute a function call" Watch "How  To execute a function call" New topic
Author

How To execute a function call

ksparwez
Greenhorn

Joined: Sep 25, 2000
Posts: 2
Hi,
Iam doing a project to monitor the invocation of each package in a Java application. Iam sending each call to a function to my own method where I want to execute it. Iam passing the function call as a string to my function. I would like to know how will I be able to execute the string.
for example: if we have
System.out.println("Hello World"); in the original code. then Iam modifying the code as
mypackage.monitor("System.out.println("Hello World"); ");
where mypackage is the package containing the method monitor.
I would like to know how can I execute the command in monitor method and then go to the next line in the original source code.
Will anybody please help me.
-Parwez
Harish Kashyap
Ranch Hand

Joined: Jun 14, 2000
Posts: 118
hi
i think u r doing it wrong way.
u can't do it the way u r trying. because when u r passing the statement as an string it is getting compiled as a string. no way it can give u correct results. moreover u extract statement in the monitor method but its not compiled as a java statement, it can't run.
u can run operating system commands like that but once compiler has done its job and code is handed over to the interpretter it can't come back to compiler by itself just for 1 or 2 statements.
think some other way out for your application.
harish
Doug Gschwind
Greenhorn

Joined: Sep 17, 2000
Posts: 27
Looks like the Method class (java.lang.reflect, JDK 1.2.2) may be of some help, as would the java.lang.Class class. You would then have object references that you could pass to monitor() to have it execute the given Method in a given Class or something similar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How To execute a function call