While drools 2.x was limited to XML, 4.0 preference is for the DRL,
which is a none xml format. It doesn't produce a jar at the moment just
a binary Packaage instance, which you can serialise.
Mark
fuadhamidov wrote:
hi,
i developed my project using drools 2.5. now i want to upgrade to drools
4.0. in my project i
(1) create xml file,
(2) compile xml file & get jar file,
(3) save jar file
(4) and load jar file when i need to run rules
i was able to upgrade xml file to drools 4.0 xml format, but i can not do
necessary modification in code to compile xml and get "jar or any reloadable
file".
There is my code that is developed for drools 2.5. Can you help me to
upgrade it for drools 4.0?
void compile() throws Exception {
// read xml file, returns data in xml format
String rulecontent = readRuleFromFile();
byte[] bytes = null;
// codes for drools 2.5. i want to develop corresponding code for 4
statement bellow that runs with drools 4.0
// RuleSetReader reader = new RuleSetReader();
// RuleSet ruleSet = reader.read(new BufferedReader(new
StringReader(rulecontent)));
// RuleSetCompiler compiler = new RuleSetCompiler(ruleSet, "com.sample",
"knowledgeHelper");
// bytes = compiler.getBinaryDeploymentJar();
// some codes for drools 4.0, but it is not finilized
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromXml(new BufferedReader(new
StringReader(rulecontent)));
Package pkg = builder.getPackage();
//... and then what? how do it get bytecode from package?
//may be 3 statements are not necessary for compilation
// save to disk as a jar file
writeRuleToJar(bytes);
}
void runrule(Object usg) throws Exception {
// runs both, drools 2.5 and drools 4.0
ConflictResolver[] conflictResolvers = new ConflictResolver[] {
SalienceConflictResolver.getInstance(),
ComplexityConflictResolver.getInstance(),
FifoConflictResolver.getInstance() };
CompositeConflictResolver compositeConflictResolver = new
CompositeConflictResolver(conflictResolvers);
byte[] bytecode = readRuleFromJar();
// i can not develope this part also
// RuleBaseLoader loader = new RuleBaseLoader(compositeConflictResolver);
// loader.addFromByteArray(bytecode);
// RuleBase ruleBase = loader.buildRuleBase();
// modification in code for drools 4.0
// WorkingMemory workingMemory = ruleBase.newWorkingMemory();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
// workingMemory.assertObject(usg);
workingMemory.insert(usg);
workingMemory.fireAllRules();
}