Class Compiler

java.lang.Object
cl.obcom.desktopfx.expr.Compiler

public final class Compiler extends Object

Expression compiler. The compiler recognizes the following grammar:

expression conditional-or  
  | conditional-or ? expression : expression if-then-else (lazy)
conditional-or conditional-and  
  | conditional-or || conditional-and conditional or (lazy)
conditional-and equality  
  | conditional-and && equality conditional and (lazy)
equality relational  
  | relational == relational equal to
  | relational != relational not equal to
relational additive  
  | additive < additive less than
  | additive <= additive less than or equal to
  | additive > additive greater than
  | additive >= additive greater than or equal to
additive multiplicative  
  | additive + multiplicative concatenation or addition
  | additive - multiplicative substraction
multiplicative unary  
  | multiplicative * unary multiplication
  | multiplicative / unary division
  | multiplicative % unary remainder
unary primary  
  | ! unary logical not
  | - unary negative
  | + unary positive
primary ( expression )  
  | function  
  | string  
  | number  
function identifier ( arguments )  
  | identifier ( )  
  | identifier  
arguments expression [ , expression ]*  
identifier name [ . name ]* package notation
name [A-Za-z$_][A-Za-z0-9$_]* case sensitive
string " [ any-character-with \" for " ]* " double quotes
  | '  [ any-character-with \' for  '  ]*  ' single quote
number digits [ . digits ]? BigDecimal

The following built-in functions are available:

  • capacity(expr): the value of the user capacity expr.
  • evaluate(expr): evaluates the string expression expr.
  • hasCapacity(expr): true if the user has capacity expr.
  • hasPrivilege(expr): true if the user has privilege expr.
  • matches(expr, regex): true if expr matches the pattern regex.
  • systemProp(expr): the value of the system property expr.

The following built-in properties are available:

  • anonUser: true if login type is ANONYMOUS.
  • envName: the name of the server environment.
  • kioskUser: true if login type is KIOSK.
  • menuName: the name of the menu of the user.
  • normalUser: true if login type is NORMAL.
  • officeType: the type of the office the user.
  • stationName: the name of the workstation.
  • userName: the name of the user.
  • userType: the type of the profile of the user.

The following built-in constants are available:

  • null: the null object reference.
  • true: the boolean value true.
  • false: the boolean value false.
See Also:
  • Constructor Details

    • Compiler

      public Compiler(Desktop desktop, Object defaultLogic)
      Constructs a new Compiler instance.
      Parameters:
      desktop - the Desktop Application.
      defaultLogic - an object with default user logic.
      Throws:
      NullPointerException - if an argument is null.
  • Method Details

    • getDefaultLogic

      public Object getDefaultLogic()
      Returns an object with the default user-supplied logic.
      Returns:
      an object with the default user-supplied logic.
    • getQuotientScale

      public int getQuotientScale()
      Returns the scale of quotients. By default the scale is 20.
      Returns:
      the scale of quotients.
    • setQuotientScale

      public void setQuotientScale(int scale)
      Changes the scale of quotients. By default the scale is 20.
      Parameters:
      scale - the new scale of quotients.
    • addFunction

      public Function addFunction(Function function)
      Adds a function to the list of functions of the compiler.
      Parameters:
      function - the function to added to the list.
      Returns:
      the function previously indexed by the same name.
      Throws:
      NullPointerException - if function is null.
    • removeFunction

      public Function removeFunction(Function function)
      Removes a function from the list of functions of the compiler.
      Parameters:
      function - the function to be remove from the list.
      Returns:
      the function associatted with the function name.
      Throws:
      NullPointerException - if function is null.
    • compile

      public Expression compile(String expr)
      Compiles the supplied expression string.
      Parameters:
      expr - the string expression to compiled.
      Returns:
      the resulting compiled Expression.
      Throws:
      NullPointerException - if expr is null.
      ExpressionException - if the expression is invalid.
    • toString

      public static String toString(Object value)
      Converts an object value to a String value.
      Parameters:
      value - the value to convert to a String (can be null).
      Returns:
      a String or null if value is null.
    • toBoolean

      public static Boolean toBoolean(Object value)
      Converts an object value to a Boolean value.
      Parameters:
      value - the value to convert to a Boolean (can be null).
      Returns:
      a Boolean or null if value is null.
    • toNumber

      public static BigDecimal toNumber(Object value)
      Converts an object value to a BigDecimal number.
      Parameters:
      value - the value to convert to a BigDecimal (can be null).
      Returns:
      a BigDecimal or null if value is null.
      Throws:
      NumberFormatException - if value is invalid.
    • compare

      public static int compare(Object lvalue, Object rvalue)
      Compares two object values and returns -1, 0, or 1 if the left value is less than, equal to, or greater than the right value.
      Parameters:
      lvalue - the left value of the comparison.
      rvalue - the right value of the comparison.
      Returns:
      -1, 0, or 1 if lvalue is less than, equal to, or greater than rvalue.
      Throws:
      NullPointerException - if an argument is null.