[rules-users] Type-Casting in when-part of rule

Fermion henss at physik.uni-wuppertal.de
Fri Apr 11 12:48:15 EDT 2008


Hi!

I'm using pattern matching on Java objects in the when part of my rules. One
example might be:

CommonDataObject($name : name matches ".*STATUS_D.._B..\.fsm.*", type ==
Type.STRING, $stringValue : stringValue != "OK" && stringValue != "UNKNOWN")

So you can see, that my Java object "CommonDataObject" has at least 3
members: name, type and stringValue.

This works all fine.

Unfortunately my object could also hold a Float or an Integer value.

The current implementation uses additional "floatValue" and "integerValue"
members in order to access them from the rules.

I would prefer very much to remove my "stringValue", "floatValue" and
"integerValue" members at all. As I already have a "type" member (which can
be Type.STRING, Type.FLOAT or Type.INTEGER), I would like to just store one
member called "value" which would then just be an Object.
As the rules have access to the type-member, they should then be able to
cast the value-member to the correct type:

CommonDataObject($name : name matches ".*STATUS_D.._B..\.fsm.*", type ==
Type.STRING, $value : (String)value != "OK" && (String)value != "UNKNOWN")


Unfortunately it seems, that a direct type-cast is not possible in the when
part of a rule.

Maybe someone knows a way to realize this functionality...

Thanks in advance!
-- 
View this message in context: http://www.nabble.com/Type-Casting-in-when-part-of-rule-tp16628142p16628142.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list