use of org.kie.dmn.core.ast.DMNContextEvaluator in project drools by kiegroup.
the class DMNEvaluatorCompiler method compileContext.
private DMNExpressionEvaluator compileContext(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String contextName, Context expression) {
Context ctxDef = expression;
DMNContextEvaluator ctxEval = new DMNContextEvaluator(node.getName(), ctxDef);
ctx.enterFrame();
try {
for (ContextEntry ce : ctxDef.getContextEntry()) {
if (ce.getVariable() != null) {
String entryName = ce.getVariable().getName();
DMNCompilerHelper.checkVariableName(model, node.getSource(), entryName);
DMNType entryType = compiler.resolveTypeRef(model, node, ce.getVariable(), ce.getVariable(), ce.getVariable().getTypeRef());
// add context entry to the list of available variables for the following entries
ctx.setVariable(entryName, entryType);
DMNExpressionEvaluator evaluator = compileExpression(ctx, model, node, entryName, ce.getExpression());
ctxEval.addEntry(entryName, entryType, evaluator, ce);
} else {
// if the variable is not defined, then it should be the last
// entry in the context and the result of this context evaluation is the
// result of this expression itself
// TODO: if it is not the last entry, raise error message
DMNType type = null;
if (ctxDef.getParent() instanceof ContextEntry && ((ContextEntry) ctxDef.getParent()).getVariable() != null) {
ContextEntry parentEntry = (ContextEntry) ctxDef.getParent();
type = compiler.resolveTypeRef(model, node, parentEntry.getVariable(), parentEntry.getVariable(), parentEntry.getVariable().getTypeRef());
} else if (node instanceof BusinessKnowledgeModelNode) {
type = ((BusinessKnowledgeModelNode) node).getResultType();
} else if (node instanceof DecisionNode) {
type = ((DecisionNode) node).getResultType();
}
ctxEval.addEntry(DMNContextEvaluator.RESULT_ENTRY, type, compileExpression(ctx, model, node, contextName, ce.getExpression()), ce);
}
}
} finally {
ctx.exitFrame();
}
return ctxEval;
}
Aggregations