[rules-users] Binding Not

Joshua Undesser jundesse at cdmtech.com
Fri Dec 21 17:44:33 EST 2007


I have a question on the return value of a not statement........

I have two fairly large rules in respect to the LHS when declarations.  
They are identical except for the fact that in one of them, I am checking to
see if one more object exits, while in the other I am checking to see if it
doesn't exist.   It seems silly to try have duplicate rules expressively
typed when this is the only difference.   So what i tried to do was bind the
value of the not statement as shown below....

rule "Rule Name"
  no-loop = true
  when
       .........

      $msg : (or Message (description == "OK")
                     not Message (description == "OK"))
       .........
  then
     if ($msg == null) {
          createMessage("OK");  // 
     }

     .... rest of RHS.....
end

I figured if the Message object didn't exist, null would be returned and
assigned to the $msg variable.   But it was not.    For now I have it
separated into two rules, but logically I would like to combine them, as
every other part of the LHS and RHS match.

I also tried a few different variants as shown below thinking it would work,
but didn't.  

rule "Rule Name"
  no-loop = true
  when
       .........

      (or $msg : Message (description == "OK")
           not Message (description == "OK"))
       .........
  then
     if ($msg == null) {
          createMessage("OK");  // 
     }

     .... rest of RHS.....
end


I even tried the above with the entire "then" side encapsulated in a
try/catch block to catch the null pointer that gets thrown, but no luck.

Anyone have any suggestions?   Just seems like there should be a way to do
this.





-- 
View this message in context: http://www.nabble.com/Binding-Not-tp14463587p14463587.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list