Class NashornEvaluator<T>

  • Type Parameters:
    T - generic parameter for return types from this evaluator
    All Implemented Interfaces:
    Evaluator<T>

    public class NashornEvaluator<T>
    extends java.lang.Object
    implements Evaluator<T>
    public void setBindings(Bindings bindings, int scope);
    • Constructor Summary

      Constructors 
      Constructor Description
      NashornEvaluator​(java.lang.Class<? extends T> resultType, java.lang.Object... vars)
      Create a new NashornEvaluator.
    • Method Summary

      Modifier and Type Method Description
      T eval()
      Evaluate the compiled script if it is compiled, or the raw script text otherwise.
      NashornEvaluator<T> put​(java.lang.String varName, java.lang.Object var)
      Put a varianble into the script environment
      NashornEvaluator<T> script​(java.lang.String scriptText)
      Set the script that will be evaluated.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NashornEvaluator

        public NashornEvaluator​(java.lang.Class<? extends T> resultType,
                                java.lang.Object... vars)
        Create a new NashornEvaluator.
        Parameters:
        resultType - The required class of the result type, which must extend generic parameter type t.
        vars - Optional pairs of names and values. vars[0] is a name, vars[1] is a value, ...
    • Method Detail

      • script

        public NashornEvaluator<T> script​(java.lang.String scriptText)
        Set the script that will be evaluated.
        Specified by:
        script in interface Evaluator<T>
        Parameters:
        scriptText - Nashorn compatible script text
        Returns:
        this NashornEvaluator, for method chaining
      • eval

        public T eval()
        Evaluate the compiled script if it is compiled, or the raw script text otherwise. It is not an error to call this without setting the script to something other than the default of "", but it not very useful in most cases.
        Specified by:
        eval in interface Evaluator<T>
        Returns:
        The value produced by the script, compiled or not
      • put

        public NashornEvaluator<T> put​(java.lang.String varName,
                                       java.lang.Object var)
        Put a varianble into the script environment
        Specified by:
        put in interface Evaluator<T>
        Parameters:
        varName - the variable name to add to the environment
        var - the object to bind to the varname
        Returns:
        this NashornEvaluator, for method chaining