-
Language:
English
-
Language:
English
19.6. HelloWorld Example: Rule "Hello World"
rule "Hello World"
dialect "mvel"
when
m : Message( status == Message.HELLO, message : message )
then
System.out.println( message );
modify ( m ) { message = "Goodbye cruel world",
status = Message.GOODBYE };
end- The LHS (after
when) section of the rule states that it will be activated for eachMessageobject inserted into the Working Memory whose status isMessage.HELLO. - Two variable bindings are created: the variable
messageis bound to themessageattribute and the variablemis bound to the matchedMessageobject itself. - The RHS (after
then) or consequence part of the rule is written using the MVEL expression language, as declared by the rule's attributedialect. - After printing the content of the bound variable
messagetoSystem.out, the rule changes the values of themessageandstatusattributes of theMessageobject bound tom. - MVEL's
modifystatement allows you to apply a block of assignments in one statement, with the engine being automatically notified of the changes at the end of the block.