Package com.singularsys.client
Class GWTExpose
java.lang.Object
com.singularsys.client.GWTExpose
- All Implemented Interfaces:
EntryPoint
GWT entry point exposing parts of the Jep system to JavaScript using the JSNI system.
The following methods are provided
var node = window.jep.parse(string)parse an expressionwindow.jep.evaluateD()evaluate the last expression parsedwindow.jep.evaluate(node)evaluate a nodewindow.jep.getVariableValue(name)return the value of a Jep variablewindow.jep.setVariable(name,val)set the value of a Jep variablewindow.jep.getErrMsg()return the last error messagewindow.jep.nodeType(node)finds the type of a given nodewindow.jep.getNChildren(node)return the number of childerne of a nodewindow.jep.getChild(node,i)find the i-th child of a nodewindow.jep.getOperator(node)find the operator associated with a nodewindow.jep.getNodeName(node)find the name of associated with a node, either a variable name or function namewindow.jep.getNodeValue(node)finds the value of a node, either a constant value of a variable valuewindow.jep.getOpPrec(op)find the precedence of an operatorwindow.jep.getOpSymbol(op)find the symbol of an operatorwindow.jep.nf.buildVarNode(name)build a node representing a variablewindow.jep.nf.buildConstantNode(val)build a node with a constant valuewindow.jep.nf.buildBinaryOpNode(op,l,r)build a node with two arguments
- Author:
- rich
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NodebuildBinaryOpNode(Operator op, Node l, Node r) static NodebuildConstantNode(Object val) static Nodestatic voidconsoleLog(String msg) Native method to write to the JavaScript consolestatic doubleEvaluates the last expression returning a double.static ObjectevaluateNE(Node node) Evaluate a node, returning an object, does not throw exceptionsstatic ObjectEvaluate a node, returning an objectstatic NodeGets the child of a nodestatic StringReturns the error message generated by the last action.static ObjectgetJavaValue(Object val) Convert a JavaScript value to Java value suitable for Jep.static ObjectgetJSValue(Object val) Convert values produced by Jep into values suitable for JavaScript.static intgetNChildren(Node n) Return the number of children of a nodestatic StringgetNodeName(Node n) Returns the name of a variable or function nodestatic Operatorstatic ObjectgetNodeValue(Node n) Returns the value of a constant or variable nodestatic intstatic StringgetOpSymbol(Operator op) static ObjectgetVariableValueO(String name) Gets the value of a variable as an object valuestatic intReturns the type of the node.static voidNative method written in JavaScript.voidStandard GWT method called when module loaded.static NodeParse an expressionstatic NodeParse an expression, does not throw exceptionsstatic VariablesetVariable(String name, Object obj) Set the value of a variable to a object valuestatic VariablesetVariableNE(String name, Object obj) Set the value of a variable to a object valuestatic String
-
Constructor Details
-
GWTExpose
public GWTExpose()
-
-
Method Details
-
onModuleLoad
public void onModuleLoad()Standard GWT method called when module loaded.- Specified by:
onModuleLoadin interfaceEntryPoint
-
parse
Parse an expression- Parameters:
S- expression- Returns:
- root node of parse tree
- Throws:
ParseException- if the string cannot be successfully parsed
-
parseNE
Parse an expression, does not throw exceptions- Parameters:
S- expression- Returns:
- root node of parse tree or null the string cannot be successfully parsed
- Throws:
ParseException
-
evaluateD
public static double evaluateD()Evaluates the last expression returning a double.- Returns:
- either the double result or NaN on EvaluationException
-
evaluateO
Evaluate a node, returning an object- Parameters:
node- expression to evaluate- Returns:
- value or null on EvaluationException
- Throws:
EvaluationException- if an error in evaluation
-
evaluateNE
Evaluate a node, returning an object, does not throw exceptions- Parameters:
node- expression to evaluate- Returns:
- value or null if an error occurred during evaluation
-
setVariableNE
Set the value of a variable to a object value- Parameters:
name- name of variableobj- JavaScript value of the variable- Returns:
- the variable object or null if an attempt to set a constant variable or the value cannot be converted to Java
-
setVariable
Set the value of a variable to a object value- Parameters:
name- name of variableobj- JavaScript value of the variable- Returns:
- the variable object
- Throws:
JepException- if an attempt to set a constant variable or the value cannot be converted to Java
-
getJavaValue
Convert a JavaScript value to Java value suitable for Jep. Most types are parsed directly apart from JsArray arrays which are converted toVectors<Object>the type used by standard Jep.- Parameters:
val- value from JavaScript, must be Number, String, Boolean or array.- Returns:
- converted value or null on error.
- Throws:
EvaluationException
-
getVariableValueO
Gets the value of a variable as an object value- Parameters:
name- variable name- Returns:
- value as an object
-
getJSValue
Convert values produced by Jep into values suitable for JavaScript. Changes Jeps Vector representation for arrays to- Parameters:
val-- Returns:
-
getErrorMsg
Returns the error message generated by the last action.- Returns:
- the error message or "" if no error detected
-
toString
- Throws:
EvaluationException
-
nodeType
Returns the type of the node.- Parameters:
n- node to examine- Returns:
- 2 for operators, 3 for variable, 4 for functions or 5 for constants
-
getNChildren
Return the number of children of a node- Parameters:
n- node to examine- Returns:
- number of children
-
getChild
Gets the child of a node- Parameters:
n- node to examinei- position of child index from zero- Returns:
- the child
-
getNodeName
Returns the name of a variable or function node- Parameters:
n- node to examine- Returns:
- a string
-
getNodeValue
Returns the value of a constant or variable node- Parameters:
n- node to examine- Returns:
- a object representing the value
-
getNodeOperator
-
getOpPrec
-
getOpSymbol
-
buildVarNode
-
buildConstantNode
-
buildBinaryOpNode
-
onModLoad
public static void onModLoad()Native method written in JavaScript. Adds methods to the JavaScriptwindow.jepobject. Methods are- jep.parse(expression)
- jep.evaluateD()
- jep.evluate(node)
- jep.getVariableValue(name)
- jep.setVariableValue(name,val)
- jep.getJavaValue(val)
-
consoleLog
Native method to write to the JavaScript console- Parameters:
msg-
-