Class PhonScriptContext

java.lang.Object
ca.phon.script.PhonScriptContext
Direct Known Subclasses:
QueryScriptContext

public class PhonScriptContext extends Object
Handles setting up script context, scope and evaluation scripts.
  • Field Details

  • Constructor Details

    • PhonScriptContext

      public PhonScriptContext(PhonScript script)
  • Method Details

    • redirectStdOut

      public void redirectStdOut(PrintStream stream)
    • getStdOut

      public PrintStream getStdOut()
    • redirectStdErr

      public void redirectStdErr(PrintStream stream)
    • getStdErr

      public PrintStream getStdErr()
    • getContextFactory

      public org.mozilla.javascript.ContextFactory getContextFactory()
    • enter

      public org.mozilla.javascript.Context enter()
      Enter and return a new script context. Every call to this method should have a matching call to {#link exit()
    • exit

      public void exit()
    • eval

      public static Object eval(String text) throws PhonScriptException
      Evaulate the given text and return the result (if any)
      Parameters:
      script -
      Returns:
      the return value of the script. May be null
      Throws:
      PhonScriptException
    • createBasicScope

      public org.mozilla.javascript.Scriptable createBasicScope()
      Create a basic Scriptable object
      Returns:
      basic Scriptable
    • createImporterScope

      public org.mozilla.javascript.Scriptable createImporterScope() throws PhonScriptException
      Setup scope for script with default imports included and the require function installed.
      Returns:
      the top-level scope for the script
      Throws:
      PhonScriptException
    • hasFunction

      public boolean hasFunction(org.mozilla.javascript.Scriptable scope, String name, int arity)
      Does the script have a function with the given name and arity.
      Parameters:
      name -
      arity -
      Returns:
      true if a function with the given name and arity is found, false otherwise
    • getEvaluatedScope

      public org.mozilla.javascript.Scriptable getEvaluatedScope() throws PhonScriptException
      Throws:
      PhonScriptException
    • resetEvaulatedScope

      public void resetEvaulatedScope()
    • getEvaluatedScope

      public org.mozilla.javascript.Scriptable getEvaluatedScope(org.mozilla.javascript.Scriptable parentScope) throws PhonScriptException
      Get the evaluated scope for the script. The evaluated scope is the Scriptable object resulting from evaulating the script. The evaluated scope is useful for working with functions defined in the scropt.
      Parameters:
      parentScope - may be null
      Returns:
      the evaluated scope
      Throws:
      PhonScriptException
    • getCompiledScript

      public org.mozilla.javascript.Script getCompiledScript() throws PhonScriptException
      Return the compiled version of the script.567\l *
      Returns:
      compiled script
      Throws:
      PhonScriptException
    • getPhonScript

      public PhonScript getPhonScript()
      Get the phon script object associated with this context
      Returns:
      the PhonScript
    • getScriptParameters

      public ScriptParameters getScriptParameters(org.mozilla.javascript.Scriptable scope) throws PhonScriptException
      Get the parameters for the script.
      Parameters:
      scope -
      Returns:
      script parameters
      Throws:
      PhonScriptException
    • exec

      public Object exec(org.mozilla.javascript.Scriptable scope) throws PhonScriptException
      Evaluate script using given scope
      Parameters:
      scope -
      Returns:
      result of executing the script or null if not applicable
      Throws:
      PhonScriptException
    • callFunction

      public Object callFunction(org.mozilla.javascript.Scriptable scope, String name, Object... args) throws PhonScriptException
      Call the specified function with the given arguments.
      Parameters:
      scope -
      args -
      method -
      Returns:
      Throws:
      PhonScriptException
    • getWrapFactory

      public org.mozilla.javascript.WrapFactory getWrapFactory()
    • installParams

      public void installParams(org.mozilla.javascript.Scriptable scope) throws PhonScriptException
      Install these script params into the given scope
      Parameters:
      scope -
      context -
      Throws:
      PhonScriptException