The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Java and Beanshell question

Hello,
I need to provide ability to dynamically change the behaviour of charts using Beanshell. I have been looking at Beanshell site but couldn't get any examples.

Here is what I am trying to achieve.

In my dashboard application, I set the basic properities of the chart but need to do the following

"
BarRenderer3D r = (BarRenderer3D) plot.getRenderer();
r.setDrawBarOutline(true);

GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.BLUE,
0.0f, 300.0f, new Color(0,0,100,100));
GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, new Color(0,0,230,200),
0.0f, 300.0f, new Color(204,204,255,200));
r.setSeriesPaint(0,gp0);
r.setSeriesPaint(1,gp1);
"

I don't want to compile the above code in the application but leave it outside as a customizable source by the end-user. The only thing the application should pass is the "plot" variable and then rest of the renderer modifications should be done inside the Beanshell script.

I just started looking into Beanshell and got excited about the extensibility but don't know how to do it.

Thanks
Nilesh
Nilesh Jethwa Send private email
Sunday, June 10, 2007
 
 
Take a look at the Interpreter class and examples.

Here's a basic kind of example:
- create an Interpreter
- set variables in the context the could be accessed by the script.
- evaluate the script text
- get results back out and dereference them.

import bsh.Interpreter;
...

Interpreter interpreter = new Interpreter();

// Beanshell script references for context, session
interpreter.set("context", context);
interpreter.set("session", session);

// Evaluate the script
// Could also set common imports before eval'ing script

interpreter.eval("import mypackage.*; javax.sql.*;");

interpreter.eval(userInputScript);

// If the script is expected to create certain types
// of result objects, retrieve them and cast.
XXXType resultX = (XXXType)interpreter.get("someVar");
YYYType resultY = (YYYType)interpreter.get("otherVar");
Carlos Bonilla Send private email
Monday, June 11, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz