[rules-users] Maps in Drools

André Thieme address.good.until.2009.dec.14 at justmail.de
Fri Aug 21 15:08:41 EDT 2009


Edson Tirelli schrieb:
> 
>    Andre,
> 
>    The misunderstanding here is that the LHS, except for code blocks 
> like "eval", "return value expressions" and "accumulate code blocks", 
> are all "Drools Language". When you use the "dialect" attribute in a 
> rule or package you are telling the compiler what dialect (MVEL or Java) 
> you will use inside these code blocks mentioned previously + the 
> language for the RHS.

Good that you clear that up, thanks.


>     In other words:
> 
> Map( this["type"] == "Point", $x : this["x"], size == 5 )

I thought this is only possible when one declares the dialect MVEL.
Now I understand that what you just wrote also results in a valid rule,
even when MVEL is not set.

In your code above you:
1. check if this.get("type").equals("Point")
2. you set $x to the value of this.get("x")
3. check if this.size == 5
where I interpret 3. as calling the size() method of java.util.Map.
Was that right so far?


>     Everything you see in the previous expression is "Drools language", 
> does not matter if you set the dialect to java or mvel in the rule. It 
> happens that Drools uses the same map syntax as MVEL (and a lot of other 
> scripting languages). Also, we know, that drools implementation will 
> resolve the first 2 above expressions in MVEL behind the scenes, and the 
> 3rd will be resolved nativelly, but that is not something users should 
> have to worry about, since they are writing it in "Drools Language".

Yes, I understand.
Only with the middle part I still have some problems.
As you used it,   $x : this["x"]   it works for me.
A minor issue I have with this, but we can ignore that for now, is, that
this will be interpreted.
The real problem for me is: it only works when between the brackets
there is a literal string.
I however can't do that, because my lib should support the general case,
where between the brackets there could be any type of object (which I
would pass in via a global var).


>     If they write an eval, THEN they need to differentiate between MVEL 
> and Java according to the chosen dialect.
> 
> rule xyz
>    dialect "mvel"
> when
>    eval( ...here you write MVEL code... )
> then
>    // here you write MVEL code
> end
> 
> rule xyz2
>    dialect "java"
> when
>    eval( ...here you write JAVA code... )
> then
>    // here you write JAVA code
> end

Very good, thanks again for clearing this up.


André
-- 



More information about the rules-users mailing list