Thanks for the detailed explanation Anil! I agree that Drools might be an 
overkill for this requirement. I am looking at Groovy and shall take a look at 
Rhino as well.

Thanks,
Yogesh




________________________________
From: Anil Gangolli <a...@busybuddha.org>
To: users@appfuse.dev.java.net
Sent: Friday, February 13, 2009 11:03:57 AM
Subject: Re: [appfuse-user] Mathematical formula implementation in Java/JEE

 
We recently used Javascript (using Rhino) for something that sounds
similar.  In Java 1.6, there is a generic scripting API with Rhino
shipped with the SDK.  We were unable to use Java 1.6 yet at build time
for compatibility reasons  but we are essentially using the same
combination.  Groovy would probably be a good choice as well.

Drools would be more appropriate if you need to worry about complex
rule chaining.   We handled simple acyclic recomputation chaining
ourselves by explicitly tracking dependencies and changes in result
values.  (e.g. x depends on y and z, y depends on a and b.  The value
of b changes, y requires recomputation, x requires recomputation).

--a.
   

tonylu880042 wrote: 
Hi,
 I would like suggest you to use the GroovyShell from Groovy project.
 I use this in my web action for providing some rule customization just like
your case.
 The advantage of using GroovyShell() is you can put your Java data model
into GroovyShell and execute your script(Mathematical formula which is coded
in Java form).
Or, you can using the dynamic bean in Spring for further detail please check
out my blog in the following link.
http://tony880042.blogspot.com/2008/08/how-to-add-scripting-support-in-your.html
 
http://tony880042.blogspot.com/2008/08/how-to-add-scripting-support-in-your.html
 



Yogesh Bhardwaj wrote:

Hello all,

This question is not related to AppFuse so please pardon me, but since
there are so many developers from open source community here, just thought
of getting some opinions. We have a business requirement in which the end
users would create mathematical "formulae" through a UI. So in a single
transaction, a user could create a formula, apply it on the transactional
data, and save the formula for future use. The operands in a formula would
be attributes of certain objects, and the operators could potentially go
beyond just simple algebraic operators. An example could look like this:

if (object.country == "USA")
then output = (object.normalRate * (@someConstant + #someUserInput)) /
object.quantity
else output = (object.exciseRate * @someConstant) / object.quantity

The "decision-making" behavior of the formula inclines me towards using
some rules engine like JBoss Rules/Drools. Does anyone here know if JBoss
Rules or any other rules engine would fit for a requirement like this,
where rules could be created dynamically through a UI and then saved (file
or database) or users could select a rule among several available ones?

I would really appreciate any feedback.

Thanks,
Yogesh


      

Reply via email to