use of org.drools.template.DataProvider in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceImpl method chooseDataProvider.
private DataProvider chooseDataProvider(final RuleModel model) {
DataProvider dataProvider;
TemplateModel tplModel = (TemplateModel) model;
if (tplModel.getRowsCount() > 0) {
dataProvider = new ArrayDataProvider(tplModel.getTableAsArray());
} else {
dataProvider = generateEmptyIterator();
}
return dataProvider;
}
use of org.drools.template.DataProvider in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceImpl method marshal.
@Override
public String marshal(final RuleModel model) {
// Build rule
final String ruleTemplate = marshalRule(model);
log.debug("ruleTemplate:\n{}", ruleTemplate);
log.debug("generated template:\n{}", ruleTemplate);
final DataProvider dataProvider = chooseDataProvider(model);
final DataProviderCompiler tplCompiler = new DataProviderCompiler();
final InputStream templateStream = new ByteArrayInputStream(ruleTemplate.getBytes(IoUtils.UTF8_CHARSET));
final DefaultTemplateContainer tc = new DefaultTemplateContainer(templateStream, false);
final TemplateDataListener listener = new TemplateDataListener(tc, false);
final String generatedDrl = tplCompiler.compile(dataProvider, listener);
log.debug("generated drl:\n{}", generatedDrl);
return generatedDrl;
}
Aggregations