sboag       01/07/27 10:42:41

  Modified:    java/src/org/apache/xpath/axes WalkerFactory.java
               java/src/org/apache/xpath/compiler Compiler.java
               java/src/org/apache/xpath/patterns
                        ContextMatchStepPattern.java StepPattern.java
  Log:
  These are changes submitted (offline) by Mukund Raghavachari/Watson/[EMAIL 
PROTECTED]
  
  This fixes a bug with match="chapter//footnote[1]" patterns.
  
  The main change here is minor to remove the automatic attachment of parent::* 
to simple step patterns.
  
  He has re-implemented executePredicates to be
  more efficient. Given a pattern such as row[6], it
  does not iterate over the entire axis until it reaches
  the node to see if it is the sixth node. Rather,
  starting from the current node, it works backwards
  (preceding siblings) until it either runs out of nodes
  or finds more than six nodes that match the
  predicate [I can explain it better if desired].
  This optimization improves performance slightly
  overall. It helps decoy and patterns most (by
  about 10%).
  
  The other optimization that I implemented was the
  following. For a pattern foo[][3][][4] ..., where more
  than one predicate is a number (position check),
  in checking the predicate [4], the fact that the
  current node has passed foo[][3] implies that it is
  the only node that is the third node among its
  siblings that passes foo[]. Therefore, any
  subsequent position checks can be true if and
  only if the position is [1]. This optimization is not
  used by the xsltmark benchmarks and so does
  not offer any performance benefits.
  
  Revision  Changes    Path
  1.17      +4 -3      
xml-xalan/java/src/org/apache/xpath/axes/WalkerFactory.java
  
  Index: WalkerFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/WalkerFactory.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- WalkerFactory.java        2001/06/29 21:44:34     1.16
  +++ WalkerFactory.java        2001/07/27 17:42:40     1.17
  @@ -834,7 +834,7 @@
            pat = pat.getRelativePathPattern()) 
       {
         int nextAxis = pat.getAxis();
  -      int nextPaxis = pat.getPredicateAxis();
  +      //int nextPaxis = pat.getPredicateAxis();
         pat.setAxis(axis);
         
         // The predicate axis can't be moved!!!  Test Axes103
  @@ -871,7 +871,8 @@
             StepPattern attrPat = new StepPattern(whatToShow, 
                                       pat.getNamespace(),
                                       pat.getLocalName(),
  -                                    newAxis, pat.getPredicateAxis());
  +                             //newAxis, pat.getPredicateAxis);
  +                                             newAxis, 0); // don't care 
about the predicate axis
             XNumber score = pat.getStaticScore();
             pat.setNamespace(null);
             pat.setLocalName(NodeTest.WILD);
  @@ -903,7 +904,7 @@
           }
         }
         axis = nextAxis;
  -      paxis = nextPaxis;
  +      //paxis = nextPaxis;
         tail = pat;
       }
       
  
  
  
  1.26      +2 -2      
xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- Compiler.java     2001/07/11 06:49:51     1.25
  +++ Compiler.java     2001/07/27 17:42:40     1.26
  @@ -936,7 +936,7 @@
         // translate this to a select pattern from the node being tested, 
         // which is really how we're treating match patterns, it works out to 
         // self::foo/parent::node[child::foo[3]]", or close enough.
  -      if(addMagicSelf && pattern.getPredicateCount() > 0)
  +     /*      if(addMagicSelf && pattern.getPredicateCount() > 0)
         {
           StepPattern selfPattern = new StepPattern(DTMFilter.SHOW_ALL, 
                                                     Axis.PARENT, Axis.CHILD);
  @@ -945,7 +945,7 @@
           pattern.setRelativePathPattern(selfPattern);
           pattern.setStaticScore(score);
           selfPattern.setStaticScore(score);
  -      }
  +     }*/
       }
       else
       {
  
  
  
  1.3       +8 -7      
xml-xalan/java/src/org/apache/xpath/patterns/ContextMatchStepPattern.java
  
  Index: ContextMatchStepPattern.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/ContextMatchStepPattern.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ContextMatchStepPattern.java      2001/06/12 19:17:01     1.2
  +++ ContextMatchStepPattern.java      2001/07/27 17:42:40     1.3
  @@ -158,11 +158,12 @@
   
             if (score != NodeTest.SCORE_NONE)
             {
  -            score = executePredicates( xctxt, prevStep, SCORE_OTHER, 
  -                       predContext, relative);
  -
  -            if (score != NodeTest.SCORE_NONE)
  -              return score;
  +           //score = executePredicates( xctxt, prevStep, SCORE_OTHER, 
  +           //       predContext, relative);
  +           if (executePredicates(xctxt, dtm, context))
  +               return score;
  +           
  +           score = NodeTest.SCORE_NONE;
             }
             
             if(needToTraverseAttrs && iterRootIsAttr
  @@ -185,8 +186,8 @@
           
                     if (score != NodeTest.SCORE_NONE)
                     {
  -                    score = executePredicates( xctxt, prevStep, SCORE_OTHER, 
  -                               predContext, arelative);
  +                   //score = executePredicates( xctxt, prevStep, 
SCORE_OTHER, 
  +                   //       predContext, arelative);
           
                       if (score != NodeTest.SCORE_NONE)
                         return score;
  
  
  
  1.21      +305 -255  
xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java
  
  Index: StepPattern.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- StepPattern.java  2001/06/12 19:17:02     1.20
  +++ StepPattern.java  2001/07/27 17:42:41     1.21
  @@ -74,12 +74,9 @@
   public class StepPattern extends NodeTest implements SubContextList
   {
   
  -  /** NEEDSDOC Field m_axisForPredicate */
  -  protected int m_axisForPredicate;
  -
  -  /** NEEDSDOC Field m_axis */
  +  /** The axis for this test. */
     protected int m_axis;
  -  
  +
     /**
      * Construct a StepPattern that tests for namespaces and node names.
      *
  @@ -87,15 +84,16 @@
      * @param whatToShow Bit set defined mainly by [EMAIL PROTECTED] 
org.w3c.dom.traversal.NodeFilter}.
      * @param namespace The namespace to be tested.
      * @param name The local name to be tested.
  +   * @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
  +   * @param axisForPredicate No longer used.
      */
  -  public StepPattern(int whatToShow, String namespace, String name,
  -                     int axis, int axisForPredicate)
  +  public StepPattern(int whatToShow, String namespace, String name, int axis,
  +                     int axisForPredicate)
     {
   
       super(whatToShow, namespace, name);
   
       m_axis = axis;
  -    m_axisForPredicate = axisForPredicate;
     }
   
     /**
  @@ -103,15 +101,15 @@
      *
      *
      * @param whatToShow Bit set defined mainly by [EMAIL PROTECTED] 
org.w3c.dom.traversal.NodeFilter}.
  +   * @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
  +   * @param axisForPredicate No longer used.
      */
  -  public StepPattern(int whatToShow,
  -                     int axis, int axisForPredicate)
  +  public StepPattern(int whatToShow, int axis, int axisForPredicate)
     {
   
       super(whatToShow);
  -    
  +
       m_axis = axis;
  -    m_axisForPredicate = axisForPredicate;
     }
   
     /**
  @@ -179,34 +177,37 @@
      * @serial
      */
     StepPattern m_relativePathPattern;
  -  
  +
     /**
  -   * This function is used to fixup variables from QNames to stack frame 
  +   * 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 
  +   * @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).
  +   * @param globalsSize The number of variables in the global variable area.
      */
     public void fixupVariables(java.util.Vector vars, int globalsSize)
     {
  +
       super.fixupVariables(vars, globalsSize);
  -    if(null != m_predicates)
  +
  +    if (null != m_predicates)
       {
  -      for (int i = 0; i < m_predicates.length; i++) 
  +      for (int i = 0; i < m_predicates.length; i++)
         {
           m_predicates[i].fixupVariables(vars, globalsSize);
         }
       }
  -    if(null != m_relativePathPattern)
  +
  +    if (null != m_relativePathPattern)
       {
         m_relativePathPattern.fixupVariables(vars, globalsSize);
       }
     }
   
  -
     /**
      * Set the reference to nodetest and predicate for
      * parent or ancestor.
  @@ -218,10 +219,10 @@
     {
   
       m_relativePathPattern = expr;
  -    
  +
       calcScore();
     }
  -  
  +
     /**
      * Get the reference to nodetest and predicate for
      * parent or ancestor.
  @@ -231,19 +232,18 @@
      */
     public StepPattern getRelativePathPattern()
     {
  -
       return m_relativePathPattern;
     }
  -  
  -//  /**
  -//   * Set the list of predicate expressions for this pattern step.
  -//   * @param predicates List of expression objects.
  -//   */
  -//  public void setPredicates(Expression[] predicates)
  -//  {
  -//    m_predicates = predicates;
  -//  }
  -  
  +
  +  //  /**
  +  //   * Set the list of predicate expressions for this pattern step.
  +  //   * @param predicates List of expression objects.
  +  //   */
  +  //  public void setPredicates(Expression[] predicates)
  +  //  {
  +  //    m_predicates = predicates;
  +  //  }
  +
     /**
      * Set the list of predicate expressions for this pattern step.
      * @return List of expression objects.
  @@ -253,13 +253,12 @@
       return m_predicates;
     }
   
  -
     /**
      * The list of predicate expressions for this pattern step.
      *  @serial
      */
     Expression[] m_predicates;
  -  
  +
     /**
      * Tell if this expression or it's subexpressions can traverse outside
      * the current subtree.
  @@ -338,12 +337,13 @@
       if (null == m_targetString)
         calcTargetString();
     }
  -  
  +
     /**
      * Execute this pattern step, including predicates.
      *
      *
      * @param xctxt XPath runtime context.
  +   * @param currentNode The current node context.
      *
      * @return [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
      *         [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
  @@ -357,26 +357,16 @@
             throws javax.xml.transform.TransformerException
     {
   
  -    if (m_whatToShow == NodeTest.SHOW_BYFUNCTION)
  -    {
  -      if (null != m_relativePathPattern)
  -      {
  -        return m_relativePathPattern.execute(xctxt, currentNode);
  -      }
  -      else
  -        return NodeTest.SCORE_NONE;
  -    }
  +    DTM dtm = xctxt.getDTM(currentNode);
   
  -    if (null == m_relativePathPattern)
  +    if (dtm != null)
       {
  -      return super.execute(xctxt, currentNode);
  -    }
  -    else
  -    {
  -      if (super.execute(xctxt, currentNode) == NodeTest.SCORE_NONE)
  -        return NodeTest.SCORE_NONE;
  -      return m_relativePathPattern.executeRelativePathPattern(xctxt, this);
  +      int expType = dtm.getExpandedTypeID(currentNode);
  +
  +      return execute(xctxt, currentNode, dtm, expType);
       }
  +
  +    return NodeTest.SCORE_NONE;
     }
   
     /**
  @@ -396,34 +386,11 @@
     public XObject execute(XPathContext xctxt)
             throws javax.xml.transform.TransformerException
     {
  -
  -    if (m_whatToShow == NodeTest.SHOW_BYFUNCTION)
  -    {
  -      if (null != m_relativePathPattern)
  -      {
  -        return m_relativePathPattern.execute(xctxt);
  -      }
  -      else
  -        return NodeTest.SCORE_NONE;
  -    }
  -
  -    XObject score = super.execute(xctxt, xctxt.getCurrentNode());
  -
  -    if (score == NodeTest.SCORE_NONE)
  -      return score;
  -
  -    else if (null != m_relativePathPattern)
  -    {
  -      return m_relativePathPattern.executeRelativePathPattern(xctxt, this);
  -    }
  -    else
  -    {
  -      return score;
  -    }
  +    return execute(xctxt, xctxt.getCurrentNode());
     }
  -  
  +
     /**
  -   * Execute an expression in the XPath runtime context, and return the 
  +   * Execute an expression in the XPath runtime context, and return the
      * result of the expression.
      *
      *
  @@ -434,13 +401,14 @@
      *
      * @return The result of the expression in the form of a 
<code>XObject</code>.
      *
  -   * @throws javax.xml.transform.TransformerException if a runtime exception 
  +   * @throws javax.xml.transform.TransformerException if a runtime exception
      *         occurs.
      */
  -  public XObject execute(XPathContext xctxt, int currentNode, 
  -                         DTM dtm, int expType)
  -    throws javax.xml.transform.TransformerException
  +  public XObject execute(
  +          XPathContext xctxt, int currentNode, DTM dtm, int expType)
  +            throws javax.xml.transform.TransformerException
     {
  +
       if (m_whatToShow == NodeTest.SHOW_BYFUNCTION)
       {
         if (null != m_relativePathPattern)
  @@ -451,49 +419,131 @@
           return NodeTest.SCORE_NONE;
       }
   
  -    XObject score = super.execute(xctxt, currentNode, dtm, expType);
  +    XObject score;
   
  +    score = super.execute(xctxt, currentNode, dtm, expType);
  +
       if (score == NodeTest.SCORE_NONE)
  -      return score;
  +      return NodeTest.SCORE_NONE;
   
  -    else if (null != m_relativePathPattern)
  +    if (getPredicateCount() != 0)
       {
  -      return m_relativePathPattern.executeRelativePathPattern(xctxt, this);
  +      if (!executePredicates(xctxt, dtm, currentNode))
  +        return NodeTest.SCORE_NONE;
       }
  -    else
  +
  +    if (null != m_relativePathPattern)
  +      return m_relativePathPattern.executeRelativePathPattern(xctxt, dtm,
  +              currentNode);
  +
  +    return score;
  +  }
  +
  +  /**
  +   * New Method to check whether the current node satisfies a position 
predicate
  +   *
  +   * @param xctxt The XPath runtime context.
  +   * @param predPos Which predicate we're evaluating of foo[1][2][3].
  +   * @param dtm The DTM of the current node.
  +   * @param context The currentNode.
  +   * @param pos The position being requested, i.e. the value returned by 
  +   *            m_predicates[predPos].execute(xctxt).
  +   *
  +   * @return true of the position of the context matches pos, false 
otherwise.
  +   */
  +  private final boolean checkProximityPosition(XPathContext xctxt,
  +          int predPos, DTM dtm, int context, int pos)
  +  {
  +
  +    try
       {
  -      return score;
  +      DTMAxisTraverser traverser =
  +        dtm.getAxisTraverser(Axis.PRECEDINGSIBLING);
  +
  +      for (int child = traverser.first(context); DTM.NULL != child;
  +              child = traverser.next(context, child))
  +      {
  +        try
  +        {
  +          xctxt.pushCurrentNode(child);
  +
  +          if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
  +          {
  +            boolean pass = true;
  +
  +            try
  +            {
  +              xctxt.pushSubContextList(this);
  +
  +              for (int i = 0; i < predPos; i++)
  +              {
  +                XObject pred = m_predicates[i].execute(xctxt);
  +
  +                if (XObject.CLASS_NUMBER == pred.getType())
  +                {
  +                  throw new Error("Why: Should never have been called");
  +                }
  +                else if (!pred.bool())
  +                {
  +                  pass = false;
  +
  +                  break;
  +                }
  +              }
  +            }
  +            finally
  +            {
  +              xctxt.popSubContextList();
  +            }
  +
  +            if (pass)
  +              pos--;
  +
  +            if (pos < 1)
  +              return false;
  +          }
  +        }
  +        finally
  +        {
  +          xctxt.popCurrentNode();
  +        }
  +      }
       }
  +    catch (javax.xml.transform.TransformerException se)
  +    {
  +
  +      // TODO: should keep throw sax exception...
  +      throw new java.lang.RuntimeException(se.getMessage());
  +    }
  +
  +    return (pos == 1);
     }
   
  -  
     /**
      * Get the proximity position index of the current node based on this
      * node test.
      *
      *
      * @param xctxt XPath runtime context.
  +   * @param predPos Which predicate we're evaluating of foo[1][2][3].
      *
      * @return the proximity position index of the current node based on the
      *         node test.
      */
  -  public int getProximityPosition(XPathContext xctxt, int predPos)
  +  private final int getProximityPosition(XPathContext xctxt, int predPos)
     {
   
  +    int pos = 0;
       int context = xctxt.getCurrentNode();
       DTM dtm = xctxt.getDTM(context);
  -    int pos = 0;
  +    int parent = dtm.getParent(context);
   
  -    int parentContext = xctxt.getPredicateRoot();    
  -      
       try
       {
  -      xctxt.pushCurrentNode(parentContext);
  -
  -      DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axisForPredicate);
  +      DTMAxisTraverser traverser = dtm.getAxisTraverser(Axis.CHILD);
   
  -      for (int child = traverser.first(parentContext); DTM.NULL != child;
  -              child = traverser.next(parentContext, child))
  +      for (int child = traverser.first(parent); DTM.NULL != child;
  +              child = traverser.next(parent, child))
         {
           try
           {
  @@ -502,27 +552,28 @@
             if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
             {
               boolean pass = true;
  -            
  +
               try
               {
                 xctxt.pushSubContextList(this);
  -              xctxt.pushPredicateRoot(parentContext);
  -      
  +
                 for (int i = 0; i < predPos; i++)
                 {
                   XObject pred = m_predicates[i].execute(xctxt);
   
                   if (XObject.CLASS_NUMBER == pred.getType())
                   {
  -                  if ((pos+1) != (int) pred.num())
  +                  if ((pos + 1) != (int) pred.num())
                     {
                       pass = false;
  +
                       break;
                     }
                   }
                   else if (!pred.bool())
                   {
                     pass = false;
  +
                     break;
                   }
                 }
  @@ -530,10 +581,9 @@
               finally
               {
                 xctxt.popSubContextList();
  -              xctxt.popPredicateRoot();
  -            }              
  -            
  -            if(pass)
  +            }
  +
  +            if (pass)
                 pos++;
   
               if (child == context)
  @@ -554,16 +604,10 @@
         // TODO: should keep throw sax exception...
         throw new java.lang.RuntimeException(se.getMessage());
       }
  -    finally
  -    {
  -      xctxt.popCurrentNode();
  -
  -      // xctxt.popContextNodeList();
  -    }
   
       return pos;
     }
  -  
  +
     /**
      * Get the proximity position index of the current node based on this
      * node test.
  @@ -576,7 +620,6 @@
      */
     public int getProximityPosition(XPathContext xctxt)
     {
  -
       return getProximityPosition(xctxt, xctxt.getPredicatePos());
     }
   
  @@ -596,51 +639,46 @@
   
       int context = xctxt.getCurrentNode();
       DTM dtm = xctxt.getDTM(context);
  +    int parentContext = dtm.getParent(context);
   
  -    int parentContext = xctxt.getPredicateRoot();    
  +    // System.out.println("parentContext: "+parentContext.getNodeName());
  +    try
       {
  -
  -      // System.out.println("parentContext: "+parentContext.getNodeName());
  -      try
  -      {
  -        xctxt.pushCurrentNode(parentContext);
  +      xctxt.pushCurrentNode(parentContext);
   
  -        int count = 0;
  -        DTMAxisTraverser traverser = 
dtm.getAxisTraverser(m_axisForPredicate);
  +      int count = 0;
  +      DTMAxisTraverser traverser = dtm.getAxisTraverser(Axis.CHILD);
   
  -        for (int child = traverser.first(parentContext); DTM.NULL != child;
  -                child = traverser.next(parentContext, child))
  +      for (int child = traverser.first(parentContext); DTM.NULL != child;
  +              child = traverser.next(parentContext, child))
  +      {
  +        try
           {
  -          try
  -          {
  -            xctxt.pushCurrentNode(child);
  +          xctxt.pushCurrentNode(child);
   
  -            if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
  -              count++;
  -          }
  -          finally
  -          {
  -            xctxt.popCurrentNode();
  -          }
  +          if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
  +            count++;
           }
  -
  -        return count;
  +        finally
  +        {
  +          xctxt.popCurrentNode();
  +        }
         }
  -      catch (javax.xml.transform.TransformerException se)
  -      {
   
  -        // TODO: should keep throw sax exception...
  -        throw new java.lang.RuntimeException(se.getMessage());
  -      }
  -      finally
  -      {
  -        xctxt.popCurrentNode();
  +      return count;
  +    }
  +    catch (javax.xml.transform.TransformerException se)
  +    {
   
  -        // xctxt.popContextNodeList();
  -      }
  +      // TODO: should keep throw sax exception...
  +      throw new java.lang.RuntimeException(se.getMessage());
       }
  +    finally
  +    {
  +      xctxt.popCurrentNode();
   
  -    // return 0;
  +      // xctxt.popContextNodeList();
  +    }
     }
   
     /**
  @@ -648,7 +686,8 @@
      *
      *
      * @param xctxt The XPath runtime context.
  -   * NEEDSDOC @param prevStep
  +   * @param dtm The DTM of the current node.
  +   * @param currentNode The current node context.
      *
      * @return [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
      *         [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
  @@ -658,197 +697,206 @@
      *
      * @throws javax.xml.transform.TransformerException
      */
  -  public XObject executeRelativePathPattern(
  -          XPathContext xctxt, StepPattern prevStep)
  +  protected final XObject executeRelativePathPattern(
  +          XPathContext xctxt, DTM dtm, int currentNode)
               throws javax.xml.transform.TransformerException
     {
   
       XObject score = NodeTest.SCORE_NONE;
  -    int context = xctxt.getCurrentNode();
  -    DTM dtm = xctxt.getDTM(context);
  +    int context = currentNode;
  +    DTMAxisTraverser traverser;
   
  -    if (null != dtm)
  -    {
  -      int predContext = xctxt.getCurrentNode();
  -      DTMAxisTraverser traverser;
  -      
  -      int axis = m_axis;
  -      
  -      traverser = dtm.getAxisTraverser(axis);
  +    traverser = dtm.getAxisTraverser(m_axis);
   
  -      for (int relative = traverser.first(context); DTM.NULL != relative;
  -              relative = traverser.next(context, relative))
  +    for (int relative = traverser.first(context); DTM.NULL != relative;
  +            relative = traverser.next(context, relative))
  +    {
  +      try
         {
  -        try
  -        {
  -          xctxt.pushCurrentNode(relative);
  +        xctxt.pushCurrentNode(relative);
   
  -          score = execute(xctxt);
  -          
  -          if (score != NodeTest.SCORE_NONE)
  -          {
  -            score = executePredicates( xctxt, prevStep, SCORE_OTHER, 
  -                       predContext, relative);
  +        score = execute(xctxt);
   
  -            if (score != NodeTest.SCORE_NONE)
  -              break;
  -          }
  -        }
  -        finally
  -        {
  -          xctxt.popCurrentNode();
  -        }
  +        if (score != NodeTest.SCORE_NONE)
  +          break;
         }
  +      finally
  +      {
  +        xctxt.popCurrentNode();
  +      }
       }
   
       return score;
     }
   
     /**
  -   * NEEDSDOC Method executePredicates 
  -   *
  +   * Execute the predicates on this step to determine if the current node 
  +   * should be filtered or accepted.
      *
  -   * NEEDSDOC @param xctxt
  -   * NEEDSDOC @param prevStep
  -   * NEEDSDOC @param score
  +   * @param xctxt The XPath runtime context.
  +   * @param dtm The DTM of the current node.
  +   * @param currentNode The current node context.
      *
  -   * NEEDSDOC (executePredicates) @return
  +   * @return true if the node should be accepted, false otherwise.
      *
      * @throws javax.xml.transform.TransformerException
      */
  -  protected static XObject executePredicates(
  -          XPathContext xctxt, StepPattern prevStep, XObject score, 
  -          int context, int predicateRootContext)
  +  protected final boolean executePredicates(
  +          XPathContext xctxt, DTM dtm, int currentNode)
               throws javax.xml.transform.TransformerException
     {
   
  -    int n = prevStep.getPredicateCount();
  +    boolean result = true;
  +    boolean positionAlreadySeen = false;
  +    int n = getPredicateCount();
   
  -    if (n != 0)
  +    try
       {
  -      try
  +      xctxt.pushSubContextList(this);
  +
  +      for (int i = 0; i < n; i++)
         {
  -        xctxt.pushCurrentNode(context);
  -        xctxt.pushSubContextList(prevStep);
  -        xctxt.pushPredicateRoot(predicateRootContext);
  +        xctxt.pushPredicatePos(i);
   
  -        for (int i = 0; i < n; i++)
  +        try
           {
  -          xctxt.pushPredicatePos(i);
  -          try
  +          XObject pred = m_predicates[i].execute(xctxt);
  +
  +          if (XObject.CLASS_NUMBER == pred.getType())
             {
  -            XObject pred = prevStep.m_predicates[i].execute(xctxt);
  -  
  -            if (XObject.CLASS_NUMBER == pred.getType())
  +            int pos = (int) pred.num();
  +
  +            if (positionAlreadySeen)
  +            {
  +              result = (pos == 1);
  +
  +              break;
  +            }
  +            else
               {
  -              int pos = (int) pred.num();
  -              if (prevStep.getProximityPosition(xctxt, i) != pos)
  +              positionAlreadySeen = true;
  +
  +              if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos))
                 {
  -                score = NodeTest.SCORE_NONE;
  -  
  +                result = false;
  +
                   break;
                 }
               }
  -            else if (!pred.bool())
  -            {
  -              score = NodeTest.SCORE_NONE;
  -  
  -              break;
  -            }
             }
  -          finally
  +          else if (!pred.bool())
             {
  -            xctxt.popPredicatePos();
  +            result = false;
  +
  +            break;
             }
           }
  -      }
  -      finally
  -      {
  -        xctxt.popCurrentNode();
  -        xctxt.popSubContextList();
  -        xctxt.popPredicateRoot();
  +        finally
  +        {
  +          xctxt.popPredicatePos();
  +        }
         }
       }
  +    finally
  +    {
  +      xctxt.popSubContextList();
  +    }
   
  -    return score;
  +    return result;
     }
  -  
  +
  +  /**
  +   * Get the string represenentation of this step for diagnostic purposes.
  +   *
  +   *
  +   * @return A string representation of this step, built by 
reverse-engineering 
  +   * the contained info.
  +   */
     public String toString()
     {
  +
       StringBuffer buf = new StringBuffer();
  -    for(StepPattern pat = this; pat != null; pat = pat.m_relativePathPattern)
  +
  +    for (StepPattern pat = this; pat != null; pat = 
pat.m_relativePathPattern)
       {
  -      if(pat != this)
  +      if (pat != this)
           buf.append("/");
  +
         buf.append(Axis.names[pat.m_axis]);
         buf.append("::");
  -      if(0x000005000 == pat.m_whatToShow)
  +
  +      if (0x000005000 == pat.m_whatToShow)
         {
           buf.append("doc()");
         }
  -      else if(DTMFilter.SHOW_BYFUNCTION == pat.m_whatToShow)
  +      else if (DTMFilter.SHOW_BYFUNCTION == pat.m_whatToShow)
         {
           buf.append("function()");
         }
  -      else if(DTMFilter.SHOW_ALL == pat.m_whatToShow)
  +      else if (DTMFilter.SHOW_ALL == pat.m_whatToShow)
         {
           buf.append("node()");
         }
  -      else if(DTMFilter.SHOW_TEXT == pat.m_whatToShow)
  +      else if (DTMFilter.SHOW_TEXT == pat.m_whatToShow)
         {
           buf.append("text()");
         }
  -      else if(DTMFilter.SHOW_PROCESSING_INSTRUCTION == pat.m_whatToShow)
  +      else if (DTMFilter.SHOW_PROCESSING_INSTRUCTION == pat.m_whatToShow)
         {
           buf.append("processing-instruction(");
  -        if(null != pat.m_name)
  +
  +        if (null != pat.m_name)
           {
             buf.append(pat.m_name);
           }
  +
           buf.append(")");
         }
  -      else if(DTMFilter.SHOW_COMMENT == pat.m_whatToShow)
  +      else if (DTMFilter.SHOW_COMMENT == pat.m_whatToShow)
         {
           buf.append("comment()");
         }
  -      else if(null != pat.m_name)
  +      else if (null != pat.m_name)
         {
  -        if(DTMFilter.SHOW_ATTRIBUTE == pat.m_whatToShow)
  +        if (DTMFilter.SHOW_ATTRIBUTE == pat.m_whatToShow)
           {
             buf.append("@");
           }
  -        if(null != pat.m_namespace)
  +
  +        if (null != pat.m_namespace)
           {
             buf.append("{");
             buf.append(pat.m_namespace);
             buf.append("}");
           }
  +
           buf.append(pat.m_name);
         }
  -      else if(DTMFilter.SHOW_ATTRIBUTE == pat.m_whatToShow)
  +      else if (DTMFilter.SHOW_ATTRIBUTE == pat.m_whatToShow)
         {
           buf.append("@");
         }
  -      else if((DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT) 
  -              == pat.m_whatToShow)
  +      else if ((DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT)
  +               == pat.m_whatToShow)
         {
           buf.append("doc-root()");
         }
         else
         {
  -        buf.append("?"+Integer.toHexString(pat.m_whatToShow));
  +        buf.append("?" + Integer.toHexString(pat.m_whatToShow));
         }
  -      if(null != pat.m_predicates)
  +
  +      if (null != pat.m_predicates)
         {
  -        for (int i = 0; i < pat.m_predicates.length; i++) 
  +        for (int i = 0; i < pat.m_predicates.length; i++)
           {
             buf.append("[");
             buf.append(pat.m_predicates[i]);
             buf.append("]");
           }
  -        
         }
       }
  +
       return buf.toString();
     }
   
  @@ -890,25 +938,27 @@
   
       // return XPath.MATCH_SCORE_NONE;
     }
  -  
  +
  +  /**
  +   * Set the axis that this step should follow. 
  +   *
  +   *
  +   * @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
  +   */
     public void setAxis(int axis)
     {
       m_axis = axis;
     }
  -  
  +
  +  /**
  +   * Get the axis that this step follows. 
  +   *
  +   *
  +   * @return The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
  +   */
     public int getAxis()
     {
       return m_axis;
  -  }
  -  
  -  public void setPredicateAxis(int axisForPredicate)
  -  {
  -    m_axisForPredicate = axisForPredicate;
  -  }
  -  
  -  public int getPredicateAxis()
  -  {
  -    return m_axisForPredicate;
     }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to