[rules-users] About for and inheritance

Evert Penninckx evert.penninckx at gmail.com
Fri Jan 14 06:02:58 EST 2011


Hi

I stumbled upon this problem last week. I see this is a very old post, and I
was wondering if a "solution" has been implemented?

It seems logical to me, that "from" only matches if an element in the list
matches the required subclass. This means the classcast exception is catched
and causes the rule not to match.
rule "likes french cheese"
    when
        $person : Person ()
        FrenchCheese( smell == "good" ) from $person.getLikes()
    then 
        System.out.println("likes french cheese");
end
This rule should only match FrenchCheese, even if other subclasses of Cheese
are present in the set of Cheeses (getLikes()). 


They way I avoid it now is using an Enum containing each Cheese class (since
I can't get it working with reflection).
rule "likes french cheese"
    when
        $person : Person ()
        $cheese : Cheese( cheeseType == CheeseTypes.FrenchCheese ) from
$person.getLikes()
        FrenchCheese( smell == "good" ) from $cheese
    then 
        System.out.println("likes french cheese");
end
A bit awkward in my opinion. It would be nice if drools provided for the
matching itself. 


So again, has this "problem" evolved since 2007?



Greetz

Evert



-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/About-for-and-inheritance-tp54110p2254750.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list