roxy1987 [http://community.jboss.org/people/roxy1987] created the discussion
"Integration with Drools" To view the discussion, visit: http://community.jboss.org/message/576585#576585 -------------------------------------------------------------- Hi, I am trying to invoke the rules with jBPM. My class definition is following : package com.jboss.dvd.seam; import org.drools.PackageIntegrationException; import org.drools.RuleBase; import org.drools.RuleBaseFactory; import org.drools.RuleIntegrationException; import org.drools.WorkingMemory; import org.drools.compiler.DrlParser; import org.drools.compiler.DroolsParserException; import org.drools.compiler.PackageBuilder; import org.drools.lang.descr.PackageDescr; import org.drools.reteoo.*; import org.drools.rule.InvalidPatternException; import org.drools.rule.Package; import org.jbpm.context.exe.ContextInstance; import org.jbpm.graph.def.ActionHandler; import org.jbpm.graph.exe.ExecutionContext; import java.io.*; import java.util.Iterator; import java.util.List; public class FireRulesActionHandler implements ActionHandler { private static final long serialVersionUID = 1L; public List objectNames; public static String ruleFile; /** * The FireRulesActionHandler gets variables from the Instance, and asserts * them into the Rules Engine and invokes the rules. */ public void execute(ExecutionContext executionContext) throws Exception { // load up the rulebase RuleBase ruleBase = readRule(); WorkingMemory workingMemory = ruleBase.newWorkingMemory(); // load the data Object object = null; System.out.println(objectNames.toString()); Iterator iter = objectNames.iterator(); String objectName = ""; ContextInstance ci = executionContext.getContextInstance(); while (iter.hasNext()) { objectName = (String) iter.next(); object = ci.getVariable(objectName); System.out.println("object name is: " + objectName); // assert the object into the rules engine workingMemory.assertObject(object); } // assert the contextInstance so that it may be used to set results workingMemory.assertObject(ci); workingMemory.fireAllRules(); } /** * Please note that this is the "low level" rule assembly API. */ private static RuleBase readRule() throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { // read in the source Reader reader = new InputStreamReader(FireRulesActionHandler.class.getResourceAsStream(ruleFile)); DrlParser parser = new DrlParser(); PackageDescr packageDescr = parser.parse(reader); // pre build the package PackageBuilder builder = new PackageBuilder(); builder.addPackage(packageDescr); Package pkg = builder.getPackage(); // add the package to a rulebase RuleBase ruleBase = RuleBaseFactory.newRuleBase(); ruleBase.addPackage(pkg); return ruleBase; } } 1. First thing is that, it is not able to recognize the function newWorkingMemory(). 2. Secondly the function assertObject(Object) is also reported undefined. Please Help. Thanks -------------------------------------------------------------- Reply to this message by going to Community [http://community.jboss.org/message/576585#576585] Start a new discussion in jBPM at Community [http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
_______________________________________________ jboss-user mailing list [email protected] https://lists.jboss.org/mailman/listinfo/jboss-user
