private Object invokeTheFunction(List<String> names, FEELFunction fn, EvaluationContext ctx, Object[] params) { if (names.size() == 1) { Object result = fn.invokeReflectively(ctx, params); return result; } else { try { Object newRoot = ctx.getValue(names.get(0)); ctx.enterFrame(); try { Map<String, Object> asMap = ((Map<String, Object>) newRoot); asMap.forEach(ctx::setValue); } catch (ClassCastException e) { ctx.setRootObject(newRoot); // gracefully handle the less common scenario. } return invokeTheFunction(names.subList(1, names.size()), fn, ctx, params); } finally { ctx.exitFrame(); } } }
public Object rreturn(Function<EvaluationContext, Object> expression) { try { ctx.enterFrame(); List results = new ArrayList(); ctx.setValue("partial", results); ForIteration[] ictx = initializeContexts(ctx, iterationContexts); while (ForExpressionNode.nextIteration(ctx, ictx)) { Object result = expression.apply(ctx); results.add(result); } return results; } catch (EndpointOfRangeNotOfNumberException e) { // ast error already reported return null; } finally { ctx.exitFrame(); } }
@Override public EvaluationContext current() { return new SilentWrappingEvaluationContextImpl(wrapped.current()); }
private void evaluateExpressionInContext(EvaluationContext ctx, List results, Object v) { try { ctx.enterFrame(); // handle it as a predicate // Have the "item" variable set first, so to respect the DMN spec: The expression in square brackets can reference a list // element using the name item, unless the list element is a context that contains the key "item". ctx.setValue( "item", v ); // using Root object logic to avoid having to eagerly inspect all attributes. ctx.setRootObject(v); // a filter would always return a list with all the elements for which the filter is true. // In case any element fails in there or the filter expression returns null, it will only exclude the element, but will continue to process the list. // In case all elements fail, the result will be an empty list. Object r = this.filter.evaluate(new SilentWrappingEvaluationContextImpl(ctx)); // evaluate filter, ignoring errors if( r instanceof Boolean && ((Boolean)r) == Boolean.TRUE ) { results.add( v ); } } finally { ctx.exitFrame(); } }
@Override public Object evaluate(CompiledExpression expr, EvaluationContext ctx) { CompiledFEELExpression e = (CompiledFEELExpression) expr; return e.apply(newEvaluationContext(ctx.getListeners(), ctx.getAllValues())); }
@Override public void setValue(String name, Object value) { wrapped.setValue(name, value); }
@Override public Object getValue(String name) { return wrapped.getValue(name); }
@Override public Object evaluate(EvaluationContext ctx) { String varName = EvalHelper.normalizeVariableName( getText() ); if( ! ctx.isDefined( varName ) ) { ctx.notifyEvt( astEvent( FEELEvent.Severity.ERROR, Msg.createMessage( Msg.UNKNOWN_VARIABLE_REFERENCE, getText()), null) ); return null; } return ctx.getValue( varName ); }
if ( name instanceof NameRefNode ) { value = ctx.getValue( name.getText() ); } else if (name instanceof QualifiedNameNode) { QualifiedNameNode qn = (QualifiedNameNode) name; String[] qns = qn.getPartsAsStringArray(); value = ctx.getValue( qns ); } else if (name instanceof PathExpressionNode) { PathExpressionNode pathExpressionNode = (PathExpressionNode) name; return result; } else { ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.FUNCTION_NOT_FOUND, name.getText())) ); return ((UnaryTest) value).apply( ctx, p ); } else { ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.CAN_T_INVOKE_AN_UNARY_TEST_WITH_S_PARAMETERS_UNARY_TESTS_REQUIRE_1_SINGLE_PARAMETER, params.getElements().size()) ) );
public FEELFnResult<Object> invoke(@ParameterName("ctx") EvaluationContext ctx, @ParameterName("namespace") String namespace, @ParameterName("model name") String modelName, @ParameterName("decision name") String decisionName, @ParameterName("parameters") Map<String, Object> parameters) { DMNRuntime dmnRuntime = ctx.getDMNRuntime(); ctx.enterFrame(); DMNModel dmnModel = dmnRuntime.getModel(namespace, modelName); if (dmnModel == null) { capturedException = new FEELEventBase(FEELEvent.Severity.ERROR, "Error invoking function", new RuntimeException("Error invoking function " + getName() + ".", e)); } finally { ctx.exitFrame();
private Boolean iterateContexts(EvaluationContext ctx, List<IterationContextCompiled> iterationContexts, Function<EvaluationContext, Object> expression, Quantifier quantifier) { try { ctx.enterFrame(); QEIteration[] ictx = initializeContexts(ctx, iterationContexts); while (QuantifiedExpressionNode.nextIteration(ctx, ictx)) { Boolean result = (Boolean) expression.apply(ctx); if (result != null && result.equals(quantifier.positiveTest())) { return quantifier.positiveTest(); } } return quantifier.defaultValue(); } finally { ctx.exitFrame(); } }
if( clazzName != null && methodSignature != null ) { Class<?> clazz = Class.forName(clazzName, true, ctx.getRootClassLoader()); if( clazz != null ) { String[] mp = parseMethod( methodSignature ); return new JavaFunction( ANONYMOUS, params, clazz, method ); } else { ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.PARAMETER_COUNT_MISMATCH_ON_FUNCTION_DEFINITION, getText()) ) ); return null; ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.UNABLE_TO_FIND_EXTERNAL_FUNCTION_AS_DEFINED_BY, getText()) ) ); } catch( Exception e ) { ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.ERROR_RESOLVING_EXTERNAL_FUNCTION_AS_DEFINED_BY, getText()), e) );
@Override public Map<String, Object> getAllValues() { return wrapped.getAllValues(); }
public Map<String, Object> closeContext() { evaluationContext.exitFrame(); return resultContext; } }
@Override public void enterFrame() { wrapped.enterFrame(); }
@Override public ClassLoader getRootClassLoader() { return wrapped.getRootClassLoader(); } }
@Override public Object getRootObject() { return wrapped.getRootObject(); }
@Override public DMNRuntime getDMNRuntime() { return wrapped.getDMNRuntime(); }
for (Object v : list) { try { ctx.enterFrame(); ctx.setValue("item", v); ctx.setRootObject(v); ctx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.ERROR_EXECUTING_LIST_FILTER, filterExpression), null, e)); return null; } finally { ctx.exitFrame();
public ContextBuilder setEntry(String key, Object value) { resultContext.put(key, value); evaluationContext.setValue(key, value); return this; }