com.metamatrix.query.sql.util
Class VariableContext

java.lang.Object
  extended by com.metamatrix.query.sql.util.VariableContext

public class VariableContext
extends java.lang.Object

This class holds a map of variables to their values, these variables and their values are held in the context of a Block in the procedure language, differrent Statements populate the map by declaring variables and assigning values. This class holds reference to a parent VariableContext that holds variable info for parent Block. The variable declared at the parent level is available to its immediate child context and any children, down the heirarchy.


Constructor Summary
VariableContext()
          Constructor for VariableContext.
VariableContext(java.util.Map variableMap)
          Constructor for VariableContext.
 
Method Summary
 boolean containsVariable(ElementSymbol variable)
          Check if this context or any of it's parent contexts contain this variable
 void getFlattenedContextMap(java.util.Map values)
          Helper Methods
 VariableContext getParentContext()
          Get the parent context for this variable context.
 java.lang.Object getValue(ElementSymbol variable)
          Get the value for the given variable, if the variable exits in the current context just return the value of the variable else lookup the parent context and return the value of the variable.
 boolean isEmpty()
          Check if the current context and its parents contain any variables
 void setParentContext(VariableContext parent)
          Set the parent variable context for this variable context, when looking up the variable's value, if the variable is not present in the current context, the parent context is lookedup.
 void setValue(ElementSymbol variable, java.lang.Object value)
          Set the value for the given, if the variable aready exits replaces its value with the given value else adds a new variable to the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableContext

public VariableContext()
Constructor for VariableContext.


VariableContext

public VariableContext(java.util.Map variableMap)
Constructor for VariableContext.

Method Detail

setValue

public void setValue(ElementSymbol variable,
                     java.lang.Object value)
Set the value for the given, if the variable aready exits replaces its value with the given value else adds a new variable to the map.

Parameters:
variable - The ElementSymbol to be added as a variable.
value - The value to be set for the given variable.

getValue

public java.lang.Object getValue(ElementSymbol variable)
Get the value for the given variable, if the variable exits in the current context just return the value of the variable else lookup the parent context and return the value of the variable.

Parameters:
variable - The ElementSymbol whose value needs to be returned.
Returns:
The value of the given variable

setParentContext

public void setParentContext(VariableContext parent)
Set the parent variable context for this variable context, when looking up the variable's value, if the variable is not present in the current context, the parent context is lookedup.

Parameters:
parent - The parent VariableContext.

getParentContext

public VariableContext getParentContext()
Get the parent context for this variable context. When looking up the variable's value, if the variable is not present in the current context, the parent context is lookedup.

Returns:
The parent VariableContext.

getFlattenedContextMap

public void getFlattenedContextMap(java.util.Map values)
Helper Methods


containsVariable

public boolean containsVariable(ElementSymbol variable)
Check if this context or any of it's parent contexts contain this variable

Parameters:
variable - The variable which may be present on this context
Returns:
A boolean value indiating if the given variable is present on this context or any of it's parent contexts.

isEmpty

public boolean isEmpty()
Check if the current context and its parents contain any variables

Returns:
A boolean bollean value indicating if this context is empty


Copyright © 2009. All Rights Reserved.