Class PhonScriptContext
java.lang.Object
ca.phon.script.PhonScriptContext
- Direct Known Subclasses:
QueryScriptContext
Handles setting up script context, scope and
evaluation scripts.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncallFunction(org.mozilla.javascript.Scriptable scope, String name, Object... args) Call the specified function with the given arguments.org.mozilla.javascript.ScriptableCreate a basic Scriptable objectorg.mozilla.javascript.ScriptableSetup scope for script with default imports included and therequirefunction installed.org.mozilla.javascript.Contextenter()Enter and return a new script context.static ObjectEvaulate the given text and return the result (if any)exec(org.mozilla.javascript.Scriptable scope) Evaluate script using given scopevoidexit()org.mozilla.javascript.ScriptReturn the compiled version of the script.567\l *org.mozilla.javascript.ContextFactoryorg.mozilla.javascript.Scriptableorg.mozilla.javascript.ScriptablegetEvaluatedScope(org.mozilla.javascript.Scriptable parentScope) Get the evaluated scope for the script.Get the phon script object associated with this contextgetScriptParameters(org.mozilla.javascript.Scriptable scope) Get the parameters for the script.org.mozilla.javascript.WrapFactorybooleanhasFunction(org.mozilla.javascript.Scriptable scope, String name, int arity) Does the script have a function with the given name and arity.voidinstallParams(org.mozilla.javascript.Scriptable scope) Install these script params into the given scopevoidredirectStdErr(PrintStream stream) voidredirectStdOut(PrintStream stream) void
-
Field Details
-
SCRIPT_EXPORTS
- See Also:
-
-
Constructor Details
-
PhonScriptContext
-
-
Method Details
-
redirectStdOut
-
getStdOut
-
redirectStdErr
-
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 {#linkexit() -
exit
public void exit() -
eval
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
Setup scope for script with default imports included and therequirefunction installed.- Returns:
- the top-level scope for the script
- Throws:
PhonScriptException
-
hasFunction
Does the script have a function with the given name and arity.- Parameters:
name-arity-- Returns:
trueif a function with the given name and arity is found,falseotherwise
-
getEvaluatedScope
- 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 benull- Returns:
- the evaluated scope
- Throws:
PhonScriptException
-
getCompiledScript
Return the compiled version of the script.567\l *- Returns:
- compiled script
- Throws:
PhonScriptException
-
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
Evaluate script using given scope- Parameters:
scope-- Returns:
- result of executing the script or
nullif 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
Install these script params into the given scope- Parameters:
scope-context-- Throws:
PhonScriptException
-