Tea Java Runtime API
Version 3.1.0

com.pdmfc.tea.runtime
Class SContext

java.lang.Object
  |
  +--com.pdmfc.tea.runtime.SContext
Direct Known Subclasses:
STeaRuntime

public class SContext
extends java.lang.Object

Represents a context inside which variables are created and commands executed. Contexts form an hierarchy, where child contexts hide variables defined in parent contexts. A context with no parent is a top level context.


Constructor Summary
protected SContext()
          Initializes a top level context.
  SContext(int initialCapacity)
          Initializes a top level context with a particular initial capacity.
protected SContext(SContext parent)
          Initializes a context descending from parent.
 
Method Summary
protected  void clearAll()
          Forgets all the variables.
 SContext clone(SContext parent)
           
 java.lang.Object getVar(SObjSymbol name)
          Obtains the contents of the variable associated with symbol name.
 SObjVar getVarObject(SObjSymbol name)
          Obtains the contents of the variable associated with symbol name.
 boolean isDefined(SObjSymbol name)
          Checks if a given variable is defined in this context.
 SContext newChild()
           
 SObjVar newVar(SObjSymbol name, java.lang.Object value)
          Creates a new variable inside this context.
 SObjVar newVar(java.lang.String name, java.lang.Object value)
          Creates a new variable inside this context.
 void setVar(SObjSymbol name, java.lang.Object value)
          Sets the contents of a variable previously created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SContext

protected SContext()
Initializes a top level context.

SContext

protected SContext(SContext parent)
Initializes a context descending from parent. Variables defined inside this context hide variables with the same name inside context. If parent is null then this will be a top-level context.
Parameters:
parent - The parent context of this one. It may be null.

SContext

public SContext(int initialCapacity)
Initializes a top level context with a particular initial capacity.
Method Detail

newChild

public SContext newChild()

clone

public SContext clone(SContext parent)

clearAll

protected void clearAll()
Forgets all the variables.

newVar

public final SObjVar newVar(java.lang.String name,
                            java.lang.Object value)
Creates a new variable inside this context. The variable will be associated with a symbol named name and it will have has contents the object referenced by value.
Parameters:
name - The name of the symbol to be associated to the variable being created.
value - Reference to the object to be stored inside the variable.

isDefined

public final boolean isDefined(SObjSymbol name)
Checks if a given variable is defined in this context. The variable is also searched in all parent contexts.
Parameters:
name - The symbol associated with the variable being checked for existence.
Returns:
True if the variable is defined in this context or in some of its parent contexts. False otherwise.

newVar

public final SObjVar newVar(SObjSymbol name,
                            java.lang.Object value)
Creates a new variable inside this context. The variable will be associated with symbol name and it will have has contents the object referenced by value.
Parameters:
name - Symbol to be associated to the variable being created.

setVar

public final void setVar(SObjSymbol name,
                         java.lang.Object value)
                  throws SNoSuchVarException
Sets the contents of a variable previously created. After this method returns variable name will have as contents a reference to object value.
Parameters:
name - Symbol associated with the variable to be set.
value - Object to store in the variable.
Throws:
SNoSuchVarException - Throw if no variable name was previously created.

getVar

public final java.lang.Object getVar(SObjSymbol name)
                              throws SNoSuchVarException
Obtains the contents of the variable associated with symbol name. If such a variable does not exist in this context then it is searched in its parent.
Parameters:
name - Symbol associated with the variable whose contents are to be retrieved.
Returns:
The object in the variable associated with symbol name.
Throws:
SNoSuchVarException - Thrown if the variable does not exist neither in this context nor in any of the contexts up the hierarchy.

getVarObject

public final SObjVar getVarObject(SObjSymbol name)
                           throws SNoSuchVarException
Obtains the contents of the variable associated with symbol name. If such a variable does not exist in this context then it is searched in its parent.
Parameters:
name - Symbol associated with the variable whose contents are to be retrieved.
Returns:
The object in the variable associated with symbol name.
Throws:
SNoSuchVarException - Thrown if the variable does not exist neither in this context nor in any of the contexts up the hierarchy.

Tea Java Runtime API
Version 3.1.0

© 2002 PDM&FC, All Rights Reserved.