Hi Finckler,

The issue is that you are trying to perform dynamic scripting in other words to contents of a variable. The interpretor does not expand the word o to the function you are trying to execute. However if I am not mistaken

i.eval("result = eval(/"o./"+g);");
System.out.println( i.get("result") );

Should work. That instucts the interpretor to execute the contents of o not simply to look for an o.

Hope that helps


On 10/3/07, Finckler, Christian <Christian.Finckler@ottogroup.com > wrote:
I would like to execute the following java-code:
                Interpreter i = new Interpreter();
                i.set("o", new OrderDetailVO());           //normal java bean
                i.set("g", "getQuantity()" );

                i.eval("result = o.getQuantity()");
                System.out.println( i.get("result") );     //this works

                i.eval("result = o.g");
                System.out.println( i.get("result") );     //this not

In this code, I would like to pass an object and a method name, that should be excecuted on the given object.
The first eval-expression works fine, but with the second expression I get the following exception:
Exception in thread "main" Sourced file: inline evaluation of: ``result = o.g;'' : Cannot access field: g, on object: orderws1.OrderDetailVO@10b4199 : at Line: 1 : in file: inline evaluation of: ``result = o.g;'' : o .g

The interpreter thinks, that the letter g is an attribute instead of an inputparameter string, that should be executed as method name.

How can i tell the interpreter, that it should replace the letter g first with the given string and then evaluate the expression?

I know that I can archive that directly with java reflection, but in the end, I would like to execute statements like this on an given object: getOrder().getCustomer().getAddress().getStreet().
With java-reflection this is not possible.

Thank you for your help,

This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Beanshell-users mailing list

09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0