Class GWTExpose

java.lang.Object
com.singularsys.client.GWTExpose
All Implemented Interfaces:
EntryPoint

public class GWTExpose extends Object implements 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 expression
  • window.jep.evaluateD() evaluate the last expression parsed
  • window.jep.evaluate(node) evaluate a node
  • window.jep.getVariableValue(name) return the value of a Jep variable
  • window.jep.setVariable(name,val) set the value of a Jep variable
  • window.jep.getErrMsg() return the last error message
  • window.jep.nodeType(node) finds the type of a given node
  • window.jep.getNChildren(node) return the number of childerne of a node
  • window.jep.getChild(node,i) find the i-th child of a node
  • window.jep.getOperator(node) find the operator associated with a node
  • window.jep.getNodeName(node) find the name of associated with a node, either a variable name or function name
  • window.jep.getNodeValue(node) finds the value of a node, either a constant value of a variable value
  • window.jep.getOpPrec(op) find the precedence of an operator
  • window.jep.getOpSymbol(op) find the symbol of an operator
  • window.jep.nf.buildVarNode(name) build a node representing a variable
  • window.jep.nf.buildConstantNode(val) build a node with a constant value
  • window.jep.nf.buildBinaryOpNode(op,l,r) build a node with two arguments
Author:
rich
See Also:
  • Constructor Details

    • GWTExpose

      public GWTExpose()
  • Method Details

    • onModuleLoad

      public void onModuleLoad()
      Standard GWT method called when module loaded.
      Specified by:
      onModuleLoad in interface EntryPoint
    • parse

      public static Node parse(String S) throws ParseException
      Parse an expression
      Parameters:
      S - expression
      Returns:
      root node of parse tree
      Throws:
      ParseException - if the string cannot be successfully parsed
    • parseNE

      public static Node parseNE(String S) throws ParseException
      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

      public static Object evaluateO(Node node) throws EvaluationException
      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

      public static Object evaluateNE(Node node)
      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

      public static Variable setVariableNE(String name, Object obj)
      Set the value of a variable to a object value
      Parameters:
      name - name of variable
      obj - 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

      public static Variable setVariable(String name, Object obj) throws JepException
      Set the value of a variable to a object value
      Parameters:
      name - name of variable
      obj - 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

      public static Object getJavaValue(Object val) throws EvaluationException
      Convert a JavaScript value to Java value suitable for Jep. Most types are parsed directly apart from JsArray arrays which are converted to Vectors<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

      public static Object getVariableValueO(String name)
      Gets the value of a variable as an object value
      Parameters:
      name - variable name
      Returns:
      value as an object
    • getJSValue

      public static Object getJSValue(Object val)
      Convert values produced by Jep into values suitable for JavaScript. Changes Jeps Vector representation for arrays to
      Parameters:
      val -
      Returns:
    • getErrorMsg

      public static String getErrorMsg()
      Returns the error message generated by the last action.
      Returns:
      the error message or "" if no error detected
    • toString

      public static String toString(Node node) throws EvaluationException
      Throws:
      EvaluationException
    • nodeType

      public static int nodeType(Node n)
      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

      public static int getNChildren(Node n)
      Return the number of children of a node
      Parameters:
      n - node to examine
      Returns:
      number of children
    • getChild

      public static Node getChild(Node n, int i)
      Gets the child of a node
      Parameters:
      n - node to examine
      i - position of child index from zero
      Returns:
      the child
    • getNodeName

      public static String getNodeName(Node n)
      Returns the name of a variable or function node
      Parameters:
      n - node to examine
      Returns:
      a string
    • getNodeValue

      public static Object getNodeValue(Node n)
      Returns the value of a constant or variable node
      Parameters:
      n - node to examine
      Returns:
      a object representing the value
    • getNodeOperator

      public static Operator getNodeOperator(Node n)
    • getOpPrec

      public static int getOpPrec(Operator op)
    • getOpSymbol

      public static String getOpSymbol(Operator op)
    • buildVarNode

      public static Node buildVarNode(String n)
    • buildConstantNode

      public static Node buildConstantNode(Object val)
    • buildBinaryOpNode

      public static Node buildBinaryOpNode(Operator op, Node l, Node r)
    • onModLoad

      public static void onModLoad()
      Native method written in JavaScript. Adds methods to the JavaScript window.jep object. Methods are
      • jep.parse(expression)
      • jep.evaluateD()
      • jep.evluate(node)
      • jep.getVariableValue(name)
      • jep.setVariableValue(name,val)
      • jep.getJavaValue(val)
    • consoleLog

      public static void consoleLog(String msg)
      Native method to write to the JavaScript console
      Parameters:
      msg -