Quantcast

Using Beanshell as an expression evaluator

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using Beanshell as an expression evaluator

Brent Easton-2

I am trying to work out the best way to integrate Beanshell into my application. I want to use Beanshell to add the ability to parse and evaluate arbitrarily complex expressions typed in by users.

For example

  20 * xpos + ypos/2

The expressions are entered and validated at one point of time, but are evaluated much later, in a different phase of operation of the program when xpos and ypos will have determinable values.

I have successfully used the Parser to parse and validate the structure of expression.

My problem is determining and binding values to the variables in the expression at runtime. The variables 'xpos' and 'ypos' (plus a host of other 'variables') are not predetermined at the time the expression is created.

At evaluation time, I need to determine what variables are used in the expression are undefined, then bind them to values from my application, evaluate the expression and then return the result to my application.

Any pointers would be appreciated.

Regards,
Brent.







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

Re: Using Beanshell as an expression evaluator

Stewart Cambridge

Check the bsh.Interpreter class. The methods set(), unset() and eval() may help you.


2008/6/22 Brent Easton <[hidden email]>:

I am trying to work out the best way to integrate Beanshell into my application. I want to use Beanshell to add the ability to parse and evaluate arbitrarily complex expressions typed in by users.

For example

 20 * xpos + ypos/2

The expressions are entered and validated at one point of time, but are evaluated much later, in a different phase of operation of the program when xpos and ypos will have determinable values.

I have successfully used the Parser to parse and validate the structure of expression.

My problem is determining and binding values to the variables in the expression at runtime. The variables 'xpos' and 'ypos' (plus a host of other 'variables') are not predetermined at the time the expression is created.

At evaluation time, I need to determine what variables are used in the expression are undefined, then bind them to values from my application, evaluate the expression and then return the result to my application.

Any pointers would be appreciated.

Regards,
Brent.







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


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

Re: Using Beanshell as an expression evaluator

Brent Easton-2
Thanks Stewart,
 
I was aware of those, but the problem is how do you find out which variables are undefined and need to be set? The set of variables available is not canonical.
 
I have got something working by subclassing NameSpace with a custom getVariableImpl implementation that builds a list of undefined variables. When an expression is created, I do a test evaluation and record the list of undefined variables. When the expression is to be evaluated for real, I use bind the known undefined variables to the current property values.

This seems to be working fine for the limited use of evaluating a single expression. My next task is to implement a more general script object. What I really need to work out is how to dynamically reference property values in my main application from within beanscript. Slowly getting there.

Regards,

Brent.


*********** REPLY SEPARATOR ***********

On 23/06/2008 at 11:21 AM Stewart Cambridge wrote:


Check the bsh.Interpreter class. The methods set(), unset() and eval() may help you.


2008/6/22 Brent Easton <[hidden email]>:

I am trying to work out the best way to integrate Beanshell into my application. I want to use Beanshell to add the ability to parse and evaluate arbitrarily complex expressions typed in by users.

For example

 20 * xpos + ypos/2

The expressions are entered and validated at one point of time, but are evaluated much later, in a different phase of operation of the program when xpos and ypos will have determinable values.

I have successfully used the Parser to parse and validate the structure of expression.

My problem is determining and binding values to the variables in the expression at runtime. The variables 'xpos' and 'ypos' (plus a host of other 'variables') are not predetermined at the time the expression is created.

At evaluation time, I need to determine what variables are used in the expression are undefined, then bind them to values from my application, evaluate the expression and then return the result to my application.

Any pointers would be appreciated.

Regards,
Brent.







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


____________________________________________________________
Brent Easton                      
Analyst/Programmer                              
University of Western Sydney                                  
Email:
[hidden email]

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

Re: Using Beanshell as an expression evaluator

Stewart Cambridge

I'm not sure if I understood your requirements correctly.

It seems to me that if your scripts are truly and totally dynamic, then you cannot know before hand what variables will need to be populated into the interpreter context - the user could write anything.

I once used beanshell to create a perfectly workable expression calculator and rules engine for a financial services application.
I had such mechanisms as:
-------------
public interface Populatable extends Dynamic
{
  void setCode(String code);
  Class getContextClass();
}
-------------
public interface Calculatable extends Populatable, Checkable
{
    String getCalculation();
}
-------------
public interface CalculatorContext
{
    Populatable[] getPopulatables();
}
-------------
/**
 * Populates the Spring ApplicationContext into the Beanshell's shared namespace.
 */
public class ApplicationContextAwareCalculatorPopulator implements ApplicationContextAware
{
  public void setApplicationContext( ApplicationContext cxt )
    throws BeansException
  {
    try
    {
      Interpreter i = new Interpreter();
      i.set( Calculator.APPLICATION_CONTEXT, cxt);
      i.eval("bsh.shared." + Calculator.APPLICATION_CONTEXT + " = " + Calculator.APPLICATION_CONTEXT);
    }
    catch(EvalError e)
    {
.......
    }
  }
}
-------------
//Calculator class
  public Calculator( CalculatorHolder holder )
    throws EvalError
  {
    this.interpreter = new Interpreter();
interpreter.getNameSpace().importCommands( Calculator.class.getPackage().getName() ); // pre-defined calculator functions
// gives access to spring beans via bsh.shared
    interpreter.eval( APPLICATION_CONTEXT + " = bsh.shared." + APPLICATION_CONTEXT );
.......
}

  public void init( CalculatorContext populateFromContext )
    throws EvalError
  {
    Populatable[] populatables = populateFromContext.getPopulatables();
    for ( int i = 0; i < populatables.length; i++ )
    {
........etc
-------------

I have absolutely no idea if this is helpful to you or not.
The calculation expressions and "populatables" were configured through a database, so that ultimately there was a well defined set of expression variables. The expressions could be changed at runtime by the user and did reference objects (the "populatables") fetched via hibernate and injected into the calculator context, as well as all the Spring beans my app was built upon.
If the user tried to reference a populatable or bean that didn't exist, I'd just catch the EvalError and report it to the user.
Ultimately, what else can you do? If the user doesn't set "xpos", then it's an error, plain and simple.
You've constructed a list of unset variable that the user needs to set before the expression is run, but if the user doesn't set one, what can you do that's different to a general EvalError? I suppose you can pinpoint specifically what is not set, and include that in your friendly error message.



2008/6/23 Brent Easton <[hidden email]>:
Thanks Stewart,
 
I was aware of those, but the problem is how do you find out which variables are undefined and need to be set? The set of variables available is not canonical.
 
I have got something working by subclassing NameSpace with a custom getVariableImpl implementation that builds a list of undefined variables. When an expression is created, I do a test evaluation and record the list of undefined variables. When the expression is to be evaluated for real, I use bind the known undefined variables to the current property values.

This seems to be working fine for the limited use of evaluating a single expression. My next task is to implement a more general script object. What I really need to work out is how to dynamically reference property values in my main application from within beanscript. Slowly getting there.

Regards,

Brent.


*********** REPLY SEPARATOR ***********


On 23/06/2008 at 11:21 AM Stewart Cambridge wrote:

Check the bsh.Interpreter class. The methods set(), unset() and eval() may help you.


2008/6/22 Brent Easton <[hidden email]>:

I am trying to work out the best way to integrate Beanshell into my application. I want to use Beanshell to add the ability to parse and evaluate arbitrarily complex expressions typed in by users.

For example

 20 * xpos + ypos/2

The expressions are entered and validated at one point of time, but are evaluated much later, in a different phase of operation of the program when xpos and ypos will have determinable values.

I have successfully used the Parser to parse and validate the structure of expression.

My problem is determining and binding values to the variables in the expression at runtime. The variables 'xpos' and 'ypos' (plus a host of other 'variables') are not predetermined at the time the expression is created.

At evaluation time, I need to determine what variables are used in the expression are undefined, then bind them to values from my application, evaluate the expression and then return the result to my application.

Any pointers would be appreciated.

Regards,
Brent.







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


____________________________________________________________
Brent Easton                      
Analyst/Programmer                              
University of Western Sydney                                  
Email:
[hidden email]


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

Re: Using Beanshell as an expression evaluator

Brent Easton-2
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.
 

*********** REPLY SEPARATOR ***********

On 23/06/2008 at 12:31 PM Stewart Cambridge wrote:

I'm not sure if I understood your requirements correctly.

It seems to me that if your scripts are truly and totally dynamic, then you cannot know before hand what variables will need to be populated into the interpreter context - the user could write anything.

I once used beanshell to create a perfectly workable expression calculator and rules engine for a financial services application.
I had such mechanisms as:
-------------
public interface Populatable extends Dynamic
{
  void setCode(String code);
  Class getContextClass();
}
-------------
public interface Calculatable extends Populatable, Checkable
{
    String getCalculation();
}
-------------
public interface CalculatorContext
{
    Populatable[] getPopulatables();
}
-------------
/**
 * Populates the Spring ApplicationContext into the Beanshell's shared namespace.
 */
public class ApplicationContextAwareCalculatorPopulator implements ApplicationContextAware
{
  public void setApplicationContext( ApplicationContext cxt )
    throws BeansException
  {
    try
    {
      Interpreter i = new Interpreter();
      i.set( Calculator.APPLICATION_CONTEXT, cxt);
      i.eval("bsh.shared." + Calculator.APPLICATION_CONTEXT + " = " + Calculator.APPLICATION_CONTEXT);
    }
    catch(EvalError e)
    {
.......
    }
  }
}
-------------
//Calculator class
  public Calculator( CalculatorHolder holder )
    throws EvalError
  {
    this.interpreter = new Interpreter();
interpreter.getNameSpace().importCommands( Calculator.class.getPackage().getName() ); // pre-defined calculator functions
// gives access to spring beans via bsh.shared
    interpreter.eval( APPLICATION_CONTEXT + " = bsh.shared." + APPLICATION_CONTEXT );
.......
}

  public void init( CalculatorContext populateFromContext )
    throws EvalError
  {
    Populatable[] populatables = populateFromContext.getPopulatables();
    for ( int i = 0; i < populatables.length; i++ )
    {
........etc
-------------

I have absolutely no idea if this is helpful to you or not.
The calculation expressions and "populatables" were configured through a database, so that ultimately there was a well defined set of expression variables. The expressions could be changed at runtime by the user and did reference objects (the "populatables") fetched via hibernate and injected into the calculator context, as well as all the Spring beans my app was built upon.
If the user tried to reference a populatable or bean that didn't exist, I'd just catch the EvalError and report it to the user.
Ultimately, what else can you do? If the user doesn't set "xpos", then it's an error, plain and simple.
You've constructed a list of unset variable that the user needs to set before the expression is run, but if the user doesn't set one, what can you do that's different to a general EvalError? I suppose you can pinpoint specifically what is not set, and include that in your friendly error message.



____________________________________________________________
Brent Easton                      
Analyst/Programmer                              
University of Western Sydney                                  
Email:
[hidden email]

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

Re: Using Beanshell as an expression evaluator

Stewart Cambridge

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 <[hidden email]>:
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.
 

*********** REPLY SEPARATOR ***********


On 23/06/2008 at 12:31 PM Stewart Cambridge wrote:

I'm not sure if I understood your requirements correctly.

It seems to me that if your scripts are truly and totally dynamic, then you cannot know before hand what variables will need to be populated into the interpreter context - the user could write anything.

I once used beanshell to create a perfectly workable expression calculator and rules engine for a financial services application.
I had such mechanisms as:
-------------
public interface Populatable extends Dynamic
{
  void setCode(String code);
  Class getContextClass();
}
-------------
public interface Calculatable extends Populatable, Checkable
{
    String getCalculation();
}
-------------
public interface CalculatorContext
{
    Populatable[] getPopulatables();
}
-------------
/**
 * Populates the Spring ApplicationContext into the Beanshell's shared namespace.
 */
public class ApplicationContextAwareCalculatorPopulator implements ApplicationContextAware
{
  public void setApplicationContext( ApplicationContext cxt )
    throws BeansException
  {
    try
    {
      Interpreter i = new Interpreter();
      i.set( Calculator.APPLICATION_CONTEXT, cxt);
      i.eval("bsh.shared." + Calculator.APPLICATION_CONTEXT + " = " + Calculator.APPLICATION_CONTEXT);
    }
    catch(EvalError e)
    {
.......
    }
  }
}
-------------
//Calculator class
  public Calculator( CalculatorHolder holder )
    throws EvalError
  {
    this.interpreter = new Interpreter();
interpreter.getNameSpace().importCommands( Calculator.class.getPackage().getName() ); // pre-defined calculator functions
// gives access to spring beans via bsh.shared
    interpreter.eval( APPLICATION_CONTEXT + " = bsh.shared." + APPLICATION_CONTEXT );
.......
}

  public void init( CalculatorContext populateFromContext )
    throws EvalError
  {
    Populatable[] populatables = populateFromContext.getPopulatables();
    for ( int i = 0; i < populatables.length; i++ )
    {
........etc
-------------

I have absolutely no idea if this is helpful to you or not.
The calculation expressions and "populatables" were configured through a database, so that ultimately there was a well defined set of expression variables. The expressions could be changed at runtime by the user and did reference objects (the "populatables") fetched via hibernate and injected into the calculator context, as well as all the Spring beans my app was built upon.
If the user tried to reference a populatable or bean that didn't exist, I'd just catch the EvalError and report it to the user.
Ultimately, what else can you do? If the user doesn't set "xpos", then it's an error, plain and simple.
You've constructed a list of unset variable that the user needs to set before the expression is run, but if the user doesn't set one, what can you do that's different to a general EvalError? I suppose you can pinpoint specifically what is not set, and include that in your friendly error message.



____________________________________________________________
Brent Easton                      
Analyst/Programmer                              
University of Western Sydney                                  
Email:
[hidden email]


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

Re: Using Beanshell as an expression evaluator

Alexey Zinger
In reply to this post by Brent Easton-2
Is there a reason you couldn't use your extended NameSpace object at runtime to check for any unretrieved variables?  I'm not familiar with your project's specifics, but I can't imagine any reason you couldn't do this.  Is there something your application knows at expression "compile" time it doesn't know at "run" time?

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



--- On Mon, 6/23/08, Brent Easton <[hidden email]> wrote:

> From: Brent Easton <[hidden email]>
> Subject: Re: [Beanshell-users] Using Beanshell as an expression  evaluator
> To: "Stewart Cambridge" <[hidden email]>
> Cc: [hidden email]
> Date: Monday, June 23, 2008, 6:34 AM
> Thanks Stewart,
>
> I was aware of those, but the problem is how do you find
> out which variables are undefined and need to be set? The
> set of variables available is not canonical.
>
> I have got something working by subclassing NameSpace with
> a custom getVariableImpl implementation that builds a list
> of undefined variables. When an expression is created, I do
> a test evaluation and record the list of undefined
> variables. When the expression is to be evaluated for real,
> I use bind the known undefined variables to the current
> property values.
> This seems to be working fine for the limited use of
> evaluating a single expression. My next task is to
> implement a more general script object. What I really need
> to work out is how to dynamically reference property values
> in my main application from within beanscript. Slowly
> getting there.
> Regards,
> Brent.
>
> *********** REPLY SEPARATOR ***********
>
> On 23/06/2008 at 11:21 AM Stewart Cambridge wrote:
>
> Check the bsh.Interpreter class. The methods set(), unset()
> and eval() may help you.
>
>
>
> 2008/6/22 Brent Easton <[hidden email]>:
>
>
> I am trying to work out the best way to integrate Beanshell
> into my application. I want to use Beanshell to add the
> ability to parse and evaluate arbitrarily complex
> expressions typed in by users.
>
> For example
>
>  20 * xpos + ypos/2
>
> The expressions are entered and validated at one point of
> time, but are evaluated much later, in a different phase of
> operation of the program when xpos and ypos will have
> determinable values.
>
> I have successfully used the Parser to parse and validate
> the structure of expression.
>
> My problem is determining and binding values to the
> variables in the expression at runtime. The variables
> 'xpos' and 'ypos' (plus a host of other
> 'variables') are not predetermined at the time the
> expression is created.
>
> At evaluation time, I need to determine what variables are
> used in the expression are undefined, then bind them to
> values from my application, evaluate the expression and
> then return the result to my application.
>
> Any pointers would be appreciated.
>
> Regards,
> Brent.
>
>
>
>
>
>
>
> -------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
> ____________________________________________________________
> Brent Easton
> Analyst/Programmer
> University of Western Sydney
> Email:
> [hidden email]-------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users


     

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

Re: Using Beanshell as an expression evaluator

Brent Easton-2
In reply to this post by Stewart Cambridge
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 <[hidden email]>:
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:
[hidden email]

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

Re: Using Beanshell as an expression evaluator

Brent Easton
In reply to this post by Alexey Zinger
Hi Alexey,

Alexey Zinger wrote
Is there a reason you couldn't use your extended NameSpace object at runtime to check for any unretrieved variables?  I'm not familiar with your project's specifics, but I can't imagine any reason you couldn't do this.  Is there something your application knows at expression "compile" time it doesn't know at "run" time?
Yes, that is exactly what I described earlier with the custom getVariableImpl implementation to keep track of undefined variables. I have a basic expression evaluator working quite well now.

I had used JEP before which explicitly handles undefined variables for you and provides you with a list of them, so I had assumed something like this would be a standard feature of bsh.

Thanks for your comments,
Brent.
Loading...