Get a variable by a name string? how

Hi,
I am currently developing an interpreter which is of cause a class.
This interpreter will be initiated with several pieces of strings mixed
with unknown number of variables with some order which is unknown previously.
So the better way is just passing one string which contains the variable
name strings and return a collection of variables specified by the variable
ames contained in this string.
Problem is:
How can I get a variable from a name string, instead of a name
     variable?
     Java Reflection can only return fields, but not variables
     Any idea?
     And how JNI could do perphaps?
Any help appreciated
Thanks in adv
dunson

As far as i know, the names of local variables, that are only used inside methods, are not preserved in the bytecode. That means you can't grab from them by name, whatever you do. You are able to grab members though, through reflection, but it's not very efficient. I wouldn't recommend it.
As suggested, I think you need to make special provision for this with a structure like a Hashtable. It's better programming practice, it's more efficient, and you'll find it much easier to program.
Something like this:
import java.util.*;
class Doodad {
  Map stuff = new HashMap();
  Object getValue(String code) {
    return stuff.get(code);
  void setValue(String code, Object value) {
    stuff.put(code, value);

Similar Messages

  • Get a variable by a name string?

    Hi,
    I am currently developing an interpreter.
    This interpreter will be initiated with several pieces of strings mixed
    with unknown number of variables with some order which is unknown previously.
    So the better way is just passing one string which contains the variable
    name strings and return a collection of variables specified by the variable
    names contained in this string.
    Problem is:
    How can I get a local variable from a name string in a method, instead of
    by a name variable?
    Java Reflection can only return fields, but not variables
    Any idea?
    And does JNI could do it?
    Any help appreciated
    Thanks in adv
    dunson

    Interpreter for what?

  • APT - getting declared variables and parameter names

    Hi,
    I would like start using APT, but if I am not mistaken, there are severe limitations what you can do with the tool. How is it possible to get the declared name of variables or parameters and methods from the apt tool?
    @someAnnotation
    public void someMethod(A para1, B para2) {...}I would need to get the name of the method and the name of the parameters to generate new sourcecode (AspectJ -Source), how is this possible? Without the names I cannot call the method from another place right?
    Where can I find the planned features for APT? It is a pitty that the tool is in a way very powerful and in another so limitated because you cannot extract the sourcecode or names.
    Regards,
    Klaas

    What about getSimpleName? This method is defined on
    declarations.You know, ParameterDeclaration is a Declaration ...
    All of the declarations returned by
    the mirror API are for elements that exist inside
    classes, not inside methods.Huh? Parameters are an integral part of methods and methods are elements that exist inside classes (or types in general). What's your point?
    The apt API does not expose any information about the
    interiors of methods or constructors.Oh boy. For a ParameterDeclaration getSimpleName() will return the name of the parameter, e.g. suppose you are "scanning" a standard main method:public static void main(String[] args) {...}and you already have the ParameterDeclaration instance representing the sole parameter of the method, then getSimpleName() will return "args".
    BTW - this has nothing to do with exposing interiors. Just try it.

  • When I send a text to my wife i get her reply under another name. How do I fix this?

    Since I got my iPhone 4S when I text my wife her replies come under my old hotmail address name. Very strange indeed. I have tried deleting her as a contact and then renaming her but still the same. The old hotmail address isn't even listed as one of my contacts so I'm puzzled as to how this is possible.
    Any ideas?

    Thank you very much Razmee. Didn't expect such a quick reply. That worked perfectly

  • Sharepoint Workflow : how to get document full path + file name into variable?

    Hi,
    Anybody knows how to get document full path + file name into a variable in Sharepoint 2010 workflow?
    Example http://sp1:80/InvoiceQueue/Shared Documents/123.pdf
    I am using List Workflow which links to a document library.

    Hi SAMSUNG,
    According to your description, my understanding is that you want to get the full path of a document in a list workflow.
    You can set the variable to the Enconded Absolute URL of the document. The screenshot is my testing. In my testing (in the red area), when the title of a document was equal to the tile of the current item, set a variable to the Enconded Absolute URL of the
    document. I used ‘Log to history list’ to check the value of the variable in Workflow History .
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • How can I convert the variable expression stored as string back to variable expression

    How can I convert the variable expression stored as string back to variable expression?
    I am storing the expression enterd in the TSExpresssionEditControl as simple string and want to convert back to expression since I want to get the data type of that expression.

    pritam,
    I'm not sure what you're trying to do exactly. If you are trying to get the value of a variable and you only have the name of value in a string, then you can use Evaluate() to get its value. If you want the data type, my advise is to use the GetPropertyObject() API method and just pass in the loop up string. Then you'll have a handle to the data object and then proceed from there.
    Regards,
    Song D
    Application Engineer
    National Instrument
    Regards,
    Song Du
    Systems Software
    National Instruments R&D

  • Getting the variable name

    Hi
    May be a simple question, but I can't figure out how actually.
    When I'm doing this
    var obj:Object = new Object();
    obj.test = "My Test";
    for(var i:* in obj)
         trace(i + " : " + obj[i]);    
    The output is -> test : My Test
    My problem comes when I put an object inside the object
    var obj:Object = new Object();
    obj.test = new Object()
    obj.test.secondTest = "My Test";
    for(var i:* in obj)
         trace(i + " : " + obj[i]);    
    The output is -> test : [object Object]
    So any idea how to get the variable name instead of [object Object], just like the first output but with the second code. I have an object inside an object.
    Thanks

    The following approach will dig it's way in.  I added other variables to the main object just for demo sake...
    var obj:Object = new Object();
    obj.test1 = "test string";
    obj.test = new Object();
    obj.test.secondTest = "My Test";
    obj.test2 = new Object();
    obj.test2.secondTest2 = new Object();
    obj.test2.secondTest2.val = "deeper test";
    function traceObjectVars(obj_arg:Object):void {
          for(var i:* in obj_arg){
                if(typeof(obj_arg[i]) == "object"){
                      traceObjectVars(obj_arg[i]);
                } else {
                     trace(i + " : " + obj_arg[i]);
    traceObjectVars(obj);

  • How do I use the event.target.name String with an external dispatchEvent?

    ...I hope the title question makes sense...
    On my stage I have an externally loaded SWF with a button. When clicked the button dispatches an event to the main stage.
    On the main stage a listener then loads an SWF into a loader called gallery.
    The gallery loader is also being shared by buttons on the main stage which use the event.target.name String to call in SWFs with corresponding names.
    I am using Tweens to fade-out and -in content to the gallery when a button is pressed.
    Loading the SWFs was working until I tried to create a universal button function for the dispatchEvent buttons...
    The problem I have is that I don't know how to define the String to tell the newSWFRequest where to find the SWF when triggered by the external buttons.
    (I may be doing this all wrong... but figured the best way to load an SWF on to the main stage from an external SWF was by using dispatchEvent??)
    My code triggers the Event and the gallery loader fades out, but then it cannot find the new SWF:
    Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
    Please can someone help me understand the way to make the String point in the right direction? (I think the only errors are in bold below)
    Code:
    var myTweenIn2:Tween;
    var myTweenOut2:Tween;
    var nextLoadS2:String;
    // Listen for external event dispatched from external btns
    addEventListener("contactStage", btnClickExtrnl);
    function btnClickExtrnl(e:Event):void {
    nextLoadS2 = ?????
    myTweenOut2=new Tween(gallery,"alpha",None.easeOut,gallery.alpha,0,0.2,true);
    myTweenOut2.addEventListener(TweenEvent.MOTION_FINISH,tweenOutCompleteF2);
    // Btns Universal function
    function tweenOutCompleteF2(e:TweenEvent){
    myTweenOut2.removeEventListener(TweenEvent.MOTION_FINISH,tweenOutCompleteF2);
    myTweenOut2=null;
        var newSWFRequest:URLRequest = new URLRequest("swfs/" + nextLoadS2 + ".swf");
    myTweenIn2 = new Tween(gallery, "alpha", None.easeOut, gallery.alpha, 1, 0.2, true);
        gallery.load(newSWFRequest);
        gallery.x = Xpos;
        gallery.y = Ypos;
    Thank you.

    That works – thank you!
    I'm now using this code to fade in each of the SWFs:
    function contactStage(e:MouseEvent):void {
        var newSWFRequest:URLRequest = new URLRequest("swfs/"+e.currentTarget.name+".swf");
        myTweenIn = new Tween(gallery,  "alpha", None.easeOut, 0, 1, 0.2, true);
        gallery.load(newSWFRequest);
        gallery.x = Xpos;
        gallery.y = Ypos;
    But I cannot add the fade out function. I have amended the above code to create:
    var myTweenOutX:Tween;
    var myTweenInX:Tween;
    function contactStage(e:MouseEvent):void {
    myTweenOutX=new Tween(gallery,"alpha",None.easeOut,gallery.alpha,0,0.2,true);
    myTweenOutX.addEventListener(TweenEvent.MOTION_FINISH,tweenOutCompleteFX);
    function tweenOutCompleteFX(e:TweenEvent){
    myTweenOutX.removeEventListener(TweenEvent.MOTION_FINISH,tweenOutCompleteFX);
    myTweenOutX=null;
        var newSWFRequest:URLRequest = new URLRequest("swfs/"+e.currentTarget.name+".swf");
    myTweenInX = new Tween(gallery,  "alpha", None.easeOut, 0, 1, 0.2, true);
        gallery.load(newSWFRequest);
        gallery.x = Xpos;
        gallery.y = Ypos;
    But get this error:
    ReferenceError: Error #1069: Property name not found on fl.transitions.Tween and there is no default value.
    at ACOUSTIC_fla::MainTimeline/tweenOutCompleteFX()[ACOUSTIC_fla.MainTimeline::frame1:110]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at fl.transitions::Tween/set time()
    at fl.transitions::Tween/nextFrame()
    at fl.transitions::Tween/onEnterFrame()
    Where am I going wrong?

  • How can I get a list of the names of the failed steps ?

    Hi,
       I wanted to have a string which can describe all the failed steps. For example, if I had the steps below :
    Step 1
    Step 2
    Step 3, etc
    and Step 1 and Step 3 failed, how can I get a string " Step1, Step2" ?
    Can I somehow add a variable in each step which records the step result and then use all the variables at the end to creat a Result string ?
    Please help.
    ~Sam~

    Sam,
    you have at least two possibilities for your question:
    a) use the "SequencePostResultListEntry"-callback. You can check the "Step.Result.Status". If it is failed, you can copy the stepname into a string-variable which builds your "string"
    b) In the end of your MainSequence, just browse your ResultList for every step which has Result.Status as failed. Copy all stepnames into your string.
    Both methods require your station to record results, but since this is defaultsetting, there shouldn't be a problem.
    hope this helps,
    Norbert B.
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • How can I get the variable with the value from Thread Run method?

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    // I should get Inside the run method::: But I get only Inside
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    We want to access a variable from the run method of a
    Thread externally in a class or in a method. I presume you mean a member variable of the thread class and not a local variable inside the run() method.
    Even
    though I make the variable as public /public static, I
    could get the value till the end of the run method
    only. After that scope of the variable gets lost
    resulting to null value in the called method/class..
    I find it easier to implement the Runnable interface rather than extending a thread. This allows your class to extend another class (ie if you extend thread you can't extend something else, but if you implement Runnable you have the ability to inherit from something). Here's how I would write it:
    public class SampleSynchronisation
      public static void main(String[] args)
        SampleSynchronisation app = new SampleSynchronisation();
      public SampleSynchronisation()
        MyRunnable runner = new MyRunnable();
        new Thread(runner).start();
        // yield this thread so other thread gets a chance to start
        Thread.yield();
        System.out.println("runner's X = " + runner.getX());
      class MyRunnable implements Runnable
        String X = null;
        // this method called from the controlling thread
        public synchronized String getX()
          return X;
        public void run()
          System.out.println("Inside MyRunnable");
          X = "MyRunnable's data";
      } // end class MyRunnable
    } // end class SampleSynchronisation>
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run
    method "+sathr.x);
    // I should get Inside the run method::: But I get
    only Inside
    class sampleThread extends Thread
    public String x="Inside";
    public void run()
    x+="the run method";
    NB: if i write the variable in to a file I am able to
    read it from external method. This I dont want to do

  • How can I get the variable with the value from Thread's run method

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get:
    Inside the run method
    But I get only:
    Inside*/
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    Your main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.

  • How do I get a variable, or object from ABAP STACK.

    Hey Gurus,
    How do I get a variable, or object from ABAP STACK.
    Example: I start my FM. I can see in the ABAP STACK the variable I need. I can see the object; I could use to get my variable. I need to use it in my FM; however I need to reference it in the run time. How do I do that?
    Is there a method I can use for reading ABAP STACK?
    Do I just use command: get reference of u2026?
    Does anyone have an example code?
    Basis version 7
    Thanks in advance
    Martin

    Ah, you mean you want to access a variable from another program in the call stack, yes?  You can do this using field symbols, but please don't try to change a value while doing this, it could really screw things up. 
    this example, is using two programs, where the second is accessing variables of the first program.  Basically just notice that we are using the program name and the variable name when assigning the field symbol.
    report zrich_0006 .
    tables: mara.
    parameters: p_matnr type mara-matnr..
    data: matnr type mara-matnr.
    data: imarc type table of marc with header line.
    matnr = p_matnr.
    select * from marc into table imarc up to 10 rows
                   where matnr = p_matnr.
    perform in in program zrich_0007.
    report zrich_0007 .
    *       FORM in                                                       *
    form in.
      data: field(50).
      data: xmarc type marc.
      field-symbols: <matnr>.
      field-symbols: <imarc> type marc_upl_tt.
    * Assign an individual variable
      field = '(ZRICH_0006)matnr'.
      assign (field) to <matnr>.
    * Assign an internal table
      field = '(ZRICH_0006)IMARC[]'.
      assign (field) to <imarc>.
    * Write out your data
      write <matnr>.
      loop at <imarc> into xmarc.
        write: / xmarc-werks.
      endloop.
    endform.
    Regards,
    Rich Heilman

  • How can i get this variable value into second page IN BSP

    Hi friends
    I have variable wk_matnr value 'ABC' in first page of BSP.
    How can i get this variable value into second page.
    Moosa

    Hi,
    you can define variable (page attribiue) on the second page with the same name. You can realise the Navigation with Button ther started onInputProcesing routine. In onInputProcesing you have to call navigation->set_parameter with attribut name as parameter and then starting the navigation. If you have checked the auto property on the variable on second page and varable have same name, the value of variable should be transported.
    [See this tutorial|http://help.sap.com/saphelp_erp2005/helpdata/DE/1a/c5133a62983c0ae10000000a114084/frameset.htm]
    Best regards
    Bogdan

  • How could I delete files with name string with "TAL" and older than 05.05.

    How could I delete files with name string with "TAL" and older than 05.05.2009 on unix

    Our ECC Ides system today was not responsible. For first time 17 users were working on the systtem (IWN2008/SQL2005 based). Before the people were maximally 5.
    The server is done by making a homogeneous system copy from an blade machine(now it is an VIrTUAL)
    There was enaught disk space. However I checked Wokload 03sdn transaction) inn system. and found out that at that time of restarting(I had to restart system 3 times to get logged on the system and even then it was almost unresponsive.
    I can found in there top abap."Login_Pw", "SESSION_MANAGER", "?". (BAtch), "ADMSBUF, >DEleyed Function call, RSPOWPOO""RSWWclear", ""VA01", "SAPMHHTP  "Buf  Sync" >DDLOC CLEANUP)""rsbtctE"
    What can I do?
    ¸
    Who could interfer SAP_CCMS_MONI_BATCH_DPSAP_CCMS_MONI_BATCH_DP
    the 2 main users under users profile were ZUGTIN running and SAPSYS( running many system jobs)
    How to approach the problem

  • How can I get a list of database names from environment

    Hi,
    How can I get a list of database names from environment.
    I had found a method in JE API Docs named Environment.getDatabaseNames(), and i couldn't found the same method in Berkeley DB.
    I use java interface, is it supported?
    Thanks.

    Hello,
    I don't know if it would work for you, but have you checked the db_archive utility at:
    http://download.oracle.com/docs/cd/E17076_01/html/api_reference/C/db_archive.html
    Check the -s option.
    Thanks,
    Sandra

Maybe you are looking for

  • Update error code 80070490

    My laptop is not updating and always showing code error 80070490. Update encounter an unknown error Pls. need help! what to do?

  • Urgent Issue in Plant Maintenance Module

    Dear Experts, We have requirement as described below, please give us your solutions / comments on this. We have GTC company which is having around 800 trucks for transporting the products. I n this company we have implemented SAP Plant Maintenance Mo

  • More than one table of content

    Hi, I need to put more than one table of content (contents, illustrations, tables). Is there a way to do this? When I add the second table, the first one disapears. Thank you!

  • MacBook Pro Retina "Gets Hot when viewing RAW images"

    MacBook Pro Retina Gets really Hot when viewing RAW images - somebody has this issue? Solutions?

  • My touch screen doesnt work!!

    ive had this problem before but only for a minute. my friends were sending me text messages this mornin but i was to lazy to go look since i broke my leg. when my mom called me i couldnt slide it open or anything!! plz help