Re: Using Beanshell as an expression evaluator

"Brent Easton" <[email protected]> Tue, 24 Jun 2008 09:51:09 +1000
Newsgroups gmane.comp.java.beanshell.user
Message-ID <[email protected]>
Thanks Stewart,

That explains it. I managed to stumble accross much the same solution last night. I have a subclass of Interpreter that does this

setClassLoader(this.getClass().getClassLoader());
setVar("_interp", this);

I can now access my context from a beanshell via _interp.xxxxxx() methods that I add to my custom Interpreter. 

Cheers,
Brent.
*********** REPLY SEPARATOR ***********

On 23/06/2008 at 2:49 PM Stewart Cambridge wrote:

I only gave a few snippets of the code base to give some ideas for the kind of framework that could be built.
It's actually a very large app, and for example, includes runtime configurable validation expressions through a custom Struts' validator, which populates the bsh namespace and runs a series of validations. Elsewhere the same namespace is used for other calulations and a rules engine.
The technique is indeed to set all values into the namespace before evaluation. I have to run a series of expressions, so it's more economical to set the namespace vars, run all the expressions, and then extract the vars back into the main code afterwards, rather than worrying about each expression individually.

The Spring application context is set once at start up, to be "bsh.shared.applicationContext". This means it is accessible accross namespaces. When a new Calculator is initialized, it is a convenience to eval "context = bsh.shared.applicationContext"
A bean is then accessed using context.getBean("beanname").


2008/6/23 Brent Easton <[email protected]>:

Hi Stewart,

The variables to be evaluated are set up in different parts of the application. Some are system defined, some are user defined. While it is not possible to list them all in advance and use set() to allocate values, any given value can be obtained by through a single getProperty(key) call in the main application. 

I am actually happy now with the implementation I have for the Expression evaluator. I evaluate once, find the undefined variables, set those with values from the application, the evaluate again to get a result. 

What I need for the general purpose script handling is a way to programatically callback into my application to determine the value of a given property.

I don't fully understand your example, but it is tantalizing. I feel I am missing something. Am I right that you are basically 'Settting' all available values into the NameSpace prior to evaluation? How do you reference a Spring value in a BeanShell?

Thanks,
Brent.
____________________________________________________________
Brent Easton                       
Analyst/Programmer                               
University of Western Sydney                                   
Email: [email protected]

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

_______________________________________________
Beanshell-users mailing list
Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/beanshell-users