{ by david linsin }

February 04, 2007

JBoss Rules with custom DSL

I updated my JBoss Rules example, which I started over a year ago, to use a custom Domain Specific Language (DSL) to create the implemented business rules. I'm only gonna blog about the update here, so you might wanna check out my previous blog about this example.

I started off creating a simple text file (dsl file) which contains the two business rules of my example. Then I moved all the logic of the rules file into the dsl file and associated it with a text. For instance the logic "customer:Customer(discount == true) and bill:Bill()" is being associated with a textual description "There is a customer which gets discount". Those descriptions can then be used as a building block in your rules file. The next step was to use the textual descriptions of the dsl file to build the business rules in a new rules file. Finally I had to do some minor changes in the code to get the DSL working. The outcome of all this is a clean and easy to read rules file. Furthermore you have something like a language that you can use to define your business rules.

I think this approach to define rules is very straightforward and I like it a lot! It so much easier to define a business rule with textual description. To establish a simple and easily readable DSL though, is quite difficult. The tool support in that area, at least with JBoss Rules, is very limited. That makes debugging quite a hassle. I think there should be auto-completion and syntax-highlighting in a dsl file, that would make things easier.

I think of all three example I did, this one is the most simplest and easiest to understand.

4 comments:

Unknown said...

I suggest you also look into Ruby for a candidate where you may be able to write rules in a friendly DSL syntax and even implement the JBoss rules engine in the same anguage (Ruby) in which the rules can be written as a DSL. There is a lot on this presently over the internet.

- Uri

David Linsin said...

hey uri,

I have never implemented anything in Ruby, so I cannot comment on the syntax. But I checked out a couple of tutorials and you are right, it looks quite straightforward.

When you say "implementing JBoss Rules in Ruby", I guess you mean integrating it with Ruby, right?

Maybe you could post a couple of good links to "Ruby with JBoss Rules" (or Rules Systems in general) here.

Anonymous said...

Hi,

did you have a chance to try on some XSL tranformation to port the old XML format to new DSL format.
If, I would be grateful if i could ge t some pointers

David Linsin said...

Hey Karthik,

I think transforming the Drools 2 XML to a custom DSL or the Drools 3 native language wouldn't work. At least I don't know how it could. You can transform your Drools 2 XML to Drools 3 XML though. Unfortunately I haven't done that myself, so I can't give you anymore insight on that.


com_channels

  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)

recent_postings

loading...