• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Java scripting language/library/example code.

 
Scott Wilkinson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

First post, love your work here.

I need to be pointed in the right direction, some links to some good articles would be great!

My idea is thus!:-

Problem: Our clients quite often require rules based on dynamic values, these values can change quite often and these rules be quite complex.

Essentially I want to be able to perform certain database tasks based on these rules.

What I imagine is a web interface which allows end users to build a rule based on functions & operations given a specific set of information which I would supply to a scripting language, either in specifc javaobjects, or an available sets of information retrieved from the DB via simple user functions eg (LOOKUP(<tableName>,LIST(CRITERIA(<field>,<op>,<value>),CRITERIA(<field>,<op>,<value>))), ... or similar.

I'm thinking the interface should be remiscent of the simple script used in MS-Excel, and probably built using a similar interface.


So I guess I'm looking for a scripting language that will handle flow control (IF, AND, OR ,NOT ), simple math (3 + 3), temp variables, (@x = function() + 3*@y), and the ability to create custom tokens/functions that relate to Java based functions or variables (I want to relate scripting functions back to Java code not write them into the script. Why? I want to sniff out errors or injection & I want to use existing java based code, esp. for DB operations).

I think I'd prefer loose type-ing, but I think some user error control would be nice too!

Yeah that's it in a nut shell. I'm sure i'm not the first person to attempt doing this, so maybe one of you has done this before and can point me in the right direction to get started.


Thanks, Scott.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "custom tokens/functions", but the other features would be handled by JavaScript. If you're using Java 6, then the javax.scripting package contains an API for that; see http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/ and http://download.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html

For Java 5 and earlier you'd have to resort to BSF which works similarly.
 
Scott Wilkinson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lester,

I was looking at some of the other javax.scripting like Ruby etc. which didn't make a lot of sense to me.

Also I was thinking JavaScript would be too unsecure. However it does appear to support some sort of "scoping".

The rhino javascript engine seems to tick all of my boxes, cheers!

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I'd probably aim for Groovy, but YMMV.

The issue is that if you give the users a complete language to work in, instead of a restricted DSL, you are opening yourself up for a world of hurt.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic