net.sourceforge.templat.parser.context
Class ContextStack

java.lang.Object
  extended by net.sourceforge.templat.parser.context.ContextStack

public class ContextStack
extends Object

A stack of TemplateParserContexts. At any one given moment, a ContextStack can be used by the parser to determine the value of a given variable. The contexts will be searched from inner-most (at the top of the stack) to outer-most (at the bottom of the stack).

Author:
Chris Mosher

Constructor Summary
ContextStack()
           
 
Method Summary
 boolean contains(String varName)
          Checks if this stack contains the given variable.
 TemplateParserContext current()
          Gets the current (inner-most) context (that is, the one at the top of this stack).
 Object getValue(String varName)
          Gets the value of the given variable from this stack.
 boolean isEverEqual(String varName, Object test)
          Checks if the given variable is equal to the given value in any of this stack's contexts.
 void pop()
          Pops the context off the top of this stack.
 void push(TemplateParserContext ctx)
          Pushes the given context onto the top of this stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextStack

public ContextStack()
Method Detail

push

public void push(TemplateParserContext ctx)
Pushes the given context onto the top of this stack.

Parameters:
ctx - the context to push

pop

public void pop()
Pops the context off the top of this stack.


getValue

public Object getValue(String varName)
                throws TemplateParsingException
Gets the value of the given variable from this stack. The contexts in this stack are searched from inner-most (at the top of the stack) to outer-most (at the bottom of the stack). The first context that contains the given variable is used, and the value of the variable in that context is returned.

Parameters:
varName - variable to look up
Returns:
the value of the variable
Throws:
TemplateParsingException - if the variable is not found

contains

public boolean contains(String varName)
Checks if this stack contains the given variable.

Parameters:
varName - the variable to search for
Returns:
true if any context in this stack contains the variable.

current

public TemplateParserContext current()
Gets the current (inner-most) context (that is, the one at the top of this stack).

Returns:
the inner-most context

isEverEqual

public boolean isEverEqual(String varName,
                           Object test)
                    throws TemplateParsingException
Checks if the given variable is equal to the given value in any of this stack's contexts.

Parameters:
varName - the variable to search for
test - value to check for the variable being equal to
Returns:
true if the variable is found, and contains the given value
Throws:
TemplateParsingException