Class NashornReflectEvaluator

  • All Implemented Interfaces:
    IEvaluator

    public class NashornReflectEvaluator
    extends AbstractEvaluator
    This evaluator uses the Nashorn JS engine that is available in some version of Java.

    This engine was removed in Java 14.

    There are limitations of this engine.

    1. It can only access public methods/fields 2. It can access 'private' fields only if there is a public getter 3. We have to load this via reflection as we need to load from the app classloader not the boot classloader

    • Method Detail

      • loadEvaluator

        public static IEvaluator loadEvaluator​(ClassLoader loader)
        Load the evaluator.
        Parameters:
        loader - the class loader to use
        Returns:
        the evaluator or null if Nashorn is not available.
      • evaluateExpression

        public Object evaluateExpression​(String expression,
                                         Map<String,​Object> values)
                                  throws Throwable
        Description copied from interface: IEvaluator
        Evaluate an expression to the value.
        Parameters:
        expression - the expression to evaluate
        values - the variables that the expression can evaluate against
        Returns:
        the result of the expression
        Throws:
        Throwable - if the expression fails