Retrieving the caller of a method
I have used JPDA to get details about any methods being invoked, I would like to now get the details of the invoking method.
I have used the com.sun.jdi.request.*; and com.sun.jdi.event.*;packages to get to call the methodEntry method
whenever such an event occurs. From this I can get the details of the the method which is being invoked, however when
I use the code below to get the caller method(which exists in a different class) for a method in class Test the following is printed
out:
Caller instance of Test(id=53)
This is the code I am using:
void methodEntryEvent(MethodEntryEvent event) {
String methodName = event.method().toString();
System.out.println(methodName);
try{
System.out.println( "Caller " + event.thread().frame(0).thisObject());
} catch (IncompatibleThreadStateException itex) {}
}I would really appreciate it if someone could advise me on the way to get this to work as intended.
Thank you
Dave
then calling it's frame() method with index 0, which
from what I understand is supposed to return the
stackframe containing the caller method.Are you sure ?
frame
public StackFrame frame(int index)
throws IncompatibleThreadStateException
Returns the StackFrame at the given index in the thread's current call stack. Index 0
retrieves the current frame; higher indices retrieve caller frames. The thread must be
suspended (normally through an interruption to the VM) to get this information, and it is
only valid until the thread is resumed again.
Parameters:
index - the desired frame
Returns:
the requested StackFrame
Throws:
IncompatibleThreadStateException - if the thread is not suspended in the target VM
IndexOutOfBoundsException - if the index is greater than or equal to frameCount() or is negative.(from: http://java.sun.com/j2se/1.4.2/docs/guide/jpda/jdi/com/sun/jdi/ThreadReference.html#frame(int))
Similar Messages
-
How to retrieve the call logs of iphone programmatically??
Hi
how do I retrieve the call logs of iphone programmatically ?? I have searched Address book API no help there./....You can view and download call history with PhoneView.
Dave M.
MacOSG Founder/Ambassador An Apple User Group iTunes: MacOSG Podcast
Creator of 'Mac611 - Mobile Mac Support' (designed exclusively for an iPhone/iPod touch) -
How to retrieve the calling method
Hi all,
Is there anyway I can get the calling method from the method I am currently in e.g.:
thisclass..setup().getText()
and in getText can I check to see which method has called it?
Thanks in advance.You can extend SecurityManager to get an array containing the class context (just the calling class, not the calling method), or you can create a Throwable and get an array containing a trace of the stack.
-
How to retrieve the caller of a dynamically called vi?
Hi,
following situation:
A vi is loaded dynamically into a subpanel on the panel of the calling vi using the "run vi" property node. The called vi needs to know by what vi it was called. As we can learn from some contributions in the discussion forum or from own experiments, the name of the calling vi is only contained in the array given by the "Callers' Names" property node if the vi is called "by reference". If it is called by the "run vi" property node, then there seems to be no way to find out the identity of the caller from inside the vi that is being called. Is there at least any solution that makes use of the fact that the called vi is running in a subpanel on the panel of the caller? Is there a property to read from inside the called vi the identity of the subpanel the called vi is running in?
Because my explanation has probably already become rather confusing, I am attaching a simple example.
Peter
Solved!
Go to Solution.
Attachments:
caller_vi.vi 13 KB
called_vi.vi 7 KBI don't think there is a way to do that because as far as the VI in the panel is concerned, it's running as a top-level VI. One workardound is to use a control. When calling the VI use the VI Server to set the value of the control (with the Control Value -> Set method) to the name of the VI that's calling the VI. True, it requires you to use a control, but it's not that bad of a workaround.
-
How to find out the caller of a method?
Hi there,
I wonder if there is a recommended way to find out, from which code a method gets called. My only idea is to create a stacktrace with new Exception().getStackTrace() and inspect the 2nd stacktrace element. Does anyone know if there is a better (or recommended) way to do this?
Thanks, HansSounds like you really want two methods, one for internal use and one for external use. What you're asking for goes against good OOP principles.OK - in the mentioned case, i can get along with using two different methods. But for me it was not the first time that this question arised and i guess there might be cases where it would make sense to differentiate between callers. (In the core classes, for example, there is code which checks if certain methods are overridden in a sub-class and branches execution dependent on this information, which is a similar approach).
Thanks to all replying to my question - Hans -
How to handle the call transaction in method of a custom business object
Hello all,
There is a custom report " RPTCORAPP" for approving leaves . As per my requirement i have develop a copy of leave workflow and for approval process i have call "RPTCORAPP" in Custom method of custom object. i have made a transaction for this custom report for approving attendances. I am calling this method though call transaction statement within method.
Problem: while approving the attendance workitem is not disappearing from the portal. Problem is due to call transaction statement.
once workitem come to the user, user click on it. control goes to the report, which display all the leave to approve on
the portal.
If after approving/ rejecting attendance user close the screen.workflow remain in the "process" status.Control wont come back after call transaction statement in the method.
At the same time if user clicks on back button inspite of closing the screen. it is working fine. workitem disappears from the portal.
How to handle the scenarion. if after approving/rejecting, i want the control to come back to the NEXT STATEMENT after call transactionstatement in my method.
Please help it out........:)Hi swami,
thanks for reply. but i am not using BDC in my method. iam just calling a custom transaction thriugh statement
Call transaction 'ZHR_APPROVE_CLINOUT'. This transaction directly run the report RPTCORAPP and display all the request. -
What is the call to this method
I have a method that calculates the difference between two dates; todays date and a returndate for Library-books. I have a instance-method with the get-method mentioned below. But I can't figure out what call I must use so the program runs properly. Any hints ?
See code below.
import java.io.*;
import java.util.*;
import java.text.*;
public class DateGet{
public static void main(String[] args) throws IOException, ParseException{
System.out.print(LabMetoder.numberOfDays(days));
//This call is wrong, what should I write ?
}// end main
public static int numberOfDays (int days) {
String aLine, returnDate;
Date today = new Date(); // gets todays date
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Book checkDate;
Scanner fin = new Scanner (new FileReader("book.txt")); //open infile
while (fin.hasNext()) {
aLine=fin.nextLine();//reads first line
checkDate = new Book (aLine);//creates object
if (checkDate.getReturnDate()!=null) { // checks that returnDate-field
// isn't empty
String oldDay = (checkDate.getReturnDate());
Date oldDayD = dateFormat.parse(oldDay); //changes oldDay to a
//Dateobject
days = (int)( (today.getTime() - oldDayD.getTime())/
(1000*60*60*24));
//Calculates the difference between todays date and returnDate System.out.println(days);//writes dateobject on screen (this is
// a check)
} //end if
}// end while
fin.close(); //closes book.txt
return days;
}//end NumberOfDaysI have a method that calculates the difference
between two dates; todays date and a returndate for
Library-books. I have a instance-method with the
get-method mentioned below. But I can't figure out
what call I must use so the program runs properly.
Any hints ?
See code below.
import java.io.*;
import java.util.*;
import java.text.*;
public class DateGet{
public static void main(String[] args) throws
IOException, ParseException{
System.out.print(LabMetoder.numberOfDays(days));
//This call is wrong, what should I write ?
}// end main
public static int numberOfDays (int days) {
String aLine, returnDate;
Date today = new Date(); // gets todays date
SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyyMMdd");
Book checkDate;
Scanner fin = new Scanner (new
FileReader("book.txt")); //open infile
while (fin.hasNext()) {
aLine=fin.nextLine();//reads first line
checkDate = new Book (aLine);//creates object
if (checkDate.getReturnDate()!=null) { // checks that
returnDate-field
// isn't empty
String oldDay = (checkDate.getReturnDate());
Date oldDayD = dateFormat.parse(oldDay); //changes
oldDay to a
//Dateobject
days = (int)( (today.getTime() - oldDayD.getTime())/
(1000*60*60*24));
//Calculates the difference between todays date and
returnDate System.out.println(days);//writes
dateobject on screen (this is
// a check)
} //end if
}// end while
fin.close(); //closes book.txt
return days;
}//end NumberOfDays
I have a method that calculates the difference
between two dates; todays date and a returndate for
Library-books. I have a instance-method with the
get-method mentioned below. But I can't figure out
what call I must use so the program runs properly.
Any hints ?
See code below.
import java.io.*;
import java.util.*;
import java.text.*;
public class DateGet{
public static void main(String[] args) throws
IOException, ParseException{
System.out.print(LabMetoder.numberOfDays(days));
//This call is wrong, what should I write ?
}// end main
public static int numberOfDays (int days) {
String aLine, returnDate;
Date today = new Date(); // gets todays date
SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyyMMdd");
Book checkDate;
Scanner fin = new Scanner (new
FileReader("book.txt")); //open infile
while (fin.hasNext()) {
aLine=fin.nextLine();//reads first line
checkDate = new Book (aLine);//creates object
if (checkDate.getReturnDate()!=null) { // checks that
returnDate-field
// isn't empty
String oldDay = (checkDate.getReturnDate());
Date oldDayD = dateFormat.parse(oldDay); //changes
oldDay to a
//Dateobject
days = (int)( (today.getTime() - oldDayD.getTime())/
(1000*60*60*24));
//Calculates the difference between todays date and
returnDate System.out.println(days);//writes
dateobject on screen (this is
// a check)
} //end if
}// end while
fin.close(); //closes book.txt
return days;
}//end NumberOfDaysOK, here is the message again. Thanks.
I have a method that calculates the difference between two dates; todays date and a returndate for Library-books. I have a instance-method with the get-method mentioned below. But I can't figure out what call I must use so the program runs properly. Any hints ?
See code below.
import java.io.*;
import java.util.*;
import java.text.*;
public class DateGet{
public static void main(String[] args) throws IOException, ParseException{
System.out.print(LabMetoder.numberOfDays(days));
//This call is wrong, what should I write ?
}// end main
public static int numberOfDays (int days) {
String aLine, returnDate;
Date today = new Date(); // gets todays date
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Book checkDate;
Scanner fin = new Scanner (new FileReader("book.txt")); //open infile
while (fin.hasNext()) {
aLine=fin.nextLine();//reads first line
checkDate = new Book (aLine);//creates object
if (checkDate.getReturnDate()!=null) { // checks that returnDate-field
// isn't empty
String oldDay = (checkDate.getReturnDate());
Date oldDayD = dateFormat.parse(oldDay); //changes oldDay to a
//Dateobject
days = (int)( (today.getTime() - oldDayD.getTime())/
(1000*60*60*24));
//Calculates the difference between todays date and returnDate System.out.println(days);//writes dateobject on screen (this is
// a check)
} //end if
}// end while
fin.close(); //closes book.txt
return days;
}//end NumberOfDays -
Getting the call stack up to a certain location.
Dear friends,
I am searching for a function or method that can give me
the call stack(like in debug mode).
If you know of a function that provides this information
please let me know, its very urgent.
Thanks in advance,
Eitan Illuz.Hello Eli
You may have a look at thread:
[Get the name of a function module within a function module|Get the name of a function module within a function module;
Sample coding to retrieve the calling function module:
data:
lt_callstack TYPE abap_callstack.
CALL FUNCTION 'SYSTEM_CALLSTACK'
IMPORTING
callstack = lt_callstack.
READ TABLE lt_callstack
WITH KEY blocktype = 'FUNCTION'
blockname = 'CRM_ORDER_COPY_SINGLE_OW'
TRANSPORTING NO FIELDS.
CHECK sy-subrc NE 0.
Reference: [http://martins.de/call_stack_lesen.html]
Regards
Uwe -
Using dbms_metadata to retrieve the datatype and parameter name of a procedure
Greeting Guru,
is there a subprogram in dbms_metadata that will retrieve the call spec of a procedure/function that ideally
if the my program spec is proc1(id1 in number, cde in varchar2, id2 out number)
if I call something like
select * from table(dbms_metadata.<subprogram> ('proc2')) ;
It gives me
id1 in number
cde in varchar2
id2 out number
any ideas/pointers ?Hi,
Not really sure why you need it from dbms_metadata, but DESC and DBA_ARGUMENTS (dictionary view) would provide the same info. *_ARGUMENTS has lot more info in it
desc dbn
Argument Name Type In/Out Default
<return value> NUMBER OUT
P1 NUMBER IN
desc show_html_from_url
Argument Name Type In/Out Default
P_URL VARCHAR2 IN
> col owner format a10
> col object_name format a10
> col argument_name format a10
> select owner, object_name, argument_name, data_type, data_length, in_out
from dba_arguments a where object_name = 'DBN'
OWNER OBJECT_NAM ARGUMENT_N DATA_TYPE DATA_LENGTH IN_OUT
HR DBN P1 NUMBER 22 IN
HR DBN NUMBER 22 OUT
vr,
Sudhakar -
Call C# method from javascript in WebView and retrieve the return value
The issue I am facing is the following :
I want to call a C# method from the javascript in my WebView and get the result of this call in my javascript.
In an WPF Desktop application, it would not be an issue because a WebBrowser
(the equivalent of a webView) has a property ObjectForScripting to which we can assign a C# object containg the methods we want to call from the javascript.
In an Windows Store Application, it is slightly different because the WebView
only contains an event ScriptNotify to which we can subscribe like in the example below :
void MainPage_Loaded(object sender, RoutedEventArgs e)
this.webView.ScriptNotify += webView_ScriptNotify;
When the event ScriptNotify is raised by calling window.external.notify(parameter), the method webView_ScriptNotify is called with the parameter sent by the javascript :
function CallCSharp() {
var returnValue;
window.external.notify(parameter);
return returnValue;
private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
var parameter = e.Value;
var result = DoSomerthing(parameter);
The issue is that the javascript only raise the event and doesn't wait for a return value or even for the end of the execution of webView_ScriptNotify().
A solution to this issue would be call a javascript function from the webView_ScriptNotify() to store the return value in a variable in the javascript and retrieve it after.
private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
var parameter = e.Value;
var result = ReturnResult();
await this.webView.InvokeScriptAsync("CSharpCallResult", new string[] { result });
var result;
function CallCSharp() {
window.external.notify(parameter);
return result;
function CSharpCallResult(parameter){
result = parameter;
However this does not work correctly because the call to the CSharpResult function from the C# happens after the javascript has finished to execute the CallCSharp function. Indeed the
window.external.notify does not wait for the C# to finish to execute.
Do you have any solution to solve this issue ? It is quite strange that in a Window Store App it is not possible to get the return value of a call to a C# method from the javascript whereas it is not an issue in a WPF application.I am not very familiar with the completion pattern and I could not find many things about it on Google, what is the principle? Unfortunately your solution of splitting my JS function does not work in my case. In my example my CallCSharp
function is called by another function which provides the parameter and needs the return value to directly use it. This function which called
CallCSharp will always execute before an InvokeScriptAsync call a second function. Furthermore, the content of my WebView is used in a cross platforms context so actually my
CallCSharp function more look like the code below.
function CallCSharp() {
if (isAndroid()) {
//mechanism to call C# method from js in Android
//return the result of call to C# method
} else if (isWindowsStoreApp()) {
window.external.notify(parameter);
// should return the result of call to C# method
} else {
In android, the mechanism in the webView allows to return the value of the call to a C# method, in a WPF application also. But I can't figure why for a Windows Store App we don't have this possibility. -
How to call a bean method in the faces-config file?
Hi,
I would like in my menu to call the method of a bean (it initialize some properties before opening the page) instead of opening directly the page, by I can't find how to do that.
I tried :
<managed-property>
<property-name>viewId</property-name>
<value>#{listInformationsController.listInformations}</value>
</managed-property>
And :
<managed-property>
<property-name>outcome</property-name>
<value>#{listInformationsController.listInformations}</value>
</managed-property>
With no success...
Can someone help me?
Thank you and merry christmas !Hi,
a managed property only gives you a anlde to a bean or property, it doesn't execute it. To execute a bean, you can use a custom JSF PhaseListener that calls a bean method. The reference to the bean is achieve through value binding
ValueBinding vb = FacesContect.getCurrentInstance().getApplication().createValueBinding("Name of Managed Bean);
TypeOfBean theBean =(TypeOfBean) vb.getValue(FacesContext.getCurrentInstance());
.... theBean.theMethod() ...
Frank -
How to call a static method in a class if I have just the object?
Hello. I have an abstract class A where I have a static method blah(). I have 2 classes that extend class A called B and C. In both classes I override method blah(). I have an array with objects of type B and C.
For every instance object of the array, I'm trying to call the static method in the corresponding class. For objects of type B I want to call blah() method in B class and for objects of type C I want to call blah() method in C class. I know it's possible to call a static method with the name of the object, too, but for some reason (?) it calls blah() method in class A if I try this.
So my question is: how do I code this? I guess I need to cast to the class name and then call the method with the class name, but I couldn't do it. I tried to use getClass() method to get the class name and it works, but I didn't know what to do from here...
So any help would be appreciated. Thank you.As somebody already said, to get the behavior you
want, make the methods non-static.You all asked me why I need that method to be
static... I'm not surprised to hear this question
because I asked all my friends before posting here,
and all of them asked me this... It's because some
complicated reasons, I doubt it.
the application I'm writing is
quite big...Irrelevant.
Umm... So what you're saying is there is no way to do
this with that method being static? The behavior you describe cannot be obtained with only static methods in Java. You'd have to explicitly determine the class and then explicitly call the correct class' method. -
Calling static synchronized method in the constructor
Is it ok to do so ?
(calling a static synchronized method from the constructor of the same class)
Please advise vis-a-vis pros and cons.
regards,
s.giriI would take a different take here. Sure you can do it but there are some ramifications from a best practices perspective. f you think of a class as a proper object, then making a method static or not is simple. the static variables and methods belong to the class while the non-static variables and methods belong to the instance.
a method should be bound to the class (made static) if the method operates on the class's static variables (modifies the class's state). an instance object should not directly modify the state of the class.
a method should be bound to the instance (made non-static) if it operates on the instance's (non-static) variables.
you should not modify the state of the class object (the static variables) within the instance (non-static) method - rather, relegate that to the class's methods.
although it is permitted, i do not access the static methods through an instance object. i only access static methods through the class object for clarity.
and since the instance variables are not part of the class object itself, the language cannot and does not allow access to non-static variables and methods through the class object's methods. -
Calling another method in the class from within the body of a method Im wri
Hello out there.
I have a question. I keep getting an error that reads as follows:
1 error found:
File: /Users/matthieubell/Academia/University of Waterloo/CS 125/L06/CreditCard.java [line: 80]
Error: double cannot be dereferenced
I think it is occuring because I am trying to call a method on an instance variable, which is not an object. But how do call a method I have already written, on another method I am writing in the general sense. I could make a particular object, but Im not shure that would get me the same result. I want to be able to call the method calcMinPayment on the instance variable currentBalance to wirte the method makePayment.
I have a class CreditCard
with the instance variables "private double currentBalance = 0; "
public double calcMinPayment()
// Add code here
double minimumPayment;
if (currentBalance < 50)
minimumPayment = currentBalance/10;
else
minimumPayment = 50;
return minimumPayment; // Replace this statement
* This method will decrease the current balance on the credit card if
* this payment meets or exceeds the minimum payment amount.
* pre: paymentAmt > 0
* post: The current balance should be decreased by paymentAmt if
* paymentAmt >= the minimum payment amount. Otherwise, the payment
* will not be recorded and an appropriate error message should be
* displayed.
public void makePayment(double paymentAmt)
// Add code here
double minimumPaymentAmount;
minimumPaymentAmount = currentBalance.calcMinPayment();
if (paymentAmt < minimumPaymentAmount)
System.out.println("Sorry, but your payment must exceed the minimum payment amount.");
System.out.println("This payment has not been recorded, please try again.");
else
this.currentBalance = currentBalance - paymentAmt;
thanks for youre help
-Matthieu'calcMinPayment' takes no arguments, uses a member variable (currentBalance) to compute a local variable 'minimumPayment' which it returns, ie, sends back to the caller. So you can call 'calcMinPayment' at any time.
minimumPaymentAmount = calcMinPayment(); -
How to call standard SAP method in the Custom Program ?
Hi,
i need to call sap standard method 'OpenItemRollinout' in my custom program. For the SAP Standard method 'OpenItemRollinoun' the BOR(Business Object) is 'PAYSCHEME'. So how to call the SAP standard method in the custom program ???Hi,
In the method that you have provided only one function module is being used so better use the FM and copy the remaining code based on ur requirement.
FM is ISU_S_PAYSCHEME_ROLLIN_ROLLOUT.
Regards,
Vijay.
Maybe you are looking for
-
Reading Config Files in WPF without "My.Settings"
Please I need help on this.. I am working on a WPF project and I need to read an entry from the applicationSettings section of my configuration file in the Visual Studio 2008 WPF project. My.Settings.ValueToRead works very well and it returns what I
-
my paint tool won't work when I am painting on and off using actions. It was working then all of a sudden won't work
-
Eventually we have managed to get version 8 up and running both on client and web i.e. P6 Professional and P6 EPPM for want of a better name. It appears to be running smoothly at the moment. One of the issues I have found, is that when we have summar
-
Is there a way to mass rename native files on CS? We are using folders and have items in \abc\xyz and have discovered the files in that directory have the same native file names in another folder. Our issue is that in our workflow those files will mo
-
User changed to Calculate in POV
What does it mean when the username is changed to 'Calculate' in red on the bottom left of the POV?