jQuery in Action, 3rd edition
The moose likes Other Languages and the fly likes Help with Java scripting language/library/example code. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Help with Java scripting language/library/example code." Watch "Help with Java scripting language/library/example code." New topic

Help with Java scripting language/library/example code.

Scott Wilkinson

Joined: Sep 04, 2010
Posts: 2
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

Joined: Oct 14, 2008
Posts: 1337
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

Joined: Sep 04, 2010
Posts: 2
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

Joined: Sep 29, 2008
Posts: 12617

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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Help with Java scripting language/library/example code.
jQuery in Action, 3rd edition