Could you not change your rule?
rule "An item is in the office"
salience 0
when
$item : Item( )
$container : Container(location.name = "office", items
contains $item)
then
System.out.println("item in office");
end
[I think] this would only require an update to the Container.
If a object represented by a patten changes you always need to update the
working memory's knowledge of the object.
The above requires that Container exposes an Items collection.
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: 24 October 2007 00:58
To: Rules Users List
Subject: Re: [rules-users] Rules firing with an update of another object
Hi Fabrice,
That is how it is supposed to work... no "automatic" way of doing it in
another way.
[]s
Edson
2007/10/23, Fabrice Granzotto < granz(a)mit.edu>:
Hi everybody!
Here is my code and my rule. The problem is that the rule doesn?t detect
that
my item ?chocolate? contained in the container has moved to the
?office?.
I know that if I update the item instead the container it?s working, but I
was
wondering if there is a solution to detect this movement by this way? Do you
have a solution?
Thanks!
*******CODE *******
session = ruleBase.newStatefulSession();
Location kitchen=new Location("kitchen");
Location office=new Location("office");
Container container1=new Container("container1",kitchen);
session.insert(container1);
Item chocolate=new Item("chocolate", container1);
session.insert(chocolate);
session.fireAllRules();
//No rules fired => OK
container1.setLocation(office);
session.update (session.getFactHandle(container1), container1);
session.fireAllRules();
//Once again, no rules fired => Not OK... I want detect this movement
*******RULE *******
rule "An item is in the office"
salience 0
when
$itemA : Item($cont : container,
$cont.location.name=="office")
then
System.out.println("item in office");
end
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
<
https://lists.jboss.org/mailman/listinfo/rules-users>
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @
www.jboss.com