⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 predicatednodetest.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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 * *     http://www.apache.org/licenses/LICENSE-2.0 * * 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: PredicatedNodeTest.java,v 1.2.4.2 2005/09/14 19:45:20 jeffsuttor Exp $ */package com.sun.org.apache.xpath.internal.axes;import com.sun.org.apache.xml.internal.dtm.DTM;import com.sun.org.apache.xml.internal.dtm.DTMIterator;import com.sun.org.apache.xml.internal.utils.PrefixResolver;import com.sun.org.apache.xpath.internal.Expression;import com.sun.org.apache.xpath.internal.ExpressionOwner;import com.sun.org.apache.xpath.internal.XPathContext;import com.sun.org.apache.xpath.internal.XPathVisitor;import com.sun.org.apache.xpath.internal.compiler.Compiler;import com.sun.org.apache.xpath.internal.objects.XObject;import com.sun.org.apache.xpath.internal.patterns.NodeTest;public abstract class PredicatedNodeTest extends NodeTest implements SubContextList{    static final long serialVersionUID = -6193530757296377351L;  /**   * Construct an AxesWalker using a LocPathIterator.   *   * @param locPathIterator non-null reference to the parent iterator.   */  PredicatedNodeTest(LocPathIterator locPathIterator)  {    m_lpi = locPathIterator;  }    /**   * Construct an AxesWalker.  The location path iterator will have to be set   * before use.   */  PredicatedNodeTest()  {  }    /**   * Read the object from a serialization stream.   *   * @param stream Input stream to read from   *   * @throws java.io.IOException   * @throws javax.xml.transform.TransformerException   */  private void readObject(java.io.ObjectInputStream stream)          throws java.io.IOException, javax.xml.transform.TransformerException  {    try    {      stream.defaultReadObject();      m_predicateIndex = -1;      resetProximityPositions();    }    catch (ClassNotFoundException cnfe)    {      throw new javax.xml.transform.TransformerException(cnfe);    }  }    /**   * Get a cloned PrdicatedNodeTest.   *   * @return A new PredicatedNodeTest that can be used without mutating this one.   *   * @throws CloneNotSupportedException   */  public Object clone() throws CloneNotSupportedException  {    // Do not access the location path itterator during this operation!        PredicatedNodeTest clone = (PredicatedNodeTest) super.clone();    if ((null != this.m_proximityPositions)            && (this.m_proximityPositions == clone.m_proximityPositions))    {      clone.m_proximityPositions = new int[this.m_proximityPositions.length];      System.arraycopy(this.m_proximityPositions, 0,                       clone.m_proximityPositions, 0,                       this.m_proximityPositions.length);    }        if(clone.m_lpi == this)      clone.m_lpi = (LocPathIterator)clone;    return clone;  }    // Only for clones for findLastPos.  See bug4638.  protected int m_predCount = -1;  /**   * Get the number of predicates that this walker has.   *   * @return the number of predicates that this walker has.   */  public int getPredicateCount()  {    if(-1 == m_predCount)      return (null == m_predicates) ? 0 : m_predicates.length;    else      return m_predCount;  }  /**   * Set the number of predicates that this walker has.  This does more    * that one would think, as it creates a new predicate array of the    * size of the count argument, and copies count predicates into the new    * one from the old, and then reassigns the predicates value.  All this    * to keep from having to have a predicate count value.   *   * @param count The number of predicates, which must be equal or less    *               than the existing count.   */  public void setPredicateCount(int count)  {    if(count > 0)    {      Expression[] newPredicates = new Expression[count];      for (int i = 0; i < count; i++)       {        newPredicates[i] = m_predicates[i];      }      m_predicates = newPredicates;    }    else      m_predicates = null;      }  /**   * Init predicate info.   *   * @param compiler The Compiler object that has information about this    *                 walker in the op map.   * @param opPos The op code position of this location step.   *   * @throws javax.xml.transform.TransformerException   */  protected void initPredicateInfo(Compiler compiler, int opPos)          throws javax.xml.transform.TransformerException  {    int pos = compiler.getFirstPredicateOpPos(opPos);    if(pos > 0)    {      m_predicates = compiler.getCompiledPredicates(pos);      if(null != m_predicates)      {      	for(int i = 0; i < m_predicates.length; i++)      	{      		m_predicates[i].exprSetParent(this);      	}      }    }  }  /**   * Get a predicate expression at the given index.   *   *   * @param index Index of the predicate.   *   * @return A predicate expression.   */  public Expression getPredicate(int index)  {    return m_predicates[index];  }    /**   * Get the current sub-context position.   *   * @return The node position of this walker in the sub-context node list.   */  public int getProximityPosition()  {    // System.out.println("getProximityPosition - m_predicateIndex: "+m_predicateIndex);    return getProximityPosition(m_predicateIndex);  }  /**   * Get the current sub-context position.   *   * @param xctxt The XPath runtime context.   *   * @return The node position of this walker in the sub-context node list.   */  public int getProximityPosition(XPathContext xctxt)  {    return getProximityPosition();  }    /**   * 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.   */  public abstract int getLastPos(XPathContext xctxt);  /**   * Get the current sub-context position.   *   * @param predicateIndex The index of the predicate where the proximity    *                       should be taken from.   *   * @return The node position of this walker in the sub-context node list.   */  protected int getProximityPosition(int predicateIndex)  {    return (predicateIndex >= 0) ? m_proximityPositions[predicateIndex] : 0;  }  /**   * Reset the proximity positions counts.   */  public void resetProximityPositions()  {    int nPredicates = getPredicateCount();    if (nPredicates > 0)    {      if (null == m_proximityPositions)        m_proximityPositions = new int[nPredicates];      for (int i = 0; i < nPredicates; i++)      {        try        {          initProximityPosition(i);        }        catch(Exception e)        {          // TODO: Fix this...          throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);        }      }    }  }  /**   * Init the proximity position to zero for a forward axes.   *   * @param i The index into the m_proximityPositions array.   *   * @throws javax.xml.transform.TransformerException   */  public void initProximityPosition(int i) throws javax.xml.transform.TransformerException  {    m_proximityPositions[i] = 0;  }  /**   * Count forward one proximity position.   *   * @param i The index into the m_proximityPositions array, where the increment    *          will occur.   */  protected void countProximityPosition(int i)  {  	// Note that in the case of a UnionChildIterator, this may be a   	// static object and so m_proximityPositions may indeed be null!  	int[] pp = m_proximityPositions;    if ((null != pp) && (i < pp.length))      pp[i]++;  }  /**   * Tells if this is a reverse axes.   *   * @return false, unless a derived class overrides.   */  public boolean isReverseAxes()  {    return false;  }  /**   * Get which predicate is executing.   *   * @return The current predicate index, or -1 if no predicate is executing.   */  public int getPredicateIndex()  {    return m_predicateIndex;  }  /**   * Process the predicates.   *   * @param context The current context node.   * @param xctxt The XPath runtime context.   *   * @return the result of executing the predicate expressions.   *   * @throws javax.xml.transform.TransformerException   */  boolean executePredicates(int context, XPathContext xctxt)          throws javax.xml.transform.TransformerException  {        int nPredicates = getPredicateCount();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -