syntax question about quick evaluation inside of java

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

syntax question about quick evaluation inside of java

Finckler, Christian
Hello,
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,
Christian

-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: syntax question about quick evaluation inside of java

Travis Bulford
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

Travis

On 10/3/07, Finckler, Christian <[hidden email]> wrote:
Hello,
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,
Christian

-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users



--
------------------------------------------------
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
------------------------------------------------
-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: syntax question about quick evaluation inside of java

Alexey Zinger
In reply to this post by Finckler, Christian
It should be:

Interpreter i = new Interpreter();
i.set("o", new OrderDetailVO()); //normal java bean
String g = "getQuantity()";
i.eval("o." + g); // not i.eval("o.g");

"Finckler, Christian" <[hidden email]> wrote:
Hello,
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,
Christian

-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users



Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net
http://wcollage.sourceforge.net


Building a website is a piece of cake.
Yahoo! Small Business gives you all the tools to get online.
-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: syntax question about quick evaluation inside of java

Finckler, Christian
Thank you,
with your help, I could solve it.
 
It works really good.
 
Thanks,
Christian
-----Urspr√ľngliche Nachricht-----
Von: Alexey Zinger [mailto:[hidden email]]
Gesendet: Donnerstag, 4. Oktober 2007 04:28
An: Finckler, Christian; [hidden email]
Betreff: Re: [Beanshell-users] syntax question about quick evaluation inside of java

It should be:

Interpreter i = new Interpreter();
i.set("o", new OrderDetailVO()); //normal java bean
String g = "getQuantity()";
i.eval("o." + g); // not i.eval("o.g");

"Finckler, Christian" <[hidden email]> wrote:
Hello,
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,
Christian

-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users



Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net
http://wcollage.sourceforge.net


Building a website is a piece of cake.
Yahoo! Small Business gives you all the tools to get online.

-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users