Class Script


  • public final class Script
    extends Object
    A compiled script.
    • Method Detail

      • fromFile

        public static Script fromFile​(Environment environment,
                                      String mimeType,
                                      String file)
                               throws ScriptException
        Loads a script having the provided content type and file name.
        Parameters:
        environment - The application environment.
        mimeType - The script language mime-type.
        file - The location of the script to be loaded.
        Returns:
        The script.
        Throws:
        ScriptException - If the script could not be loaded.
      • fromSource

        public static Script fromSource​(Environment environment,
                                        String mimeType,
                                        String... sourceLines)
                                 throws ScriptException
        Loads a script having the provided content type and content.
        Parameters:
        environment - The application environment.
        mimeType - The script language mime-type.
        sourceLines - The script content.
        Returns:
        The script.
        Throws:
        ScriptException - If the script could not be loaded.
      • fromSource

        public static Script fromSource​(Environment environment,
                                        String mimeType,
                                        String source)
                                 throws ScriptException
        Loads a script having the provided content type and content.
        Parameters:
        environment - The application environment.
        mimeType - The script language mime-type.
        source - The script content.
        Returns:
        The script.
        Throws:
        ScriptException - If the script could not be loaded.
      • run

        public Object run​(Map<String,​Object> bindings)
                   throws ScriptException
        Runs this script using the provided named variable bindings.
        Parameters:
        bindings - The set of bindings to inject into the script.
        Returns:
        The result returned by the script.
        Throws:
        ScriptException - If the script failed to execute.