I changed the rule "calculate totalPrice per item" to MVEL and trying to calculate and set totalPrice with one liner:
((DataItemPrice)$v).setTotalPrice(((DataItemPrice)$v).getQty()*((DataItemPrice)$v).getUnitPrice());
but that fails with message: java.lang.IllegalArgumentException: object is not an instance of declaring class
On the other hand using temporary variable of type Double will work. Here is the complete rule which works up to the comment "// THIS IS DOESN'T WORK":
rule "calculate totalPrice per item"
salience -10
no-loop
when
$q:Message(id=="item", answered==true,
value instanceof DataItemPrice, $v:value
)
then
System.out.println("setting totalPrice on item: " + ((DataItemPrice)$v).getName());
System.out.println("qty*unitPrice=" + ((DataItemPrice)$v).getQty()*((DataItemPrice)$v).getUnitPrice());
Double d = ((DataItemPrice)$v).getQty()*((DataItemPrice)$v).getUnitPrice();
((DataItemPrice)$v).setTotalPrice(d);
System.out.println("setting via temporary variable worked");
// THIS IS DOESN'T WORK
((DataItemPrice)$v).setTotalPrice(((DataItemPrice)$v).getQty()*((DataItemPrice)$v).getUnitPrice());
System.out.println("setting directly works ???");
update($q);
end
Am I again wrongly hoping that MVEL will simplify data types casting ? Or should I fail a bug ?