[rules-users] DRLParser not parsing collections

Ken Archer archerovi at hotmail.com
Wed Nov 4 09:49:37 EST 2009


I have successfully used DRLParser with several DRL files, except when they include the 'contains' syntax.  My code for parsing DRL and then dumping into XML, is below:

public class DroolsDumper {

    public static final void main(String[] args) throws DroolsParserException {
        DrlParser parser = new DrlParser();
        PackageDescr descr = parser.parse(new InputStreamReader(DroolsDumper.class.getResourceAsStream("/source.drl" )));

        // Dump to xml rule.
        XmlDumper dumper = new XmlDumper();
        String result = dumper.dump(descr);
        System.out.println(result); 
}}

This code returns the following error when the DRL includes 'contains' syntax:

Exception in thread "main" java.lang.NullPointerException
    at org.drools.xml.XmlDumper.visitPackageDescr(XmlDumper.java:224)
    at org.drools.xml.XmlDumper.dump(XmlDumper.java:71)
    at com.sample.DroolsDumper.main(DroolsDumper.java:19)

This code works fine with the following DRL (whether I dump the parsed DRL into XML or back into DRL):

rule 'cart rule'
dialect "mvel"
when
Cart ()
then
System.out.println("Hello World");
end 

But it returns the above error when the same DRL includes 'contains':

rule 'cart rule'

dialect "mvel"

when

Cart (skus contains (123))

then

System.out.println("Hello World");

end 

The DRL works fine in test scenarios and my cart class's array is declared simply as follows:

package shopping;
import java.util.ArrayList;
public class Cart {
public ArrayList<Integer> skus = new ArrayList<Integer>();
public ArrayList<Integer> getSkus() {
    return skus;
}
public void setSkus(ArrayList<Integer> skus) {
    this.skus = skus;
}
}
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091104/df586d76/attachment.html 


More information about the rules-users mailing list