java.lang.Object
com.dlsc.gmapsfx.javascript.JavascriptRuntime
- All Implemented Interfaces:
IJavascriptRuntime
public class JavascriptRuntime extends Object implements IJavascriptRuntime
Class for interacting with the JavaScript environment. This class is used by
the JavaScript objects, but should not need to be used directly for creating
or changing maps.
- Author:
- Rob Terpilowski
-
Field Summary
Fields Modifier and Type Field Description static IWebEngineengineprotected static IJavascriptRuntimeruntime -
Constructor Summary
Constructors Constructor Description JavascriptRuntime() -
Method Summary
Modifier and Type Method Description JSObjectexecute(String command)Execute the specified command returning a value (if any)protected StringgetArgString(Object arg)Takes the specified object and converts the argument to a String.StringgetArrayConstructor(String javascriptObjectType, Object[] ary)Gets an array parameter constructor as a String, which then can be passed to the execute() method.StringgetArrayFunction(String function, Object[] ary)Gets an array function as a String, which then can be passed to the execute() method.StringgetConstructor(String javascriptObjectType, Object... args)Gets a constructor as a string which then can be passed to the execute().StringgetFunction(String function, Object... args)Gets a function as a String, which then can be passed to the execute() method.StringgetFunction(String variable, String function, Object... args)Gets a function as a String, which then can be passed to the execute() method.static IJavascriptRuntimegetInstance()Gets a singleton instance of this class, creating one if it doesn't yet exist.static voidsetDefaultWebEngine(IWebEngine e)Set the WebEngine that this runtime should use.static voidsetJavascriptRuntime(IJavascriptRuntime testRuntime)Sets a Javascript runtime to use.
-
Field Details
-
Constructor Details
-
JavascriptRuntime
public JavascriptRuntime()
-
-
Method Details
-
getInstance
Gets a singleton instance of this class, creating one if it doesn't yet exist.- Returns:
- A singleton instance
-
setDefaultWebEngine
Set the WebEngine that this runtime should use.- Parameters:
e- The underlying WebEngine to use.
-
execute
Execute the specified command returning a value (if any)- Specified by:
executein interfaceIJavascriptRuntime- Parameters:
command- The JavaScript command to execute- Returns:
- The underlying JavaScript object that was returned by the script.
-
getConstructor
Gets a constructor as a string which then can be passed to the execute().- Specified by:
getConstructorin interfaceIJavascriptRuntime- Parameters:
javascriptObjectType- The type of JavaScript object to createargs- The args of the constructor- Returns:
- A string which can be passed to the JavaScript environment to create a new object.
-
getArrayConstructor
Gets an array parameter constructor as a String, which then can be passed to the execute() method.- Specified by:
getArrayConstructorin interfaceIJavascriptRuntime- Parameters:
javascriptObjectType- type The type of JavaScript object array to createary- The array elements- Returns:
- A string which can be passed to the JavaScript environment to create a new array.
-
getFunction
Gets a function as a String, which then can be passed to the execute() method.- Specified by:
getFunctionin interfaceIJavascriptRuntime- Parameters:
variable- The variable to invoke the function on.function- The function to invokeargs- Arguments the function requires- Returns:
- A string which can be passed to the JavaScript environment to invoke the function
-
getFunction
Gets a function as a String, which then can be passed to the execute() method.- Specified by:
getFunctionin interfaceIJavascriptRuntime- Parameters:
function- The function to invokeargs- Arguments the function requires- Returns:
- A string which can be passed to the JavaScript environment to invoke the function
-
getArrayFunction
Gets an array function as a String, which then can be passed to the execute() method.- Specified by:
getArrayFunctionin interfaceIJavascriptRuntime- Parameters:
function- The function to invokeary- The array of arguments to pass to the function.- Returns:
- A string which can be passed to the JavaScript environment to invoke the function
-
setJavascriptRuntime
Sets a Javascript runtime to use. Should only be used by unit tests to set a mock runtime- Parameters:
testRuntime- The runtime to use
-
getArgString
Takes the specified object and converts the argument to a String.- Parameters:
arg- The object to convert- Returns:
- A String representation of the argument.
-