Class BoxScriptingEngine

java.lang.Object
ortus.boxlang.runtime.scripting.BoxScriptingEngine
All Implemented Interfaces:
Compilable, Invocable, ScriptEngine

public class BoxScriptingEngine extends Object implements ScriptEngine, Compilable, Invocable
The BoxScriptingEngine is the JSR-223 implementation for BoxLang. It is the entry point for executing BoxLang code on the JVM.
See Also:
  • Constructor Details

    • BoxScriptingEngine

      public BoxScriptingEngine(BoxScriptingFactory boxScriptingFactory, Boolean debug)
      Constructor for the BoxScriptingEngine
      Parameters:
      boxScriptingFactory - The factory for the BoxScriptingEngine
      debug - Whether to run in debug mode, defaults to false
      See Also:
    • BoxScriptingEngine

      public BoxScriptingEngine(BoxScriptingFactory boxScriptingFactory)
      Constructor for the BoxScriptingEngine
      Parameters:
      boxScriptingFactory - The factory for the BoxScriptingEngine
      See Also:
  • Method Details

    • getRuntime

      public BoxRuntime getRuntime()
      Get the BoxRuntime for the BoxScriptingEngine
      Returns:
      The BoxRuntime for the BoxScriptingEngine
    • eval

      public Object eval(String script, ScriptContext context) throws ScriptException
      Evaluate a script in the context of the ScriptContext
      Specified by:
      eval in interface ScriptEngine
      Parameters:
      script - The script to evaluate
      context - The context to evaluate the script in
      Returns:
      The result of the script evaluation
      Throws:
      ScriptException
    • eval

      public Object eval(Reader reader, ScriptContext context) throws ScriptException
      Evaluate a script in the context of the ScriptContext
      Specified by:
      eval in interface ScriptEngine
      Parameters:
      reader - The reader to read the script from
      context - The context to evaluate the script in
      Returns:
      The result of the script evaluation
      Throws:
      ScriptException
    • eval

      public Object eval(Reader reader) throws ScriptException
      Evaluate a script bound only to the top-level BoxRuntime context
      Specified by:
      eval in interface ScriptEngine
      Parameters:
      reader - The reader to read the script from
      Returns:
      The result of the script evaluation
      Throws:
      ScriptException
    • eval

      public Object eval(String script, Bindings n) throws ScriptException
      Evaluate a script using the given Bindings
      Specified by:
      eval in interface ScriptEngine
      Parameters:
      script - The script to evaluate
      n - The Bindings to use
      Returns:
      The result of the script evaluation
      Throws:
      ScriptException
    • eval

      public Object eval(Reader reader, Bindings n) throws ScriptException
      Specified by:
      eval in interface ScriptEngine
      Throws:
      ScriptException
    • eval

      public Object eval(String script) throws ScriptException
      Evaluate a script bound only to the top-level BoxRuntime context
      Specified by:
      eval in interface ScriptEngine
      Parameters:
      script - The script to evaluate
      Returns:
      The buffer from the BoxContext
      Throws:
      ScriptException
    • createBindings

      public Bindings createBindings()
      Create a new Bindings object
      Specified by:
      createBindings in interface ScriptEngine
      Returns:
      A new Bindings object
    • creatBindings

      public Bindings creatBindings(Map<String,Object> m)
      Create a new Bindings object with the given map
      Parameters:
      m - The map to seed the Bindings with
      Returns:
      A new Bindings object with the given map
    • put

      public void put(String key, Object value)
      Specified by:
      put in interface ScriptEngine
    • get

      public Object get(String key)
      Specified by:
      get in interface ScriptEngine
    • getBindings

      public Bindings getBindings()
      Get the defaults bindings which is the variables scope = engine scope
      Returns:
      The bindings for the given scope if found, else null
    • getRequestBindings

      public Bindings getRequestBindings()
      Helper method to get the request scope bindings
    • getServerBindings

      public Bindings getServerBindings()
      Helper method to get the server scope bindings
    • getBindings

      public Bindings getBindings(int scope)
      Get the bindings for the given scope
      Specified by:
      getBindings in interface ScriptEngine
      Parameters:
      scope - The scope to get the bindings for
      Returns:
      The bindings for the given scope if found, else null
    • setBindings

      public void setBindings(Bindings bindings, int scope)
      Set the bindings for the given scope
      Specified by:
      setBindings in interface ScriptEngine
      Parameters:
      bindings - The bindings to set
      scope - The scope to set the bindings for
      Throws:
      IllegalArgumentException - If the scope is invalid
    • getContext

      public ScriptContext getContext()
      Get the ScriptContext for the BoxScriptingEngine
      Specified by:
      getContext in interface ScriptEngine
      Returns:
      The ScriptContext for the BoxScriptingEngine
    • setContext

      public void setContext(ScriptContext context)
      Set the ScriptContext for the BoxScriptingEngine
      Specified by:
      setContext in interface ScriptEngine
      Parameters:
      context - The ScriptContext to set
    • getFactory

      public ScriptEngineFactory getFactory()
      Specified by:
      getFactory in interface ScriptEngine
    • compile

      public CompiledScript compile(String script) throws ScriptException
      Compile a script
      Specified by:
      compile in interface Compilable
      Parameters:
      script - The script to compile
      Returns:
      The compiled script
      Throws:
      ScriptException
    • compile

      public CompiledScript compile(Reader script) throws ScriptException
      Compile a script
      Specified by:
      compile in interface Compilable
      Parameters:
      script - The script to compile
      Returns:
      The compiled script
      Throws:
      ScriptException
    • getBoxContext

      public JSRScriptingRequestBoxContext getBoxContext()
      Get the BoxContext for the BoxScriptingEngine
      Returns:
      The BoxContext for the BoxScriptingEngine
    • invokeMethod

      public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException
      This is used when you eval a script that is a BoxLang object definition.
      Specified by:
      invokeMethod in interface Invocable
      Parameters:
      thiz - The object to invoke the method on
      name - The name of the method to invoke
      args - The positional arguments to pass to the method
      Returns:
      The result of the method invocation
      Throws:
      ScriptException
      NoSuchMethodException
    • invokeFunction

      public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException
      This is used when you eval a script that is a BoxLang function definition, so you can invoke it.
      Specified by:
      invokeFunction in interface Invocable
      Parameters:
      name - The name of the function to invoke
      args - The positional arguments to pass to the function
      Returns:
      The result of the function invocation
      Throws:
      ScriptException
      NoSuchMethodException
    • getInterface

      public <T> T getInterface(Class<T> clasz)
      Returns an implementation of an interface using functions compiled in the interpreter.
      Specified by:
      getInterface in interface Invocable
      Parameters:
      clasz - The interface to create the dynamic proxy
      Returns:
      An implementation of the interface using functions compiled in the interpreter
    • getInterface

      public <T> T getInterface(Object thiz, Class<T> clasz)
      Builds a dynamic proxy from the passed in object that maps to the given interface.
      Specified by:
      getInterface in interface Invocable
      Parameters:
      thiz - The object to create the proxy from. This can be a BoxLang object, structure, or a Map or function.
      clasz - The interface to create the dynamic proxy
      Returns:
      An implementation of the interface using functions compiled in the interpreter