use of org.mvel2.templates.SimpleTemplateRegistry in project mvel by mvel.
the class TemplateTests method testDRLTemplate.
public void testDRLTemplate() {
String template = "@declare{\"drl\"}@includeNamed{\"ced\"; node=root }@end{}" + "" + "@declare{\"ced\"}" + "@if{ node.base==1 } @includeNamed{ \"cedX\"; connect=\"AND\"; args=node.list }" + "@elseif{ node.base ==2 }@includeNamed{ \"cedX\"; connect=\"OR\"; args=node.list }" + "@end{}" + "@end{}" + "" + "@declare{\"cedX\"}@{connect}@foreach{child : args}" + "@includeNamed{\"ced\"; node=child; }@end{} @{connect}@end{}";
TemplateRegistry reportRegistry = new SimpleTemplateRegistry();
reportRegistry.addNamedTemplate("drl", TemplateCompiler.compileTemplate(template));
TemplateRuntime.execute(reportRegistry.getNamedTemplate("drl"), null, reportRegistry);
Map<String, Object> context = new HashMap<String, Object>();
context.put("root", new Node(2, Arrays.asList(new Node(1, Collections.EMPTY_LIST))));
String result = (String) TemplateRuntime.execute(reportRegistry.getNamedTemplate("drl"), null, new MapVariableResolverFactory(context), reportRegistry);
assertEquals("OR AND AND OR", result);
}
use of org.mvel2.templates.SimpleTemplateRegistry in project mvel by mvel.
the class TemplateTests method testInclusionOfNamedTemplate.
public void testInclusionOfNamedTemplate() {
SimpleTemplateRegistry registry = new SimpleTemplateRegistry();
registry.addNamedTemplate("footemplate", compileTemplate("@{_foo_}@{_bar_}"));
registry.addNamedTemplate("bartemplate", compileTemplate("@{_bar_}@{_foo_}"));
String s = "@includeNamed{'footemplate'} :: @includeNamed{'bartemplate'}";
assertEquals("FooBar :: BarFoo", TemplateRuntime.eval(s, map, registry));
}
use of org.mvel2.templates.SimpleTemplateRegistry in project drools by kiegroup.
the class MiningSegmentation method initTemplates.
private static synchronized void initTemplates() {
if (templates == null) {
templates = new SimpleTemplateRegistry();
}
if (templateNameToFile == null) {
templateNameToFile = new HashMap<>();
templateNameToFile.put(MULTIPLEMODELMETHOD.SELECT_FIRST.name(), segmentActivationSelectFirst);
templateNameToFile.put(MULTIPLEMODELMETHOD.SELECT_ALL.name(), segmentSelectAll);
templateNameToFile.put(MULTIPLEMODELMETHOD.MODEL_CHAIN.name(), segmentModelChain);
}
}
Aggregations