Package org.apache.xpath
Class VariableStack
java.lang.Object
org.apache.xpath.VariableStack
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
JAXPVariableStack
public class VariableStack extends Object implements Cloneable
Defines a class to keep track of a stack for
template arguments and variables.
This has been changed from the previous incarnations of this class to be fairly low level.
-
Field Summary
Fields Modifier and Type Field Description static intCLEARLIMITATIONlimitation for 1K -
Constructor Summary
Constructors Constructor Description VariableStack()Constructor for a variable stack.VariableStack(int initStackSize)Constructor for a variable stack. -
Method Summary
Modifier and Type Method Description voidclearLocalSlots(int start, int len)Use this to clear the variables in a section of the stack.Objectclone()Returns a clone of this variable stack.XObjectelementAt(int i)Get the element at the given index, regardless of stackframe.XObjectgetGlobalVariable(XPathContext xctxt, int index)Get a global variable or parameter from the global stack frame.XObjectgetGlobalVariable(XPathContext xctxt, int index, boolean destructiveOK)Get a global variable or parameter from the global stack frame.XObjectgetLocalVariable(int index, int frame)Get a local variable or parameter in the current stack frame.XObjectgetLocalVariable(XPathContext xctxt, int index)Get a local variable or parameter in the current stack frame.XObjectgetLocalVariable(XPathContext xctxt, int index, boolean destructiveOK)Get a local variable or parameter in the current stack frame.intgetStackFrame()Get the position from where the search should start, which is either the searchStart property, or the top of the stack if that value is -1.XObjectgetVariableOrParam(XPathContext xctxt, QName qname)Get a variable based on it's qualified name.booleanisLocalSet(int index)Tell if a local variable has been set or not.intlink(int size)Allocates memory (called a stackframe) on the stack; used to store local variables and parameter arguments.voidreset()Reset the stack to a start position.protected voidreset(int linksSize, int varArraySize)Reset the stack to a start position.voidsetGlobalVariable(int index, XObject val)Set a global variable or parameter in the global stack frame.voidsetLocalVariable(int index, XObject val)Set a local variable or parameter in the current stack frame.voidsetLocalVariable(int index, XObject val, int stackFrame)Set a local variable or parameter in the specified stack frame.voidsetStackFrame(int sf)Set the current stack frame.intsize()Get size of the stack.voidunlink()Free up the stack frame that was last allocated withlink(int size).voidunlink(int currentFrame)Free up the stack frame that was last allocated withlink(int size).
-
Field Details
-
CLEARLIMITATION
public static final int CLEARLIMITATIONlimitation for 1K- See Also:
- Constant Field Values
-
-
Constructor Details
-
VariableStack
public VariableStack()Constructor for a variable stack. -
VariableStack
public VariableStack(int initStackSize)Constructor for a variable stack.- Parameters:
initStackSize- The initial stack size. Must be at least one. The stack can grow if needed.
-
-
Method Details
-
clone
Returns a clone of this variable stack.- Overrides:
clonein classObject- Returns:
- a clone of this variable stack.
- Throws:
CloneNotSupportedException
-
elementAt
Get the element at the given index, regardless of stackframe.- Parameters:
i- index from zero.- Returns:
- The item at the given index.
-
size
public int size()Get size of the stack.- Returns:
- the total size of the execution stack.
-
reset
public void reset()Reset the stack to a start position. -
reset
protected void reset(int linksSize, int varArraySize)Reset the stack to a start position.- Parameters:
linksSize- Initial stack size to usevarArraySize- Initial variable array size to use
-
setStackFrame
public void setStackFrame(int sf)Set the current stack frame.- Parameters:
sf- The new stack frame position.
-
getStackFrame
public int getStackFrame()Get the position from where the search should start, which is either the searchStart property, or the top of the stack if that value is -1.- Returns:
- The current stack frame position.
-
link
public int link(int size)Allocates memory (called a stackframe) on the stack; used to store local variables and parameter arguments.I use the link/unlink concept because of distant Motorola 68000 assembler memories.
- Parameters:
size- The size of the stack frame allocation. This ammount should normally be the maximum number of variables that you can have allocated at one time in the new stack frame.- Returns:
- The bottom of the stack frame, from where local variable addressing should start from.
-
unlink
public void unlink()Free up the stack frame that was last allocated withlink(int size). -
unlink
public void unlink(int currentFrame)Free up the stack frame that was last allocated withlink(int size).- Parameters:
currentFrame- The current frame to set to after the unlink.
-
setLocalVariable
Set a local variable or parameter in the current stack frame.- Parameters:
index- Local variable index relative to the current stack frame bottom.val- The value of the variable that is being set.
-
setLocalVariable
Set a local variable or parameter in the specified stack frame.- Parameters:
index- Local variable index relative to the current stack frame bottom. NEEDSDOC @param stackFrameval- The value of the variable that is being set.
-
getLocalVariable
Get a local variable or parameter in the current stack frame.- Parameters:
xctxt- The XPath context, which must be passed in order to lazy evaluate variables.index- Local variable index relative to the current stack frame bottom.- Returns:
- The value of the variable.
- Throws:
TransformerException
-
getLocalVariable
Get a local variable or parameter in the current stack frame.- Parameters:
index- Local variable index relative to the given frame bottom. NEEDSDOC @param frame- Returns:
- The value of the variable.
- Throws:
TransformerException
-
getLocalVariable
public XObject getLocalVariable(XPathContext xctxt, int index, boolean destructiveOK) throws TransformerExceptionGet a local variable or parameter in the current stack frame.- Parameters:
xctxt- The XPath context, which must be passed in order to lazy evaluate variables.index- Local variable index relative to the current stack frame bottom.- Returns:
- The value of the variable.
- Throws:
TransformerException
-
isLocalSet
Tell if a local variable has been set or not.- Parameters:
index- Local variable index relative to the current stack frame bottom.- Returns:
- true if the value at the index is not null.
- Throws:
TransformerException
-
clearLocalSlots
public void clearLocalSlots(int start, int len)Use this to clear the variables in a section of the stack. This is used to clear the parameter section of the stack, so that default param values can tell if they've already been set. It is important to note that this function has a 1K limitation.- Parameters:
start- The start position, relative to the current local stack frame.len- The number of slots to be cleared.
-
setGlobalVariable
Set a global variable or parameter in the global stack frame.- Parameters:
index- Local variable index relative to the global stack frame bottom.val- The value of the variable that is being set.
-
getGlobalVariable
Get a global variable or parameter from the global stack frame.- Parameters:
xctxt- The XPath context, which must be passed in order to lazy evaluate variables.index- Global variable index relative to the global stack frame bottom.- Returns:
- The value of the variable.
- Throws:
TransformerException
-
getGlobalVariable
public XObject getGlobalVariable(XPathContext xctxt, int index, boolean destructiveOK) throws TransformerExceptionGet a global variable or parameter from the global stack frame.- Parameters:
xctxt- The XPath context, which must be passed in order to lazy evaluate variables.index- Global variable index relative to the global stack frame bottom.- Returns:
- The value of the variable.
- Throws:
TransformerException
-
getVariableOrParam
Get a variable based on it's qualified name. This is for external use only.- Parameters:
xctxt- The XPath context, which must be passed in order to lazy evaluate variables.qname- The qualified name of the variable.- Returns:
- The evaluated value of the variable.
- Throws:
TransformerException
-