FileDocCategorySizeDatePackage
FilterExprWalker.javaAPI DocJava SE 5 API9745Fri Aug 26 14:56:06 BST 2005com.sun.org.apache.xpath.internal.axes

FilterExprWalker

public class FilterExprWalker extends AxesWalker
Walker for the OP_VARIABLE, or OP_EXTFUNCTION, or OP_FUNCTION, or OP_GROUP, op codes.
see
XPath FilterExpr descriptions

Fields Summary
private Expression
m_expr
The contained expression. Should be non-null.
private transient XNodeSet
m_exprObj
The result of executing m_expr. Needs to be deep cloned on clone op.
private boolean
m_mustHardReset
private boolean
m_canDetachNodeset
Constructors Summary
public FilterExprWalker(WalkingIterator locPathIterator)
Construct a FilterExprWalker using a LocPathIterator.

param
locPathIterator non-null reference to the parent iterator.

    super(locPathIterator, Axis.FILTEREDLIST);
  
Methods Summary
public shortacceptNode(int n)
This method needs to override AxesWalker.acceptNode because FilterExprWalkers don't need to, and shouldn't, do a node test.

param
n The node to check to see if it passes the filter or not.
return
a constant to determine whether the node is accepted, rejected, or skipped, as defined above .


    try
    {
      if (getPredicateCount() > 0)
      {
        countProximityPosition(0);

        if (!executePredicates(n, m_lpi.getXPathContext()))
          return DTMIterator.FILTER_SKIP;
      }

      return DTMIterator.FILTER_ACCEPT;
    }
    catch (javax.xml.transform.TransformerException se)
    {
      throw new RuntimeException(se.getMessage());
    }
  
public voidcallPredicateVisitors(com.sun.org.apache.xpath.internal.XPathVisitor visitor)
This will traverse the heararchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.

param
owner The owner of the visitor, where that path may be rewritten if needed.
param
visitor The visitor whose appropriate method will be called.

	  m_expr.callVisitors(new filterExprOwner(), visitor);
	  
	  super.callPredicateVisitors(visitor);
	
public java.lang.Objectclone()
Get a cloned FilterExprWalker.

return
A new FilterExprWalker that can be used without mutating this one.
throws
CloneNotSupportedException


    FilterExprWalker clone = (FilterExprWalker) super.clone();

    // clone.m_expr = (Expression)((Expression)m_expr).clone();
    if (null != m_exprObj)
      clone.m_exprObj = (XNodeSet) m_exprObj.clone();

    return clone;
  
public booleandeepEquals(com.sun.org.apache.xpath.internal.Expression expr)

see
Expression#deepEquals(Expression)

      if (!super.deepEquals(expr))
                return false;

      FilterExprWalker walker = (FilterExprWalker)expr;
      if(!m_expr.deepEquals(walker.m_expr))
      	return false;

      return true;
    
public voiddetach()
Detaches the walker from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.

  
  	super.detach();
  	if (m_canDetachNodeset)
  	{
  	  m_exprObj.detach();
  	}
  	m_exprObj = null;
  
public voidfixupVariables(java.util.Vector vars, int globalsSize)
This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.

param
vars List of QNames that correspond to variables. This list should be searched backwards for the first qualified name that corresponds to the variable reference qname. The position of the QName in the vector from the start of the vector will be its position in the stack frame (but variables above the globalsTop value will need to be offset to the current stack frame).


                                                                                               
       
  
    super.fixupVariables(vars, globalsSize);
    m_expr.fixupVariables(vars, globalsSize);
  
public intgetAnalysisBits()
Get the analysis bits for this walker, as defined in the WalkerFactory.

return
One of WalkerFactory#BIT_DESCENDANT, etc.

      if (null != m_expr && m_expr instanceof PathComponent)
      {
        return ((PathComponent) m_expr).getAnalysisBits();
      }
      return WalkerFactory.BIT_FILTER;
  
public intgetAxis()
Returns the axis being iterated, if it is known.

return
Axis.CHILD, etc., or -1 if the axis is not known or is of multiple types.

    return m_exprObj.getAxis();
  
public com.sun.org.apache.xpath.internal.ExpressiongetInnerExpression()
Get the inner contained expression of this filter.

  	return m_expr;
  
public intgetLastPos(com.sun.org.apache.xpath.internal.XPathContext xctxt)
Get the index of the last node that can be itterated to.

param
xctxt XPath runtime context.
return
the index of the last node that can be itterated to.

    return m_exprObj.getLength();
  
public intgetNextNode()
Moves the TreeWalker to the next visible node in document order relative to the current node, and returns the new node. If the current node has no next node, or if the search for nextNode attempts to step upward from the TreeWalker's root node, returns null , and retains the current node.

return
The new node, or null if the current node has no next node in the TreeWalker's logical view.


    if (null != m_exprObj)
    {
       int next = m_exprObj.nextNode();
       return next;
    }
    else
      return DTM.NULL;
  
public voidinit(com.sun.org.apache.xpath.internal.compiler.Compiler compiler, int opPos, int stepType)
Init a FilterExprWalker.

param
compiler non-null reference to the Compiler that is constructing.
param
opPos positive opcode position for this step.
param
stepType The type of step.
throws
javax.xml.transform.TransformerException


    super.init(compiler, opPos, stepType);

    // Smooth over an anomily in the opcode map...
    switch (stepType)
    {
    case OpCodes.OP_FUNCTION :
    case OpCodes.OP_EXTFUNCTION :
    	m_mustHardReset = true;
    case OpCodes.OP_GROUP :
    case OpCodes.OP_VARIABLE :
      m_expr = compiler.compile(opPos);
      m_expr.exprSetParent(this);
      //if((OpCodes.OP_FUNCTION == stepType) && (m_expr instanceof com.sun.org.apache.xalan.internal.templates.FuncKey))
      if(m_expr instanceof com.sun.org.apache.xpath.internal.operations.Variable)
      {
      	// hack/temp workaround
      	m_canDetachNodeset = false;
      }
      break;
    default :
      m_expr = compiler.compile(opPos + 2);
      m_expr.exprSetParent(this);
    }
//    if(m_expr instanceof WalkingIterator)
//    {
//      WalkingIterator wi = (WalkingIterator)m_expr;
//      if(wi.getFirstWalker() instanceof FilterExprWalker)
//      {
//      	FilterExprWalker fw = (FilterExprWalker)wi.getFirstWalker();
//      	if(null == fw.getNextWalker())
//      	{
//      		m_expr = fw.m_expr;
//      		m_expr.exprSetParent(this);
//      	}
//      }
//      		
//    }
  
public booleanisDocOrdered()
Returns true if all the nodes in the iteration well be returned in document order. Warning: This can only be called after setRoot has been called!

return
true as a default.

    return m_exprObj.isDocOrdered();
  
public voidsetInnerExpression(com.sun.org.apache.xpath.internal.Expression expr)
Set the inner contained expression of this filter.

  	expr.exprSetParent(this);
  	m_expr = expr;
  
public voidsetRoot(int root)
Set the root node of the TreeWalker.

param
root non-null reference to the root, or starting point of the query.


    super.setRoot(root);

  	m_exprObj = FilterExprIteratorSimple.executeFilterExpr(root, 
  	                  m_lpi.getXPathContext(), m_lpi.getPrefixResolver(), 
  	                  m_lpi.getIsTopLevel(), m_lpi.m_stackFrame, m_expr);