Liliana,

   I think you got trunk in the middle of a change. Let me explain:

JBoss Rules 3.0 does not support multiple patterns inside "exists". You can do exists only for a single pattern. I'm implementing support for that in JBoss Rules 3.1 (trunk), but it is not complete yet. This is why you are getting this strange error. As of now, nesting of patterns inside exists and not is in the following status:

* logic transformation is ready and tested
* parser is ready but not completelly tested
* reteoo builder is not done yet

When the above is done, "forall" conditional element will also be available. You can follow up progress looking at ticket:

http://jira.jboss.com/jira/browse/JBRULES-218

Also, just a minor comment about your rules, I don't know if you using eval() because you want to, but it is not needed. Just write:

    NumberWrapper( id == "n1", value < 100 );

   []s
   Edson

Liliana Pasquale wrote:

I have modified the rules in this manner:

function boolean test(double n, double m) {
    return (n < m);
    }

rule "Regola    3"
agenda-group    "b2";
salience 3;
no-loop true;
    when
        f2 : ForAllManager( id == "b2") &&
        n1 : NumberWrapper(id=="n1") &&
        eval(test(n1.getValue(),100.00))
    then
        System.out.println (n1.getValue());
        retract(n1);
        if(f2.getCursor().hasNextSelection()) f2.esegui();
        else assert(new BooleanWrapper(f2.getId(),true));
end

rule "Regola    3.x"
agenda-group    "b2";
salience 3;
no-loop true;
    when
        exists(f2: ForAllManager( id == "b2")) &&
        n1 : NumberWrapper(id== "n1") &&
        eval(!(test(n1.getValue(),100.00)))
    then
        System.out.println(n1.getValue());
        retract(n1);
        assert(new BooleanWrapper("b2",false));
        retract(f2);
end

And now I get the following errors:


java.lang.ClassCastException: org.drools.reteoo.InitialFactImpl
at it.polimi.forAllAnnidati.Rule_Regola_3_x_0ConsequenceInvoker.evaluate(Rule_Regola_3_x_0ConsequenceInvoker.java:18)
    at org.drools.common.DefaultAgenda.fireActivation(Unknown Source)
    at org.drools.common.DefaultAgenda.fireNextItem(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source) at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source) at it.polimi.forAllAnnidati.ForAllManager.esegui(ForAllManager.java:120) at it.polimi.forAllAnnidati.ForAllManager.esegui(ForAllManager.java :110)
    at it.polimi.forAllAnnidati.Manager.esegui(Manager.java:126)
    at it.polimi.forAllAnnidati.Gestore.inizializza(Gestore.java:61)
    at it.polimi.forAllAnnidati.Gestore.<init>(Gestore.java:8)
at it.polimi.forAllAnnidati.Dynamo_rules_test.main(Dynamo_rules_test.java:9) Exception in thread "main" org.drools.spi.ConsequenceException: java.lang.ClassCastException: org.drools.reteoo.InitialFactImpl
    at org.drools.common.DefaultAgenda.fireActivation(Unknown Source)
    at org.drools.common.DefaultAgenda.fireNextItem(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source) at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source) at it.polimi.forAllAnnidati.ForAllManager.esegui(ForAllManager.java:120) at it.polimi.forAllAnnidati.ForAllManager.esegui(ForAllManager.java :110)
    at it.polimi.forAllAnnidati.Manager.esegui(Manager.java:126)
    at it.polimi.forAllAnnidati.Gestore.inizializza(Gestore.java:61)
    at it.polimi.forAllAnnidati.Gestore.<init>(Gestore.java:8)
at it.polimi.forAllAnnidati.Dynamo_rules_test.main(Dynamo_rules_test.java:9)
Caused by: java.lang.ClassCastException: org.drools.reteoo.InitialFactImpl
at it.polimi.forAllAnnidati.Rule_Regola_3_x_0ConsequenceInvoker.evaluate (Rule_Regola_3_x_0ConsequenceInvoker.java:18)
    ... 10 more

Any ideas?

Liliana







------------------------------------------------------------------------

package it.polimi.forAllAnnidati;


public class Dynamo_rules_test {
        //private ForAllManager f1, f2, f3;
        
        
        public static void main(String[] args){
                Gestore g = new Gestore();
        }
        /*      Manager m;
                
                ArrayList<Variable> var1, var2;
                Alias a1, a2, a3;
                
                //creo i forall
                m = new Manager();
                f3 = new ForAllManager("b3",null);
                f2 = new ForAllManager("b2",null);
                f1 = new ForAllManager("b1",null);
        
                //setto la working memory
                f1.setWm(m.getWm());
                f2.setWm(m.getWm());
                f3.setWm(m.getWm());
                
                //setto le variabili
                var1 = new ArrayList<Variable>();
                var2 = new ArrayList<Variable>();
                Variable n1 = new Variable("$l/easting","Number","n1");
                Variable n2 = new Variable("$l/northing", "Number","n2");
                var1.add(n1);
                var2.add(n2);
                f3.setVariables(var2);
                f2.setVariables(var1);
                
                //setto gli Alias
                a1 = new Alias("r","$this/getRouteIn/Restaurant");
                a2 = new Alias("l","$r/location");
                a3 = new Alias("l", "$r/location");
                f1.setAlias(a1);
                f2.setAlias(a2);
                f3.setAlias(a3);
                
                //setto i forAll interni ed esterni
                f3.setExtForAll(f1);
                f2.setExtForAll(f1);
                ArrayList<ForAllManager> forAll = new 
ArrayList<ForAllManager>();
                forAll.add(f2);
                forAll.add(f3);
                f1.setForAllArray(forAll);
                
                //setto gli array e le variabili del manager esterno
                ArrayList<ForAllManager> forAll1 = new 
ArrayList<ForAllManager>();
                forAll1.add(f1);
                m.setVariables(null);
                m.setForAllArray(forAll1);
                f1.setExtForAll(m);
                m.esegui();
                
        
        } */
        
}
------------------------------------------------------------------------

package it.polimi.forAllAnnidati;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;

public class Manager {
        
         WorkingMemory wm;
         private ArrayList<ForAllManager> forAllArray;
         private ArrayList<Variable> variables;
         private ForAllThread thread;
public ForAllThread getThread() {
                return thread;
        }

        public void setThread(ForAllThread thread) {
                this.thread = thread;
        }

        public ArrayList<ForAllManager> getForAllArray() {
                return forAllArray;
        }

        public void setForAllArray(ArrayList<ForAllManager> forAllArray) {
                if(forAllArray==null) forAllArray = new 
ArrayList<ForAllManager>();
                else this.forAllArray = forAllArray;
        }

        public ArrayList<Variable> getVariables() {
                return variables;
        }

        public void setVariables(ArrayList<Variable> variables) {
                if (variables==null) variables = new ArrayList<Variable>();
                else this.variables = variables;
        }

        public Manager() {
                super();
                // TODO Auto-generated constructor stub
                
                PackageBuilder pb = new PackageBuilder();
                
                try {
                        
                        InputStream ins = new 
FileInputStream("D:\\Documenti\\Milano\\workspace\\EsempiForAllAnnidati\\src\\rules\\forAllAnnidati.drl");
                        
                        InputStreamReader isr = new InputStreamReader(ins);
                        
                        pb.addPackageFromDrl(isr);
                        
                        
                        
                } catch (DroolsParserException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                Package pkg = pb.getPackage();
                
                
                RuleBase rb = RuleBaseFactory.newRuleBase();
                
                try {
                        rb.addPackage(pkg);
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                
                wm = rb.newWorkingMemory();
                //thread = new ForAllThread(this);
                
                
        }

        public WorkingMemory getWm() {
                return wm;
        }

        public void setWm(WorkingMemory wm) {
                this.wm = wm;
        }
        public void esegui(){
                
                        //Inizializzo tutte le variabili presenti nell'array
                        if(variables!= null){
                        Iterator<Variable> itVariable = variables.iterator();
                        while(itVariable.hasNext()){
                                XmlCursor varCursor;
                                Variable var = itVariable.next();
                                XmlObject xml = 
this.parseXml("D:\\Documenti\\Milano\\workspace\\XMLBeans\\monitorData.xml");
                                varCursor = xml.newCursor();
                                varCursor.selectPath(var.getXpath());
                                varCursor.toNextSelection();
                                if(var.getType().equals("Number")) 
wm.assertObject(new NumberWrapper(Double.parseDouble(varCursor.getTextValue()), 
var.getId().toString()));
                                if(var.getType().equals("String")) 
wm.assertObject(new StringWrapper( var.getId().toString(), varCursor.getTextValue()));    
 
                        }}
                        //Inizializzo tutti i forAll presenti nell'array
                        Iterator<ForAllManager> itForAll = 
forAllArray.iterator();
                        while (itForAll.hasNext()){
                                ForAllManager forall = itForAll.next();
                                forall.setAliases(null);
                                forall.setCursor();
                                wm.assertObject(forall);
                                forall.esegui();
                                
                        }
                        System.out.println("ora asserisco le regole");
                        wm.setFocus("1");
                        wm.fireAllRules();
                        
                }
        
        public XmlObject parseXml(String xmlFilePath)
   {
       File xmlFile = new File(xmlFilePath);
       XmlObject xml = null;
       try
       {
           xml = XmlObject.Factory.parse(xmlFile);
       } catch (XmlException e)
       {
           e.printStackTrace();
       } catch (IOException e)
       {
           e.printStackTrace();
       }
       return xml;
   }

        
        }
                        
                

------------------------------------------------------------------------

package it.polimi.forAllAnnidati;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;

import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import it.polimi.forAllAnnidati.BooleanWrapper;

public class ForAllManager extends Manager {
        //id del forAll per essere asserito nella wm
        // lo stesso id del booleano che ne sostituisce il valore
        private String id;
        
        // il forAll di livello pi alto
        private Manager extForAll;
        
        //sono tutti i forAll di livello pi basso
        private ArrayList<ForAllManager> forAllArray;
        private HashMap<String,XmlCursor> aliases;
        private ArrayList<Variable> variables;
        private Alias alias;
        private XmlCursor cursor;
        private boolean value;
        private ForAllThread thread;
        
        
        
        

        public boolean isValue() {
                return value;
        }

        public void setValue(boolean value) {
                this.value = value;
        }

        public Manager getExtForAll() {
                return extForAll;
        }

        public void setExtForAll(Manager extForAll) {
                this.extForAll = extForAll;
        }

        

        public ForAllManager(String id, ArrayList<ForAllManager> forAllArray) {
                super();
                this.id = id;
                this.forAllArray = forAllArray;
                thread = new ForAllThread(this);
        }

        public ForAllManager(ArrayList<it.polimi.forAllAnnidati.ForAllManager> 
forAllArray) {
                super();
                this.forAllArray = forAllArray;
                thread = new ForAllThread(this);
        }

        public void esegui(){
                System.out.println("eseguo il forall "+ id);
                //if (cursor == null) setCursor();
                if(cursor.hasNextSelection()){
                        cursor.toNextSelection();
                        XmlCursor newCursor = cursor.newCursor();
                        if(aliases.get(alias.getVarName())!= null) 
aliases.remove(alias.getVarName());
                        aliases.put(alias.getVarName(), newCursor);     
                        //Inizializzo tutte le variabili presenti nell'array
                        
                        if(variables!=null){
                        Iterator<Variable> itVariable = variables.iterator();
                        while(itVariable.hasNext()){
                                XmlCursor varCursor;
                                Variable var = itVariable.next();
                                String s = var.getXpath();
                                StringTokenizer st = new StringTokenizer(s,"/");
                                String varId = st.nextToken().substring(1);
                                
                                if(aliases.get(varId)!= null){
                                        varCursor = 
aliases.get(varId).newCursor();
                                        
varCursor.selectPath("$this"+s.substring(s.indexOf("/")));
                                } else {
                                XmlObject xml = 
this.parseXml("D:\\Documenti\\Milano\\workspace\\XMLBeans\\monitorData.xml");
                                varCursor = xml.newCursor();
                                varCursor.selectPath(var.getXpath());
                                }
                                
                                varCursor.toNextSelection();
                                if(var.getType().equals("Number")) 
wm.assertObject(new NumberWrapper(Double.parseDouble(varCursor.getTextValue()), 
var.getId().toString()));
                                if(var.getType().equals("String")) 
wm.assertObject(new StringWrapper( var.getId().toString(), varCursor.getTextValue()));    
 
                        
                        }}
                        
                        if(forAllArray!= null ) {
                
                        //Inizializzo tutti i forAll presenti nell'array
                        Iterator<ForAllManager> itForAll = 
forAllArray.iterator();
                        while (itForAll.hasNext()){
                                ForAllManager forall = itForAll.next();
                                forall.setAliases(aliases);
                                forall.setCursor();
                                wm.assertObject(forall);
                                forall.esegui();
                        }
                        /*itForAll = forAllArray.iterator();
                         while (itForAll.hasNext()){
                                 ForAllManager forall = itForAll.next();
                                 wm.assertObject(new 
BooleanWrapper(forall.getId(),forall.isValue()));
                         }*/
                        
                }       
                wm.setFocus(id);
                wm.fireAllRules();
                }
        
                
                
                
        
        
                        
                //notifica();
                
        }
        
                        

        public ArrayList<ForAllManager> getForAllArray() {
                return forAllArray;
        }

        public void setForAllArray(ArrayList<ForAllManager> forAllArray) {
                this.forAllArray = forAllArray;
        }

        public Alias getAlias() {
                return alias;
        }

        public void setAlias(Alias alias) {
                this.alias = alias;
        }

        public String getId() {
                return id;
        }

        public void setId(String id) {
                this.id = id;
        }
        
        public void setCursor(){
                String s = alias.getXpath();
                StringTokenizer st = new StringTokenizer(s,"/");
                String varId = st.nextToken().substring(1);
                if((aliases != null) && aliases.get(varId)!=null){
                        cursor = aliases.get(varId).newCursor();
                        cursor.selectPath("$this"+ s.substring(s.indexOf("/")));
                }
                else {
                        XmlObject xml = 
this.parseXml("D:\\Documenti\\Milano\\workspace\\XMLBeans\\monitorData.xml");
                        cursor = xml.newCursor();
                        cursor.toFirstChild();
                        cursor.selectPath(alias.getXpath());
                }
                
                
                }
        public XmlObject parseXml(String xmlFilePath)
   {
       File xmlFile = new File(xmlFilePath);
       XmlObject xml = null;
       try
       {
           xml = XmlObject.Factory.parse(xmlFile);
       } catch (XmlException e)
       {
           e.printStackTrace();
       } catch (IOException e)
       {
           e.printStackTrace();
       }
       return xml;
   }


        public HashMap<String, XmlCursor> getAliases() {
                return aliases;
        }

        public void setAliases(HashMap<String, XmlCursor> a) {
                if(a == null){
                        aliases = new HashMap<String, XmlCursor>();
                
                        }
                else this.aliases = a;
                
        }

        public ArrayList<Variable> getVariables() {
                return variables;
        }

        public void setVariables(ArrayList<Variable> variables) {
                this.variables = variables;
        }
        public void notifica(){
                ForAllThread t = extForAll.getThread();
                
                synchronized(t){
                        
                        t.notify();
                }
        }

        public XmlCursor getCursor() {
                return cursor;
        }

        public ForAllThread getThread() {
                return thread;
        }

        public void setThread(ForAllThread thread) {
                this.thread = thread;
        }

        

}
------------------------------------------------------------------------

package it.polimi.forAllAnnidati;

public class BooleanWrapper {
        private boolean value;
        private String id;
        public BooleanWrapper(String id, boolean value) {
                super();
                this.value = value;
                this.id = id;
        }
        public String getId() {
                return id;
        }
        public void setId(String id) {
                this.id = id;
        }
        public boolean isValue() {
                return value;
        }
        public void setValue(boolean value) {
                this.value = value;
        }

}
------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email



--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com



---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to