com.caucho.xpath
Class Env

java.lang.Object
  extended by com.caucho.xpath.Env
All Implemented Interfaces:
ExprEnvironment

public class Env
extends java.lang.Object
implements ExprEnvironment

Global and local variable environment. The April XSLT draft introduces global and local variables. The Env class contains those bindings.

Because this class exists only to support XSL, it makes a number of assumptions that would be invalid for a typical API. Specifically, the variable names must be interned strings, i.e. variable matching uses '==', not equals.

Local variables are handled like a stack. They are pushed and popped as necessary. The top variables shadow bottom variables.

In other words, although the API somewhat resembles a HashMap, it can't be used as a generic hash map.


Constructor Summary
Env()
           
 
Method Summary
 void addFunction(java.lang.String name, java.lang.Object fun)
          Adds and extension function
 int addVar(java.lang.String name, java.lang.Object value)
          Adds the value associated with name.
 int addVar(java.lang.String name, Var value)
          Adds the value associated with name.
 void clear()
          Clears all values in the local environment.
 void free()
           
 java.lang.Object getCache(java.lang.Object key)
           
 org.w3c.dom.Node getContextNode()
          Gets the context node.
 int getContextPosition()
          Returns the position of the context node.
 int getContextSize()
          Returns the number of nodes in the context list.
 org.w3c.dom.Node getCurrentNode()
          Gets the current node.
 ExprEnvironment getExprEnv()
           
 XPathFun getFunction(java.lang.String name)
          Returns the named function.
 org.w3c.dom.Document getOwnerDocument()
          Returns a document for creating nodes.
 int getPositionIndex()
           
 AbstractPattern getSelect()
           
 StylesheetEnv getStylesheetEnv()
          Returns the StylesheetEnv
 int getTop()
          Returns the top of the stack.
 int getUseCount()
           
 Var getVar(java.lang.String name)
          Returns the value associated with name.
 VarEnv getVarEnv()
          Returns the variable environment.
 int getVarSize()
          Returns the current number of local variables.
 boolean hasMorePositions()
          Returns true if there are more positions() needed to iterate through.
 void popToTop(int top)
          Pops the last count vars from the local stack.
 void popVars(int count)
          Pops the last count vars from the local stack.
 void setCache(java.lang.Object key, java.lang.Object value)
           
 org.w3c.dom.Node setContextNode(org.w3c.dom.Node contextNode)
          Sets the context node.
 int setContextPosition(int position)
           
 int setContextSize(int size)
          Sets the context size to a know value.
 void setCurrentNode(org.w3c.dom.Node node)
          Sets the current node.
 ExprEnvironment setExprEnv(ExprEnvironment exprEnv)
          Sets the selection context
 java.util.HashMap setFunctions(java.util.HashMap functions)
          Sets the extension function library
 void setGlobal(java.lang.String name, java.lang.Object value)
          Sets a global variable.
 boolean setMorePositions(boolean more)
          Set true if there are more positions() needed to iterate through.
 void setPosition(int position)
           
 int setPositionIndex(int index)
           
 AbstractPattern setSelect(org.w3c.dom.Node node, AbstractPattern select)
          Sets the selection context
 void setStylesheetEnv(StylesheetEnv stylesheetEnv)
           
 void setVar(java.lang.String name, java.lang.Object value)
          Sets the value associated with name.
 void setVarEnv(VarEnv varEnv)
          Sets the variable environment.
 void setVarSize(int size)
          Sets the current number of local variables (popping, them).
 java.lang.String stringValue(org.w3c.dom.Node node)
          Returns the string-value of the node.
 java.lang.Object systemProperty(java.lang.String namespaceURI, java.lang.String localName)
          Returns the given system property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Env

public Env()
Method Detail

setStylesheetEnv

public void setStylesheetEnv(StylesheetEnv stylesheetEnv)

getStylesheetEnv

public StylesheetEnv getStylesheetEnv()
Description copied from interface: ExprEnvironment
Returns the StylesheetEnv

Specified by:
getStylesheetEnv in interface ExprEnvironment

setVarEnv

public void setVarEnv(VarEnv varEnv)
Sets the variable environment.


getVarEnv

public VarEnv getVarEnv()
Returns the variable environment.


clear

public void clear()
Clears all values in the local environment.


getVarSize

public int getVarSize()
Returns the current number of local variables.


setVarSize

public void setVarSize(int size)
Sets the current number of local variables (popping, them).


getVar

public Var getVar(java.lang.String name)
Returns the value associated with name.

name must be interned

Specified by:
getVar in interface ExprEnvironment

addVar

public int addVar(java.lang.String name,
                  java.lang.Object value)
Adds the value associated with name.

name must be interned


setVar

public void setVar(java.lang.String name,
                   java.lang.Object value)
Sets the value associated with name.

name must be interned


addVar

public int addVar(java.lang.String name,
                  Var value)
Adds the value associated with name.

name must be interned


popVars

public void popVars(int count)
Pops the last count vars from the local stack.


getTop

public int getTop()
Returns the top of the stack.


popToTop

public void popToTop(int top)
Pops the last count vars from the local stack.


setGlobal

public void setGlobal(java.lang.String name,
                      java.lang.Object value)
Sets a global variable.


setFunctions

public java.util.HashMap setFunctions(java.util.HashMap functions)
Sets the extension function library

Parameters:
function - new function library
Returns:
old function library

addFunction

public void addFunction(java.lang.String name,
                        java.lang.Object fun)
Adds and extension function

Parameters:
function - new function library

getFunction

public XPathFun getFunction(java.lang.String name)
Returns the named function.

Specified by:
getFunction in interface ExprEnvironment

hasMorePositions

public boolean hasMorePositions()
Returns true if there are more positions() needed to iterate through.


setMorePositions

public boolean setMorePositions(boolean more)
Set true if there are more positions() needed to iterate through.

Parameters:
more - if true, there are more positions to iterate through.
Returns:
the old more-position value.

setPositionIndex

public int setPositionIndex(int index)

getPositionIndex

public int getPositionIndex()

getCurrentNode

public org.w3c.dom.Node getCurrentNode()
Gets the current node.

Specified by:
getCurrentNode in interface ExprEnvironment

setCurrentNode

public void setCurrentNode(org.w3c.dom.Node node)
Sets the current node.


setSelect

public AbstractPattern setSelect(org.w3c.dom.Node node,
                                 AbstractPattern select)
Sets the selection context


getSelect

public AbstractPattern getSelect()

setExprEnv

public ExprEnvironment setExprEnv(ExprEnvironment exprEnv)
Sets the selection context


getExprEnv

public ExprEnvironment getExprEnv()

getContextNode

public org.w3c.dom.Node getContextNode()
Gets the context node.

Specified by:
getContextNode in interface ExprEnvironment

setContextNode

public org.w3c.dom.Node setContextNode(org.w3c.dom.Node contextNode)
Sets the context node.

Specified by:
setContextNode in interface ExprEnvironment

getContextPosition

public int getContextPosition()
Returns the position of the context node.

Specified by:
getContextPosition in interface ExprEnvironment

getContextSize

public int getContextSize()
Returns the number of nodes in the context list.

Specified by:
getContextSize in interface ExprEnvironment

getOwnerDocument

public org.w3c.dom.Document getOwnerDocument()
Returns a document for creating nodes.

Specified by:
getOwnerDocument in interface ExprEnvironment

systemProperty

public java.lang.Object systemProperty(java.lang.String namespaceURI,
                                       java.lang.String localName)
Returns the given system property.

Specified by:
systemProperty in interface ExprEnvironment

stringValue

public java.lang.String stringValue(org.w3c.dom.Node node)
Returns the string-value of the node.

Specified by:
stringValue in interface ExprEnvironment

setPosition

public void setPosition(int position)

setContextPosition

public int setContextPosition(int position)

setContextSize

public int setContextSize(int size)
Sets the context size to a know value.


getCache

public java.lang.Object getCache(java.lang.Object key)

setCache

public void setCache(java.lang.Object key,
                     java.lang.Object value)

getUseCount

public int getUseCount()

free

public void free()