Well, I'm not sure why are you constraining your rule using the class
Object. What is happening is that the engine always inserts a fact into the
engine known as InitialFact, that as all objects in java, is a subclass of
Object, and that is why the rule fires.
If instead of Object, you use a different class, like Integer for
instance, to constrain your rule, you will get the behavior you are looking
for.
[]s
Edson
2007/8/22, Dean Jones <dean.m.jones(a)gmail.com>:
Hi,
I have the following simple rulebase:
package org.drools.examples
rule "Hello World"
when
o : Object( )
then
System.out.println("Hello world (o=" + o + ")");
end
rule "Goodbye World"
when
not Object( )
then
System.out.println("Goodbye cruel world");
end
and the following code:
public class TestReadRuleFile {
public static void main(String[] args) throws Exception {
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(
new InputStreamReader(
TestReadRuleFile.class.getResourceAsStream("test.drl")));
Package pkg = builder.getPackage();
RuleBase rulebase = RuleBaseFactory.newRuleBase();
rulebase.addPackage(pkg);
StatefulSession session = rulebase.newStatefulSession();
session.fireAllRules();
}
}
which produces the following output:
Hello world (o=org.drools.reteoo.InitialFactImpl@4dde85f0)
I expected the "Goodbye World" rule to fire, as there should not be
any Objects in the working memory. If I change my code to insert an
object into the working memory as follows:
session.insert(new Object());
I now get the following output:
Hello world (o=org.drools.reteoo.InitialFactImpl@4dde85f0)
Hello world (o=java.lang.Object@17ba38f)
In this case, I expected the "Hello World" rule to fire only once. Any
thoughts on what I'm doing wrong here?
Thanks,
Dean.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
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