Unit Test (droolsjbpm-ide-common)
org.drools.ide.common.server.util.BRLPersistenceTest.testRoundTrip()
performs what you are attempting too. This test passes.
I am still uncertain why you reference "org.drools.brms" packages in your
import statements. What version of Drools are you using?
2011/9/15 AZZAZ mohamed <azzazm(a)gmail.com>
I added all necessary jar in the classpath.
Here is an excerpt from my code:
Just for information I am beginner in BRMS
/**
*
*/
package fr.dto;
import java.io.*;
import javax.swing.Box.Filler;
import org.apache.commons.io.FileUtils;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.brms.server.util.BRDRLPersistence;
import org.drools.brms.server.util.BRXMLPersistence;
import org.drools.compiler.PackageBuilder;
import org.drools.event.DebugWorkingMemoryEventListener;
import org.drools.rule.Package;
/**
* @author mazzaz
*
*/
public class RulesEngine {
private RuleBase rules;
private Reader source;
private boolean debug = false;
public RulesEngine(String rulesFile) throws RulesEngineException {
super();
try {
try
{
File file = null;
String brl =null;
file = new File(rulesFile);
BRXMLPersistence read = (BRXMLPersistence) BRXMLPersistence.getInstance();
BRDRLPersistence write = (BRDRLPersistence)
BRDRLPersistence.getInstance();
System.out.println("read && write instance ok \n");
brl = FileUtils.readFileToString(file,"UTF-8");
System.out.println("le fichier contient"+ brl);
String outputDRL = write.marshal(read.unmarshal(brl));// code blocked
here
String drlFilePath = "src/main/rules/Test_brl_to_drl.drl";
File drlFile = new File(drlFilePath);
FileUtils.writeStringToFile(drlFile,outputDRL,"");
source = new InputStreamReader(RulesEngine.class
.getResourceAsStream(drlFilePath));
}catch (IOException ie){
System.out.println("ie.getCause(): "+ie.getCause()
+"\n"+"ie.getMessage(): "+ie.getMessage());
}
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(source);
Package pkg = builder.getPackage();
rules = RuleBaseFactory.newRuleBase();
rules.addPackage(pkg);
} catch (Exception e) {
throw new RulesEngineException(
"Impossible de Compiler le fichier de regles : "
+ rulesFile, e);
}
}
public void executeRules(WorkingEnvironmentCallback callback) {
/*
* L’instanciation de la class workingMemory permet de determiner si
* toute si toute les conditions d’une regle sont remplies alors les
* consequences de cette regles sont executées
*/
WorkingMemory workingMemory = rules.newStatefulSession();
if (debug) {
workingMemory
.addEventListener(new DebugWorkingMemoryEventListener());
}
callback.initEnvironment(workingMemory);// initEnvironment methode de
// l'interface
/*
* L’execution des conséquences d’une regle se produit lorsqu’on invoque
* l’objet fireAllRules WorkingMemory
*/
workingMemory.fireAllRules();
}
}
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users