I have been struggling with this for a few days and thought someone out there may benefit from my pain.
I couldn’t figure out how to configure my excel spreadsheets for use in Seam. I tried this in my components.xml:
<drools:rule-base name="ruleBase" rule-files="Sample.xls"/ >
<drools:managed-working-memory name="workingMemory" auto-create="true" rule-base="#{ruleBase}"/>While this worked with my Sample.drl it didn’t work with Sample.xls.
So now I have a new class that creates the rule base from the excel spreadsheet. The base of the code was taken from the samples provided by the Drools IDE.
package edu.umich.med.psi.drools;
import java.io.StringReader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.compiler.PackageBuilder;
import org.drools.decisiontable.InputType;
import org.drools.decisiontable.SpreadsheetCompiler;
import org.drools.rule.Package;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
@Scope(ScopeType.APPLICATION)
@Startup()
@Name("xlsCompiler")
public class XlsCompiler
{
public RuleBase readDecisionTable(String xlsFile) throws Exception
{
// read in the source
final SpreadsheetCompiler converter = new SpreadsheetCompiler();
final String drl = converter.compile(xlsFile, InputType.XLS);
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new StringReader(drl));
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
return ruleBase;
}
}
Now in my components.xml I wire them together like this.
<drools:managed-working-memory name="workingMemory" auto-create="true" scope="session" rule-base="#{xlsCompiler.readDecisionTable('/Sample.xls')}"/>It works great.
PS I also had to include the jxl-n-n-jar in my ear.