minchau     2004/02/18 07:47:39

  Modified:    java/src/org/apache/xalan/templates ElemForEach.java
  Log:
  
  PR: bugzilla 16889
  Submitted by: Elson Jiang
  Reviewed by:  Brian Minchau
  
  Fixes ElemForEach TraceListener bug.
  
  Revision  Changes    Path
  1.38      +41 -8     
xml-xalan/java/src/org/apache/xalan/templates/ElemForEach.java
  
  Index: ElemForEach.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemForEach.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- ElemForEach.java  17 Feb 2004 22:15:52 -0000      1.37
  +++ ElemForEach.java  18 Feb 2004 15:47:39 -0000      1.38
  @@ -78,6 +78,13 @@
      * @serial
      */
     protected Expression m_selectExpression = null;
  +  
  +  
  +  /**
  +   * Used to fix bug#16889
  +   * Store XPath away for later processing.
  +   */
  +  protected XPath m_xpath = null;  
   
     /**
      * Set the "select" attribute.
  @@ -87,6 +94,10 @@
     public void setSelect(XPath xpath)
     {
       m_selectExpression = xpath.getExpression();
  +    
  +    // The following line is part of the codes added to fix bug#16889
  +    // Store xpath which will be needed when firing Selected Event
  +    m_xpath = xpath;    
     }
   
     /**
  @@ -241,7 +252,7 @@
   
       transformer.pushCurrentTemplateRuleIsNull(true);    
       if (TransformerImpl.S_DEBUG)
  -      transformer.getTraceManager().fireTraceEvent(this);
  +      transformer.getTraceManager().fireTraceEvent(this);//trigger for-each 
element event
   
       try
       {
  @@ -330,12 +341,34 @@
         if (null != keys)
           sourceNodes = sortNodes(xctxt, keys, sourceNodes);
   
  -      if (TransformerImpl.S_DEBUG)
  -      {
  -        transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
  -                "select", new XPath(m_selectExpression),
  -                new org.apache.xpath.objects.XNodeSet(sourceNodes));
  -      }
  +    if (TransformerImpl.S_DEBUG)
  +    {
  +
  +        // The original code, which is broken for bug#16889,
  +        // which fails to get the original select expression in the select 
event. 
  +        /*  transformer.getTraceManager().fireSelectedEvent(
  +         *    sourceNode,
  +         *            this,
  +         *            "select",
  +         *            new XPath(m_selectExpression),
  +         *            new org.apache.xpath.objects.XNodeSet(sourceNodes));
  +         */ 
  +
  +        // The following code fixes bug#16889
  +        // Solution: Store away XPath in setSelect(Xath), and use it here.
  +        // Pass m_xath, which the current node is associated with, onto the 
TraceManager.
  +        
  +        Expression expr = m_xpath.getExpression();
  +        org.apache.xpath.objects.XObject xObject = expr.execute(xctxt);
  +        int current = xctxt.getCurrentNode();
  +        transformer.getTraceManager().fireSelectedEvent(
  +            current,
  +            this,
  +            "select",
  +            m_xpath,
  +            xObject);
  +    }
  +
   
   
         xctxt.pushCurrentNode(DTM.NULL);
  
  
  

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

Reply via email to