/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: VariableStack.java,v 1.2.4.1 2005/09/10 18:16:22 jeffsuttor Exp $
*/
/**
* Defines a class to keep track of a stack for
* template arguments and variables.
*
* <p>This has been changed from the previous incarnations of this
* class to be fairly low level.</p>
* @xsl.usage internal
*/
{
/**
* limitation for 1K
*/
/**
* Constructor for a variable stack.
*/
public VariableStack()
{
reset();
}
/**
* Returns a clone of this variable stack.
*
* @return a clone of this variable stack.
*
* @throws CloneNotSupportedException
*/
{
// I *think* I can get away with a shallow clone here?
return vs;
}
/**
* The stack frame where all variables and params will be kept.
* @serial
*/
/**
* The top of the stack frame (<code>_stackFrames</code>).
* @serial
*/
int _frameTop;
/**
* The bottom index of the current frame (relative to <code>_stackFrames</code>).
* @serial
*/
private int _currentFrameBottom;
/**
* The stack of frame positions. I call 'em links because of distant
* <a href="http://math.millikin.edu/mprogers/Courses/currentCourses/CS481-ComputerArchitecture/cs481.Motorola68000.html">
* Motorola 68000 assembler</a> memories. :-)
* @serial
*/
/**
* The top of the links stack.
*/
int _linksTop;
/**
* Get the element at the given index, regardless of stackframe.
*
* @param i index from zero.
*
* @return The item at the given index.
*/
{
return _stackFrames[i];
}
/**
* Get size of the stack.
*
* @return the total size of the execution stack.
*/
public int size()
{
return _frameTop;
}
/**
* Reset the stack to a start position.
*
* @return the total size of the execution stack.
*/
public void reset()
{
_frameTop = 0;
_linksTop = 0;
// Adding one here to the stack of frame positions will allow us always
// to look one under without having to check if we're at zero.
}
/**
* Set the current stack frame.
*
* @param sf The new stack frame position.
*/
{
}
/**
* 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.
*
* @return The current stack frame position.
*/
public int getStackFrame()
{
return _currentFrameBottom;
}
/**
* Allocates memory (called a stackframe) on the stack; used to store
* local variables and parameter arguments.
*
* <a href="http://math.millikin.edu/mprogers/Courses/currentCourses/CS481-ComputerArchitecture/cs481.Motorola68000.html">
* Motorola 68000 assembler</a> memories.</p>
*
* @param 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.
*
* @return The bottom of the stack frame, from where local variable addressing
* should start from.
*/
{
{
}
{
}
return _currentFrameBottom;
}
/**
* Free up the stack frame that was last allocated with
* {@link #link(int size)}.
*/
public void unlink()
{
}
/**
* Free up the stack frame that was last allocated with
* {@link #link(int size)}.
* @param currentFrame The current frame to set to
* after the unlink.
*/
{
}
/**
* Set a local variable or parameter in the current stack frame.
*
*
* @param index Local variable index relative to the current stack
* frame bottom.
*
* @param val The value of the variable that is being set.
*/
{
}
/**
* Set a local variable or parameter in the specified stack frame.
*
*
* @param index Local variable index relative to the current stack
* frame bottom.
* NEEDSDOC @param stackFrame
*
* @param val The value of the variable that is being set.
*/
{
}
/**
* Get a local variable or parameter in the current stack frame.
*
*
* @param xctxt The XPath context, which must be passed in order to
* lazy evaluate variables.
*
* @param index Local variable index relative to the current stack
* frame bottom.
*
* @return The value of the variable.
*
* @throws TransformerException
*/
throws TransformerException
{
throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null),
xctxt.getSAXLocator());
// "Variable accessed before it is bound!", xctxt.getSAXLocator());
// Lazy execution of variables.
return val;
}
/**
* Get a local variable or parameter in the current stack frame.
*
*
* @param index Local variable index relative to the given
* frame bottom.
* NEEDSDOC @param frame
*
* @return The value of the variable.
*
* @throws TransformerException
*/
throws TransformerException
{
return val;
}
/**
* Get a local variable or parameter in the current stack frame.
*
*
* @param xctxt The XPath context, which must be passed in order to
* lazy evaluate variables.
*
* @param index Local variable index relative to the current stack
* frame bottom.
*
* @return The value of the variable.
*
* @throws TransformerException
*/
throws TransformerException
{
throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null),
xctxt.getSAXLocator());
// "Variable accessed before it is bound!", xctxt.getSAXLocator());
// Lazy execution of variables.
}
/**
* Tell if a local variable has been set or not.
*
* @param index Local variable index relative to the current stack
* frame bottom.
*
* @return true if the value at the index is not null.
*
* @throws TransformerException
*/
{
}
/** NEEDSDOC Field m_nulls */
/**
* 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.
*
* @param start The start position, relative to the current local stack frame.
* @param len The number of slots to be cleared.
*/
{
}
/**
* Set a global variable or parameter in the global stack frame.
*
*
* @param index Local variable index relative to the global stack frame
* bottom.
*
* @param val The value of the variable that is being set.
*/
{
}
/**
* Get a global variable or parameter from the global stack frame.
*
*
* @param xctxt The XPath context, which must be passed in order to
* lazy evaluate variables.
*
* @param index Global variable index relative to the global stack
* frame bottom.
*
* @return The value of the variable.
*
* @throws TransformerException
*/
throws TransformerException
{
// Lazy execution of variables.
return val;
}
/**
* Get a global variable or parameter from the global stack frame.
*
*
* @param xctxt The XPath context, which must be passed in order to
* lazy evaluate variables.
*
* @param index Global variable index relative to the global stack
* frame bottom.
*
* @return The value of the variable.
*
* @throws TransformerException
*/
throws TransformerException
{
// Lazy execution of variables.
}
/**
* Get a variable based on it's qualified name.
* This is for external use only.
*
* @param xctxt The XPath context, which must be passed in order to
* lazy evaluate variables.
*
* @param qname The qualified name of the variable.
*
* @return The evaluated value of the variable.
*
* @throws javax.xml.transform.TransformerException
*/
{
// J2SE does not support Xalan interpretive
/*
com.sun.org.apache.xml.internal.utils.PrefixResolver prefixResolver =
xctxt.getNamespaceContext();
// Get the current ElemTemplateElement, which must be pushed in as the
// prefix resolver, and then walk backwards in document order, searching
// for an xsl:param element or xsl:variable element that matches our
// qname. If we reach the top level, use the StylesheetRoot's composed
// list of top level variables and parameters.
if (prefixResolver instanceof com.sun.org.apache.xalan.internal.templates.ElemTemplateElement)
{
com.sun.org.apache.xalan.internal.templates.ElemVariable vvar;
com.sun.org.apache.xalan.internal.templates.ElemTemplateElement prev =
(com.sun.org.apache.xalan.internal.templates.ElemTemplateElement) prefixResolver;
if (!(prev instanceof com.sun.org.apache.xalan.internal.templates.Stylesheet))
{
while ( !(prev.getParentNode() instanceof com.sun.org.apache.xalan.internal.templates.Stylesheet) )
{
com.sun.org.apache.xalan.internal.templates.ElemTemplateElement savedprev = prev;
while (null != (prev = prev.getPreviousSiblingElem()))
{
if (prev instanceof com.sun.org.apache.xalan.internal.templates.ElemVariable)
{
vvar = (com.sun.org.apache.xalan.internal.templates.ElemVariable) prev;
if (vvar.getName().equals(qname))
return getLocalVariable(xctxt, vvar.getIndex());
}
}
prev = savedprev.getParentElem();
}
}
vvar = prev.getStylesheetRoot().getVariableOrParamComposed(qname);
if (null != vvar)
return getGlobalVariable(xctxt, vvar.getIndex());
}
*/
throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VAR_NOT_RESOLVABLE, new Object[]{qname.toString()})); //"Variable not resolvable: " + qname);
}
} // end VariableStack