19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License.
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License.
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: PredicatedNodeTest.java 468655 2006-10-28 07:12:06Z minchau $
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xpath.axes;
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTM;
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTMIterator;
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.PrefixResolver;
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.Expression;
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.ExpressionOwner;
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPathContext;
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPathVisitor;
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.compiler.Compiler;
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XObject;
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.patterns.NodeTest;
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic abstract class PredicatedNodeTest extends NodeTest implements SubContextList
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    static final long serialVersionUID = -6193530757296377351L;
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Construct an AxesWalker using a LocPathIterator.
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param locPathIterator non-null reference to the parent iterator.
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  PredicatedNodeTest(LocPathIterator locPathIterator)
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_lpi = locPathIterator;
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Construct an AxesWalker.  The location path iterator will have to be set
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * before use.
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  PredicatedNodeTest()
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Read the object from a serialization stream.
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param stream Input stream to read from
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws java.io.IOException
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws javax.xml.transform.TransformerException
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private void readObject(java.io.ObjectInputStream stream)
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws java.io.IOException, javax.xml.transform.TransformerException
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    try
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      stream.defaultReadObject();
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_predicateIndex = -1;
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      resetProximityPositions();
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    catch (ClassNotFoundException cnfe)
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      throw new javax.xml.transform.TransformerException(cnfe);
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get a cloned PrdicatedNodeTest.
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return A new PredicatedNodeTest that can be used without mutating this one.
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws CloneNotSupportedException
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Object clone() throws CloneNotSupportedException
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // Do not access the location path itterator during this operation!
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    PredicatedNodeTest clone = (PredicatedNodeTest) super.clone();
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if ((null != this.m_proximityPositions)
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            && (this.m_proximityPositions == clone.m_proximityPositions))
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      clone.m_proximityPositions = new int[this.m_proximityPositions.length];
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      System.arraycopy(this.m_proximityPositions, 0,
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                       clone.m_proximityPositions, 0,
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                       this.m_proximityPositions.length);
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(clone.m_lpi == this)
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      clone.m_lpi = (LocPathIterator)clone;
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return clone;
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Only for clones for findLastPos.  See bug4638.
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected int m_predCount = -1;
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the number of predicates that this walker has.
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return the number of predicates that this walker has.
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getPredicateCount()
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(-1 == m_predCount)
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return (null == m_predicates) ? 0 : m_predicates.length;
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    else
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return m_predCount;
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the number of predicates that this walker has.  This does more
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * that one would think, as it creates a new predicate array of the
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * size of the count argument, and copies count predicates into the new
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * one from the old, and then reassigns the predicates value.  All this
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * to keep from having to have a predicate count value.
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param count The number of predicates, which must be equal or less
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *               than the existing count.
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setPredicateCount(int count)
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(count > 0)
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      Expression[] newPredicates = new Expression[count];
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      for (int i = 0; i < count; i++)
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        newPredicates[i] = m_predicates[i];
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_predicates = newPredicates;
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    else
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_predicates = null;
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Init predicate info.
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param compiler The Compiler object that has information about this
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *                 walker in the op map.
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param opPos The op code position of this location step.
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws javax.xml.transform.TransformerException
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected void initPredicateInfo(Compiler compiler, int opPos)
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws javax.xml.transform.TransformerException
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int pos = compiler.getFirstPredicateOpPos(opPos);
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(pos > 0)
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_predicates = compiler.getCompiledPredicates(pos);
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if(null != m_predicates)
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      	for(int i = 0; i < m_predicates.length; i++)
1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      	{
1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      		m_predicates[i].exprSetParent(this);
1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      	}
1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get a predicate expression at the given index.
1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param index Index of the predicate.
1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return A predicate expression.
1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Expression getPredicate(int index)
1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_predicates[index];
1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the current sub-context position.
1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The node position of this walker in the sub-context node list.
1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getProximityPosition()
1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // System.out.println("getProximityPosition - m_predicateIndex: "+m_predicateIndex);
2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return getProximityPosition(m_predicateIndex);
2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the current sub-context position.
2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param xctxt The XPath runtime context.
2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The node position of this walker in the sub-context node list.
2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getProximityPosition(XPathContext xctxt)
2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return getProximityPosition();
2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the index of the last node that can be itterated to.
2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param xctxt XPath runtime context.
2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return the index of the last node that can be itterated to.
2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public abstract int getLastPos(XPathContext xctxt);
2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the current sub-context position.
2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param predicateIndex The index of the predicate where the proximity
2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *                       should be taken from.
2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The node position of this walker in the sub-context node list.
2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected int getProximityPosition(int predicateIndex)
2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return (predicateIndex >= 0) ? m_proximityPositions[predicateIndex] : 0;
2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Reset the proximity positions counts.
2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void resetProximityPositions()
2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int nPredicates = getPredicateCount();
2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (nPredicates > 0)
2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (null == m_proximityPositions)
2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        m_proximityPositions = new int[nPredicates];
2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      for (int i = 0; i < nPredicates; i++)
2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        try
2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          initProximityPosition(i);
2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch(Exception e)
2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // TODO: Fix this...
2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throw new org.apache.xml.utils.WrappedRuntimeException(e);
2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Init the proximity position to zero for a forward axes.
2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param i The index into the m_proximityPositions array.
2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws javax.xml.transform.TransformerException
2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void initProximityPosition(int i) throws javax.xml.transform.TransformerException
2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_proximityPositions[i] = 0;
2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Count forward one proximity position.
2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param i The index into the m_proximityPositions array, where the increment
2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *          will occur.
2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected void countProximityPosition(int i)
2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	// Note that in the case of a UnionChildIterator, this may be a
2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	// static object and so m_proximityPositions may indeed be null!
2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	int[] pp = m_proximityPositions;
2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if ((null != pp) && (i < pp.length))
2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      pp[i]++;
2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Tells if this is a reverse axes.
2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return false, unless a derived class overrides.
2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public boolean isReverseAxes()
2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return false;
2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get which predicate is executing.
3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The current predicate index, or -1 if no predicate is executing.
3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getPredicateIndex()
3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_predicateIndex;
3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Process the predicates.
3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param context The current context node.
3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param xctxt The XPath runtime context.
3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return the result of executing the predicate expressions.
3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws javax.xml.transform.TransformerException
3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  boolean executePredicates(int context, XPathContext xctxt)
3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws javax.xml.transform.TransformerException
3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int nPredicates = getPredicateCount();
3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // System.out.println("nPredicates: "+nPredicates);
3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (nPredicates == 0)
3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return true;
3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    PrefixResolver savedResolver = xctxt.getNamespaceContext();
3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    try
3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_predicateIndex = 0;
3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.pushSubContextList(this);
3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.pushCurrentNode(context);
3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      for (int i = 0; i < nPredicates; i++)
3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        XObject pred = m_predicates[i].execute(xctxt);
3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // System.out.println("pred.getType(): "+pred.getType());
3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (XObject.CLASS_NUMBER == pred.getType())
3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if (DEBUG_PREDICATECOUNTING)
3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          {
3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            System.out.flush();
3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            System.out.println("\n===== start predicate count ========");
3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            System.out.println("m_predicateIndex: " + m_predicateIndex);
3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // System.out.println("getProximityPosition(m_predicateIndex): "
3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            //                   + getProximityPosition(m_predicateIndex));
3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            System.out.println("pred.num(): " + pred.num());
3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          }
3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          int proxPos = this.getProximityPosition(m_predicateIndex);
3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          int predIndex = (int) pred.num();
3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if (proxPos != predIndex)
3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          {
3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (DEBUG_PREDICATECOUNTING)
3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson              System.out.println("\nnode context: "+nodeToString(context));
3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson              System.out.println("index predicate is false: "+proxPos);
3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson              System.out.println("\n===== end predicate count ========");
3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            return false;
3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          }
3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          else if (DEBUG_PREDICATECOUNTING)
3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          {
3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            System.out.println("\nnode context: "+nodeToString(context));
3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            System.out.println("index predicate is true: "+proxPos);
3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            System.out.println("\n===== end predicate count ========");
3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          }
3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // If there is a proximity index that will not change during the
3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // course of itteration, then we know there can be no more true
3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // occurances of this predicate, so flag that we're done after
3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // this.
3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          //
3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // bugzilla 14365
3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // We can't set m_foundLast = true unless we're sure that -all-
3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // remaining parameters are stable, or else last() fails. Fixed so
3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // only sets m_foundLast if on the last predicate
3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          {
3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            m_foundLast = true;
3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          }
3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        else if (!pred.bool())
3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          return false;
3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        countProximityPosition(++m_predicateIndex);
3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    finally
3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.popCurrentNode();
3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.popNamespaceContext();
4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.popSubContextList();
4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_predicateIndex = -1;
4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return true;
4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This function is used to fixup variables from QNames to stack frame
4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * indexes at stylesheet build time.
4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param vars List of QNames that correspond to variables.  This list
4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * should be searched backwards for the first qualified name that
4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * corresponds to the variable reference qname.  The position of the
4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * QName in the vector from the start of the vector will be its position
4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * in the stack frame (but variables above the globalsTop value will need
4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * to be offset to the current stack frame).
4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void fixupVariables(java.util.Vector vars, int globalsSize)
4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    super.fixupVariables(vars, globalsSize);
4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int nPredicates = getPredicateCount();
4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    for (int i = 0; i < nPredicates; i++)
4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_predicates[i].fixupVariables(vars, globalsSize);
4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Diagnostics.
4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param n Node to give diagnostic information about, or null.
4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return Informative string about the argument.
4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected String nodeToString(int n)
4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(DTM.NULL != n)
4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      DTM dtm = m_lpi.getXPathContext().getDTM(n);
4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return dtm.getNodeName(n) + "{" + (n+1) + "}";
4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    else
4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return "null";
4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  //=============== NodeFilter Implementation ===============
4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *  Test whether a specified node is visible in the logical view of a
4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * TreeWalker or NodeIterator. This function will be called by the
4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * implementation of TreeWalker and NodeIterator; it is not intended to
4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * be called directly from user code.
4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param n  The node to check to see if it passes the filter or not.
4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return  a constant to determine whether the node is accepted,
4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *   rejected, or skipped, as defined  above .
4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public short acceptNode(int n)
4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    XPathContext xctxt = m_lpi.getXPathContext();
4659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    try
4679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.pushCurrentNode(n);
4699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      XObject score = execute(xctxt, n);
4719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      // System.out.println("\n::acceptNode - score: "+score.num()+"::");
4739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (score != NodeTest.SCORE_NONE)
4749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
4759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (getPredicateCount() > 0)
4769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
4779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          countProximityPosition(0);
4789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if (!executePredicates(n, xctxt))
4809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            return DTMIterator.FILTER_SKIP;
4819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
4829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return DTMIterator.FILTER_ACCEPT;
4849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
4859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    catch (javax.xml.transform.TransformerException se)
4879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      // TODO: Fix this.
4909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      throw new RuntimeException(se.getMessage());
4919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    finally
4939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.popCurrentNode();
4959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return DTMIterator.FILTER_SKIP;
4989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the owning location path iterator.
5039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return the owning location path iterator, which should not be null.
5059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public LocPathIterator getLocPathIterator()
5079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
5089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_lpi;
5099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
5109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the location path iterator owner for this walker.  Besides
5139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * initialization, this function is called during cloning operations.
5149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param li non-null reference to the owning location path iterator.
5169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setLocPathIterator(LocPathIterator li)
5189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
5199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_lpi = li;
5209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(this != li)
5219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      li.exprSetParent(this);
5229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
5239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Tell if this expression or it's subexpressions can traverse outside
5269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * the current subtree.
5279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return true if traversal outside the context node's subtree can occur.
5299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   public boolean canTraverseOutsideSubtree()
5319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   {
5329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int n = getPredicateCount();
5339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    for (int i = 0; i < n; i++)
5349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
5359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if(getPredicate(i).canTraverseOutsideSubtree())
5369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return true;
5379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
5389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return false;
5399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   }
5409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	/**
5429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	 * This will traverse the heararchy, calling the visitor for
5439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	 * each member.  If the called visitor method returns
5449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	 * false, the subtree should not be called.
5459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	 *
5469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	 * @param visitor The visitor whose appropriate method will be called.
5479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	 */
5489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	public void callPredicateVisitors(XPathVisitor visitor)
5499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	{
5509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	  if (null != m_predicates)
5519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	    {
5529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	    int n = m_predicates.length;
5539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	    for (int i = 0; i < n; i++)
5549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	      {
5559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	      ExpressionOwner predOwner = new PredOwner(i);
5569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	      if (visitor.visitPredicate(predOwner, m_predicates[i]))
5579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	        {
5589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	        m_predicates[i].callVisitors(predOwner, visitor);
5599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	      }
5609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	    }
5629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	  }
5639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	}
5649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
5669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @see Expression#deepEquals(Expression)
5679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
5689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public boolean deepEquals(Expression expr)
5699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
5709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (!super.deepEquals(expr))
5719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            return false;
5729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      PredicatedNodeTest pnt = (PredicatedNodeTest) expr;
5749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (null != m_predicates)
5759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
5769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        int n = m_predicates.length;
5789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if ((null == pnt.m_predicates) || (pnt.m_predicates.length != n))
5799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson              return false;
5809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        for (int i = 0; i < n; i++)
5819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
5829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if (!m_predicates[i].deepEquals(pnt.m_predicates[i]))
5839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          	return false;
5849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
5859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
5869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else if (null != pnt.m_predicates)
5879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson              return false;
5889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return true;
5909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
5919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** This is true if nextNode returns null. */
5939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  transient protected boolean m_foundLast = false;
5949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** The owning location path iterator.
5969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *  @serial */
5979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected LocPathIterator m_lpi;
5989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
6009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Which predicate we are executing.
6019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
6029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  transient int m_predicateIndex = -1;
6039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** The list of predicate expressions. Is static and does not need
6059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *  to be deep cloned.
6069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *  @serial
6079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
6089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private Expression[] m_predicates;
6099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
6119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * An array of counts that correspond to the number
6129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * of predicates the step contains.
6139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
6149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  transient protected int[] m_proximityPositions;
6159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** If true, diagnostic messages about predicate execution will be posted.  */
6179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static final boolean DEBUG_PREDICATECOUNTING = false;
6189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  class PredOwner implements ExpressionOwner
6209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
6219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	int m_index;
6229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	PredOwner(int index)
6249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	{
6259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  		m_index = index;
6269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	}
6279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
6299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @see ExpressionOwner#getExpression()
6309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
6319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public Expression getExpression()
6329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
6339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return m_predicates[m_index];
6349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
6359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
6389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @see ExpressionOwner#setExpression(Expression)
6399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
6409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public void setExpression(Expression exp)
6419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
6429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	exp.exprSetParent(PredicatedNodeTest.this);
6439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	m_predicates[m_index] = exp;
6449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
6459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
6469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
648