Thank you so very much. Yes, changing the
parse to handle this would be very helpful.
From: rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Edson Tirelli
Sent: Wednesday, October 31, 2007
12:32 PM
To: Rules Users List
Subject: Re: [rules-users] RE:
JavaConsequenceBuilder.buildNullPointerException
Michael,
The problem is you missed the "" on:
$result.addPassedRule(leaders in same
location);
I will fix the parser code to not throw NPE for this
anymore.
Thanks,
Edson
2007/10/31,
Sure. Thanks
package validActions;
import myPackage.domain.leader.LeaderImpl;
import myPackage.domain.location.LocationImpl;
import myPackage.domain.leader.LeaderTypeImpl;
import myPackage.rivoli.service.rules.RuleResult;
rule "leaders in same location"
salience 10
when
$result : RuleResult(rulesPassed not
contains "leaders in same location")
$loc : LocationImpl()
$leaderName : String()
$leader1 : LeaderImpl(name == $leaderName,
location == $loc)
$leader2 : LeaderImpl(name != $leaderName,
this != $leader1, location == $loc)
then
$result.addPassedRule(leaders in same
location);
update($result);
end
rule "leaders king and heir"
salience 10
when
$result : RuleResult(rulesPassed not
contains "leaders king and heir")
$leaderName : String()
$king : LeaderTypeImpl(name ==
"King")
$heir : LeaderTypeImpl(name ==
"Heir")
$leader1 : LeaderImpl(name == $leaderName,
leaderType == $king)
$leader2 : LeaderImpl(name != $leaderName,
this != $leader1, leaderType == $heir)
then
$result.addPassedRule("leaders king
and heir");
update($result);
end
rule "leader in capital"
salience 10
when
$result : RuleResult(rulesPassed not contains
"leader in capital")
$loc : LocationImpl(capital == true)
$leader1 : LeaderImpl(location == $loc)
then
$result.addPassedRule("leader in
capital");
update($result);
end
rule "leader in homeland"
salience 10
when
$result : RuleResult(rulesPassed not
contains "leader in homeland")
$loc : LocationImpl(homeland == true)
$leader1 : LeaderImpl(location == $loc)
then
$result.addPassedRule("leader in
homeland");
update($result);
end
rule "abdication allowed"
when
$result : RuleResult (rulesPassed not
contains "abdication allowed"
&& rulesPassed contains
"leaders in same location"
&& rulesPassed contains "leaders king and heir")
then
$result.addPassedRule("abdication
allowed");
update($result);
end
From: rules-users-bounces@lists.jboss.org
[mailto:
rules-users-bounces@lists.jboss.org] On
Behalf Of Edson Tirelli
Sent: Tuesday, October 30, 2007
2:31 PM
To: Rules Users List
Subject: Re: [rules-users] RE:
JavaConsequenceBuilder.buildNullPointerException
Michael,
Can you show us your rule(s) please? it is raising the NPE when
trying to get the list of variables you use in the consequence... as soon as we
determine what the real problem is, I can fix the error message...
[]s
Edson
2007/10/30,
I
have the following code: (note String[] ruleFiles contains only one string)
public
class Engine {
private static RuleBase ruleBase;
public void start(String[] ruleFiles) throws Exception {
PackageBuilderConfiguration cfg = new PackageBuilderConfiguration();
JavaDialectConfiguration javaConf = (JavaDialectConfiguration)
cfg.getDialectConfiguration("java");
javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);
PackageBuilder builder = new PackageBuilder(cfg);
for (String file : ruleFiles) {
builder.addPackageFromDrl(new
InputStreamReader(ClassLoader.getSystemResourceAsStream(file)));
}
Package pkg = builder.getPackage();
PackageBuilderErrors errors = builder.getErrors();
if (errors.getErrors().length != 0) {
// do something
}
RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setAssertBehaviour(RuleBaseConfiguration.AssertBehaviour.EQUALITY);
ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
ruleBase.newStatefulSession(false);
}
}
At
the builder.addPackageFromDrl(new
InputStreamReader(ClassLoader.getSystemResourceAsStream(file))); line I'm
getting the following exception:
java.lang.NullPointerException
at
org.drools.rule.builder.dialect.java.JavaConsequenceBuilder.build(JavaConsequenceBuilder.java:54)
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:67)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:446)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:304)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)
at myPackage.rivoli.service.rules.Engine.start(Engine.java:33)
at
myPackage.rivoli.rules.LeaderKingAndHeirTest.setUp(LeaderKingAndHeirTest.java:26)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
I
am using Drools 4.0.3
I
have the following jars in my class path:
antlr-runtime-3.0.jar
core-3.2.3.v_686_R32x.jar
drools-compiler-4.0.3.jar
drools-core-4.0.3.jar
mvel14-1.2.10.jar
Any
ideas would be helpful. Thanks.
"In
theory there is no difference between theory and practice. But, in practice,
there is." - Jan L.A. van de Snepscheut
_______________________________________________
rules-users mailing list
rules-users@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
_______________________________________________
rules-users mailing list
rules-users@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