vxmlsurfer
Class Variables

java.lang.Object
  extended by vxmlsurfer.Variables

public class Variables
extends java.lang.Object

This class maintains the varibles scope list. Scope object implemented as Scriptable object in Rhino.

Author:
First Author Padmini Patnaik, Second Author Elton Pereira

Field Summary
static java.lang.String NOTEXIST
          Used to indicate that a variable does not exist.
static java.util.Stack<org.mozilla.javascript.Scriptable> scopes
           
static java.lang.String UNDEFINED
          Used to indicate that a variable exists but a value hasen't been assigned.
 
Constructor Summary
Variables()
           
 
Method Summary
static void assignVar(java.lang.String var, java.lang.String expr)
          Takes var and value, resolves them in their appropriate scopes, and makes the assignment.
static void clear()
          Clears all variables reachable from the current scope.
static void clear(java.lang.String[] arr)
          Clears the specified variables.
static void clearStack()
          Empties the stack of scopes.
static void defineVar(java.lang.String var)
          Defines a variable and initializes it to UNDEFINED.
static void defineVar(java.lang.String var, java.lang.String expr)
          Defines a variable and assigns it the resultant value.
static java.lang.String evaluateExpr(java.lang.String expr)
          Used to evaluate an expression.
static org.mozilla.javascript.Scriptable getCurrentScope()
          Returns the current scope.
(package private) static org.mozilla.javascript.Scriptable getVarScope(java.lang.String val)
          Used to get the scope in which the variable is defined.
static java.lang.Object getVarVal(java.lang.String var)
          Used to get the value of a variable.
static boolean isDefined(java.lang.String var)
          Checks if the variable is defined or not.
static boolean isNull(java.lang.String var)
          Checks if the variable has been assigned a value or not.
static void newNamedVarScope(java.lang.String var)
          Creates a new named variable scope.
static void newVarScope()
          Creates a new unnamed variable scope.
static void popScope()
          Gets the top-most scope from the scope stack and assigns it as the current scope.
static void pushScope()
          Pushes the current scope into a stack and reassigns current scope to the session scope.
static void putVar(java.lang.String var, java.lang.Object val)
          Used to explicitly put a variable-value pain in the current scope.
static void removeVarScope()
          Destroys the current variable scope and sets the current variable scope to the parent of the variable scope just destroyed.
static java.lang.String resolveExpr(java.lang.String expr)
          Used to resolve variables.
static void setScopeName(java.lang.String name)
          Gives a name to the current scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scopes

public static java.util.Stack<org.mozilla.javascript.Scriptable> scopes

UNDEFINED

public static java.lang.String UNDEFINED
Used to indicate that a variable exists but a value hasen't been assigned.


NOTEXIST

public static java.lang.String NOTEXIST
Used to indicate that a variable does not exist.

Constructor Detail

Variables

public Variables()
Method Detail

newVarScope

public static void newVarScope()
Creates a new unnamed variable scope.


newNamedVarScope

public static void newNamedVarScope(java.lang.String var)
Creates a new named variable scope. Variables created in this scope can be refered to as .

Parameters:
var - name of scope

setScopeName

public static void setScopeName(java.lang.String name)
Gives a name to the current scope. Variables created in this scope can now be refered to as .

Parameters:
var - name of scope

removeVarScope

public static void removeVarScope()
Destroys the current variable scope and sets the current variable scope to the parent of the variable scope just destroyed.


defineVar

public static void defineVar(java.lang.String var,
                             java.lang.String expr)
Defines a variable and assigns it the resultant value. "." is disallowed in var definition.

Parameters:
var - name of the variable
expr - will be evaluated and its value will be assigned to var

defineVar

public static void defineVar(java.lang.String var)
Defines a variable and initializes it to UNDEFINED. "." is disallowed in var definition

Parameters:
var - variable name

getVarVal

public static java.lang.Object getVarVal(java.lang.String var)
Used to get the value of a variable.

Parameters:
var - variable name
Returns:
Object the value of the variable. Should be appropriately casted.

getVarScope

static org.mozilla.javascript.Scriptable getVarScope(java.lang.String val)
Used to get the scope in which the variable is defined. This method will be removed soon since we want to hide Rhino totally.

Parameters:
var - name of variable
Returns:
Scriptable the scope of the variable

evaluateExpr

public static java.lang.String evaluateExpr(java.lang.String expr)
Used to evaluate an expression. It evalutes the expression in the current scope.

Parameters:
expr - expression to be evaluated
Returns:
String the result

resolveExpr

public static java.lang.String resolveExpr(java.lang.String expr)
Used to resolve variables. It handles variable names of the type ..

Parameters:
expr - expression to be evaluated
Returns:
String

assignVar

public static void assignVar(java.lang.String var,
                             java.lang.String expr)
Takes var and value, resolves them in their appropriate scopes, and makes the assignment.

Parameters:
var - variable name. May be of the form ..
expr - value expression. Use '' to indicate a string literal. May use variables here. Can assign numeric literals too.

putVar

public static void putVar(java.lang.String var,
                          java.lang.Object val)
Used to explicitly put a variable-value pain in the current scope. Note that this pair can only be accesed in this scope; nesting of scopes doesn't work here.

Parameters:
var - variable name
val - value

isDefined

public static boolean isDefined(java.lang.String var)
Checks if the variable is defined or not.

Parameters:
var - variable
Returns:
boolean true if defined

isNull

public static boolean isNull(java.lang.String var)
Checks if the variable has been assigned a value or not.

Parameters:
var - variable
Returns:
boolean true if null

clear

public static void clear()
Clears all variables reachable from the current scope.


clear

public static void clear(java.lang.String[] arr)
Clears the specified variables.

Parameters:
arr - list of variables to be cleared.

pushScope

public static void pushScope()
Pushes the current scope into a stack and reassigns current scope to the session scope. Its used for subdialog handlng.


popScope

public static void popScope()
Gets the top-most scope from the scope stack and assigns it as the current scope.


clearStack

public static void clearStack()
Empties the stack of scopes.


getCurrentScope

public static org.mozilla.javascript.Scriptable getCurrentScope()
Returns the current scope. Note this method will be removed since we want to totally hide Rhino.

Returns:
Scriptable