de.odysseus.el.util.SimpleContext Java Examples

The following examples show how to use de.odysseus.el.util.SimpleContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JuelUtils.java    From rheem with Apache License 2.0 6 votes vote down vote up
public JuelFunction(String juelExpression, Class<T> resultClass, Map<String, Class<?>> arguments) {
            // Initialize the JUEL conext.
            this.expressionFactory = new de.odysseus.el.ExpressionFactoryImpl();
            this.initializeContext(this.context = new SimpleContext());

            // Index the arguments.
            Class<?>[] argumentTypeClasses = new Class[arguments.size()];
            int argIndex = 0;
            for (Map.Entry<String, Class<?>> argumentEntry : arguments.entrySet()) {
                final String argName = argumentEntry.getKey();
                final Class<?> argTypeClass = argumentEntry.getValue();
                final TreeValueExpression argExpression =
                        this.expressionFactory.createValueExpression(this.context, String.format("${%s}", argName), argTypeClass);
                Argument argument = new Argument(argIndex++, argTypeClass, argExpression);
                argumentTypeClasses[argument.index] = argument.typeClass;
                this.arguments.put(argName, argument);
            }

            // Create the JUEL method.
            this.expression = expressionFactory.createValueExpression(this.context, juelExpression, resultClass);
//            this.expression = expressionFactory.createMethodExpression(this.context, juelExpression, resultClass, argumentTypeClasses);
        }
 
Example #2
Source File: AbstractResolver.java    From gazpachoquest with GNU General Public License v3.0 6 votes vote down vote up
protected boolean isRevealed(String relevance, Map<String, Object> answers) {
    if (StringUtils.isBlank(relevance)) {
        return true;
    }
    SimpleContext context = new SimpleContext();
    for (Entry<String, Object> answer : answers.entrySet()) {
        String code = answer.getKey();
        Object value = answer.getValue();
        if (value != null) {
            context.setVariable(code, elFactory.createValueExpression(value, value.getClass()));
        }
    }
    Boolean revealed = false;
    try {
        // Evaluate the condition
        revealed = (Boolean) elFactory.createValueExpression(context, relevance, Boolean.class).getValue(context);
    } catch (ELException e) {
        logger.warn("Errors found in evaluating the relevance condition", e);
    }
    return revealed;
}
 
Example #3
Source File: JuelUtils.java    From rheem with Apache License 2.0 5 votes vote down vote up
private void initializeContext(SimpleContext ctx) {
    try {
        ctx.setFunction("math", "sqrt", Math.class.getMethod("sqrt", double.class));
        ctx.setFunction("rheem", "logGrowth", OptimizationUtils.class.getMethod(
                "logisticGrowth", double.class, double.class, double.class, double.class)
        );
    } catch (NoSuchMethodException e) {
        throw new RheemException("Could not initialize JUEL context.", e);
    }
}
 
Example #4
Source File: JuelElProvider.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
protected SimpleContext createDefaultParsingElContext() {
  return new SimpleContext();
}
 
Example #5
Source File: JuelElContextFactory.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
public ELContext createElContext(VariableContext variableContext) {
  SimpleContext elContext = new SimpleContext(resolver);
  elContext.putContext(VariableContext.class, variableContext);
  return elContext;
}
 
Example #6
Source File: JuelElProvider.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected SimpleContext createDefaultParsingElContext() {
  return new SimpleContext();
}
 
Example #7
Source File: JuelElContextFactory.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public ELContext createElContext(VariableContext variableContext) {
  SimpleContext elContext = new SimpleContext(resolver);
  elContext.putContext(VariableContext.class, variableContext);
  return elContext;
}