Running the latest 5.0.1 snapshot jars and it can handle enums fine. See attached code. It should print out the following output when run:
Hello World Goodbye cruel world At some point I said GOODBYE OK_I_AM_SERIOUSLY_SAYING_GOODBYE_NOW is the current status AND at some point I said HELLO At some point I said HELLO --- On Fri, 5/1/09, Armaghan Mahmud <[email protected]> wrote: > From: Armaghan Mahmud <[email protected]> > Subject: [rules-users] Rules question > To: "Rules Users List" <[email protected]> > Date: Friday, May 1, 2009, 11:10 AM > I'm new to the mailing list so I'll start off by > saying hello to everyone. > I've recently started using DROOLS and I seem to have > hit a dead end. I'm > trying to pass in an enum and a list into the working > memory one at a time > but I would like my rule to first see if it the enum > matches a hard coded > enum value. Additionally, I would also like the rule to see > if the enum > value that is being passed to the working memory happens to > fall in the list > or not. First of all, is it possible to do that in one > rule? I've been > trying to do that using "&&" and > "contains" keywords but I'm not getting > anywhere. I don't have the code in front of me or I > would've pasted it but I > hope you can understand my point. Any help that I can get > in this matter > will be greatly appreciated. > > Thanks, > Armaghan > _______________________________________________ > rules-users mailing list > [email protected] > https://lists.jboss.org/mailman/listinfo/rules-users
package com.sample;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.LinkedList;
import java.util.List;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
/**
* This is a sample file to launch a rule package from a rule source file.
*/
public class DroolsTest {
public static final void main(String[] args) {
try {
//load up the rulebase
RuleBase ruleBase = readRule();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
//go !
Message message = new Message();
workingMemory.insert( message );
workingMemory.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
/**
* Please note that this is the "low level" rule assembly API.
*/
private static RuleBase readRule() throws Exception {
//read in the source
Reader source = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );
//optionally read in the DSL (if you are using it).
//Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );
//Use package builder to build up a rule package.
//An alternative lower level class called "DrlParser" can also be used...
PackageBuilder builder = new PackageBuilder();
//this will parse and compile in one step
//NOTE: There are 2 methods here, the one argument one is for normal DRL.
builder.addPackageFromDrl( source );
//Use the following instead of above if you are using a DSL:
//builder.addPackageFromDrl( source, dsl );
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
public static class Message {
public static enum Type {
HELLO, GOODBYE, OK_I_AM_SERIOUSLY_SAYING_GOODBYE_NOW;
}
private String message = "Hello World";
private Type status = Type.HELLO;
private final List<Type> statusHistory = new LinkedList<Type>();
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public Type getStatus() {
return this.status;
}
public void setStatus( Type status ) {
statusHistory.add(this.status);
this.status = status;
}
public List<Type> getStatusHistory() {
return statusHistory;
}
}
}
Sample.drl
Description: Binary data
_______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
