2

We have a Java application and we want to provide the ability for end users to write 'business rules'. These rules will be evaluated when entities are created, updated or deleted.

I am looking for a language to write these business rules. Considerations are:

  1. Configurable security - end user should not be able to call things like new File("some secret file") or call an internal API
  2. Easy to read and understand
  3. Easy to manipulate lists and maps
  4. Ability to provide a syntax checker

Any suggestions?

2
  • @Dev: -rw-r--r-- 1 root root 2168 2011-04-13 04:43 /etc/passwd is readable whole world, and has to be, to allow login. Commented Mar 18, 2012 at 5:22
  • Watch out for the inner-platform effect. Commented Mar 18, 2012 at 9:16

4 Answers 4

2

Use either a business rules engine (like Drools) or build your own vocabulary or DSL using Groovy or xText.

Sign up to request clarification or add additional context in comments.

Comments

1

Python can be made quite English readable and is available to Java as Jython package. List syntaxes in Python are very flexible and it has much syntatic suger for use cases like this. Jython is well established project and already used in business application scripting.

http://www.jython.org/

Sandboxing can be provided on Java level using JVM internal security manager mechanisms. This is what Java applets use.

Python has a syntax checker called pylint.

Comments

0

You could also try ANTLR. It's a little more complicated, but there's a lot of flexibility.

Comments

0

You can also base your DSL on XML, JSON, YAML or even LISP's s-exp.

Some examples:

Using YAML:

- action:  reject
  pattern: http://www\.example\.com/.+
- action:  allow
  pattern: http://www\.example\.net/.+

Another YAML example:

- xpath-select: /a[1]/b/c[@p1=v1]/d
  as: x
- xpath-select: /e/f/g
  as: y
- yield: "${x}+${y}"

Using XML:

<select value="*" from="mytable">
    <criteria property="name" op="eq" value="foo" />
    <criteria property="age" op="ge" value="18" />
</select>

XML, JSON, YAML are data formats. You have to interprete these data by yourself, but it prevents arbitrary objects to be created. Using a well-known data format also relieves you from having to write your own parsers. There are existing parsers available in Java.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.