viernes, 25 de enero de 2013

Drools 5.0 - Read rules



Another form to read the Droools rules is through a FileInputStream


                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();

FileInputStream  fis = new FileInputStream(url);
kbuilder.add(ResourceFactory.newInputStreamResource(fis), ResourceType.DTABLE);

KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;

Instead of

             kbuilder.add(ResourceFactory.newClassPathResource(url), ResourceType.DRL);

No hay comentarios:

Publicar un comentario