<div dir="ltr"><br>&nbsp;&nbsp; You are using variables (like $nissan) before binding them. Remember you can only use a variable &quot;after&quot; binding it.<br><br>&nbsp;&nbsp; []s<br>&nbsp;&nbsp; Edson<br><br><div class="gmail_quote">2008/8/20 Marcin Krol <span dir="ltr">&lt;<a href="mailto:mrkafk@gmail.com">mrkafk@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello everyone,<br>
<br>
I managed to produce my first example of Drools rules. However, I am having problems with some field restrictions:<br>
<br>
Racing order:Unable to create restriction &#39;[QualifiedIndentifierRestr: != $nissan.pos ]&#39; for field &#39;pos&#39; in the rule &#39;Racing order&#39;<br>
<br>
The problem is only SOME field restrictions produce this error. Other field restrictions don&#39;t!<br>
<br>
If anybody has a hint or knows why this is not working, please let me know, I would greatly appreciate it.<br>
<br>
<br>
<br>
The rules are:<br>
<br>
<br>
#created on: 2008-08-20<br>
package com.sample<br>
<br>
#list any import classes here.<br>
<br>
#declare any global variables here<br>
<br>
dialect &quot;mvel&quot;<br>
<br>
import com.sample.Car;<br>
<br>
rule &quot;Racing order&quot;<br>
 &nbsp; &nbsp;when<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;// Porsche was not red<br>
 &nbsp; &nbsp; &nbsp; &nbsp;$porsche : Car( manufacturer == &quot;Porsche&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos != $nissan.pos,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos != $subaru.pos,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;color != &quot;red&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//color != &quot;blue&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//color != $nissan.color,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//color != $subaru.color<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// First car was Nissan<br>
 &nbsp; &nbsp; &nbsp; &nbsp;$nissan : Car( manufacturer == &quot;Nissan&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; pos == 1,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; color != $subaru.color,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; color != $porsche.color )<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;// Subaru was blue<br>
 &nbsp; &nbsp; &nbsp; &nbsp;$subaru : Car( manufacturer == &quot;Subaru&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//pos == 2,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos != $nissan.pos,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos != $porsche.pos,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;color == &quot;blue&quot; )<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 2nd car was silver<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Car( pos == 2,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;color == &quot;silver&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this in ( $nissan, $subaru, $porsche ) )<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;then<br>
 &nbsp; &nbsp; &nbsp; &nbsp;System.out.println( &quot;Nissan &quot; + $nissan.getPos() + &quot; &quot; + $nissan.getColor() );<br>
 &nbsp; &nbsp; &nbsp; &nbsp;System.out.println( &quot;Subaru &quot; + $subaru.getPos() + &quot; &quot; + $subaru.getColor() );<br>
 &nbsp; &nbsp; &nbsp; &nbsp;System.out.println( &quot;Porsche &quot; + $porsche.getPos() + &quot; &quot; + $porsche.getColor() );<br>
<br>
end<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
<br>
<br>
<br>
The Car.java file:<br>
<br>
<br>
package com.sample;<br>
<br>
 &nbsp; &nbsp;public class Car {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;private String manufacturer;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;private String color;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;private int pos;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public Car() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public Car(String manufacturer, String color, int pos) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.color = color;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.pos = pos;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.manufacturer = manufacturer;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public String getManufacturer() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return this.manufacturer;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public float getPos() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return this.pos;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public String getColor() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return this.color;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp;}<br>
<br>
<br>
<br>
<br>
The CarExample.java file, which is the main app:<br>
<br>
<br>
<br>
package com.sample;<br>
<br>
import java.io.InputStreamReader;<br>
<br>
import org.drools.RuleBase;<br>
import org.drools.RuleBaseFactory;<br>
import org.drools.StatefulSession;<br>
import org.drools.compiler.PackageBuilder;<br>
import com.sample.Car;<br>
<br>
public class CarExample {<br>
<br>
 &nbsp; &nbsp;public static void main(String[] args) throws Exception {<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;final PackageBuilder builder = new PackageBuilder();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;builder.addPackageFromDrl( new InputStreamReader( CarExample.class.getResourceAsStream( &quot;CarExample.drl&quot; ) ) );<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;final RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;ruleBase.addPackage( builder.getPackage() );<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;final StatefulSession session = ruleBase.newStatefulSession();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;String[] names = new String[] { &quot;Nissan&quot;, &quot;Subaru&quot;, &quot;Porsche&quot;};<br>
 &nbsp; &nbsp; &nbsp; &nbsp;String[] colors = new String[] { &quot;red&quot;, &quot;blue&quot;, &quot;silver&quot;};<br>
 &nbsp; &nbsp; &nbsp; &nbsp;int[] positions = new int[] { 1, 2, 3 };<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;for ( int n = 0; n &lt; names.length; n++ ) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for ( int c = 0; c &lt; colors.length; c++ ) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for ( int p = 0; p &lt; positions.length; p++ ) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;session.insert( new Car( names[n], colors[c], positions[p]) );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;session.fireAllRules();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;session.dispose();<br>
 &nbsp; &nbsp;}<br>
<br>
<br>
<br>
}<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>
</div>