xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zong...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xalan/templates ElemExsltFuncResult.java
Date Wed, 11 Feb 2004 20:45:37 GMT
zongaro     2004/02/11 12:45:37

  Modified:    java/src/org/apache/xalan/transformer TransformerImpl.java
               java/src/org/apache/xalan/templates ElemExsltFuncResult.java
  Log:
  Fix for bugzilla bug report 24302.
  
  Fields in the object representing an EXSLT function element (ElemExsltFunction)
  were being used to store execution state information for references to that
  function.  That caused problems with multi-threaded code that used Transformer
  objects created from the same Templates object - each Transformer shares the
  same instances of ElemExsltFunction.
  
  The fix was to replace the fields ElemExsltFunction.m_result and
  ElemExsltFunction.m_isResultSet with a new ObjectStack field in TransformerImpl
  named m_currentFuncResult.
  
  Reviewed by Morris Kwan (mkwan () ca!ibm!com)
  
  Revision  Changes    Path
  1.155     +40 -0     xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
  retrieving revision 1.154
  retrieving revision 1.155
  diff -u -r1.154 -r1.155
  --- TransformerImpl.java	22 Oct 2003 18:45:57 -0000	1.154
  +++ TransformerImpl.java	11 Feb 2004 20:45:37 -0000	1.155
  @@ -313,6 +313,13 @@
     BoolStack m_currentTemplateRuleIsNull = new BoolStack();
   
     /**
  +   * Keeps track of the result delivered by any EXSLT <code>func:result</code>
  +   * instruction that has been executed for the currently active EXSLT
  +   * <code>func:function</code>
  +   */
  +  ObjectStack m_currentFuncResult = new ObjectStack();
  +  
  +  /**
      * The message manager, which manages error messages, warning
      * messages, and other types of message events.   
      */
  @@ -3008,6 +3015,39 @@
     public void popCurrentTemplateRuleIsNull()
     {
       m_currentTemplateRuleIsNull.pop();
  +  }
  +
  +  /**
  +   * Push a funcion result for the currently active EXSLT
  +   * <code>func:function</code>.
  +   * 
  +   * @param val the result of executing an EXSLT
  +   * <code>func:result</code> instruction for the current
  +   * <code>func:function</code>.
  +   */
  +  public void pushCurrentFuncResult(Object val) {
  +    m_currentFuncResult.push(val);
  +  }
  +
  +  /**
  +   * Pops the result of the currently active EXSLT <code>func:function</code>.
  +   * 
  +   * @return the value of the <code>func:function</code>
  +   */
  +  public Object popCurrentFuncResult() {
  +    return m_currentFuncResult.pop();
  +  }
  +
  +  /**
  +   * Determines whether an EXSLT <code>func:result</code> instruction has been
  +   * executed for the currently active EXSLT <code>func:function</code>.
  +   * 
  +   * @return <code>true</code> if and only if a <code>func:result</code>
  +   * instruction has been executed
  +   */
  +  public boolean currentFuncResultSeen() {
  +    return !m_currentFuncResult.empty()
  +               && m_currentFuncResult.peek() != null;
     }
   
     /**
  
  
  
  1.8       +11 -28    xml-xalan/java/src/org/apache/xalan/templates/ElemExsltFuncResult.java
  
  Index: ElemExsltFuncResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemExsltFuncResult.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ElemExsltFuncResult.java	22 Oct 2003 17:38:45 -0000	1.7
  +++ ElemExsltFuncResult.java	11 Feb 2004 20:45:37 -0000	1.8
  @@ -76,28 +76,26 @@
     public void execute(TransformerImpl transformer) throws TransformerException
     {    
       XPathContext context = transformer.getXPathContext();
  -    ElemExsltFunction owner = getOwnerFunction();
   
       if (TransformerImpl.S_DEBUG)
         transformer.getTraceManager().fireTraceEvent(this);
       
  -    if (owner != null)
  -    {
  -      // Verify that result has not already been set by another result
  -      // element. Recursion is allowed: intermediate results are cleared 
  -      // in the owner ElemExsltFunction execute().
  -      if (owner.isResultSet())
  +    // Verify that result has not already been set by another result
  +    // element. Recursion is allowed: intermediate results are cleared 
  +    // in the owner ElemExsltFunction execute().
  +    if (transformer.currentFuncResultSeen()) {
           throw new TransformerException("An EXSLT function cannot set more than one result!");
  -      
  -      int sourceNode = context.getCurrentNode();
  -      // Set the return value;
  -      XObject var = getValue(transformer, sourceNode);
  -      owner.setResult(var);
       }
   
  +    int sourceNode = context.getCurrentNode();
  +
  +    // Set the return value;
  +    XObject var = getValue(transformer, sourceNode);
  +    transformer.popCurrentFuncResult();
  +    transformer.pushCurrentFuncResult(var);
  +
       if (TransformerImpl.S_DEBUG)
         transformer.getTraceManager().fireTraceEndEvent(this);    
  -    
     }
   
     /**
  @@ -123,19 +121,4 @@
     {
       return Constants.EXSLT_ELEMNAME_FUNCRESULT_STRING;
     }
  -  
  -  /**
  -   * Get the ElemExsltFunction that contains the ElemResult so we can set an ElemExsltFunction
variable
  -   * to the local variable stack index to the return value.
  -   */
  -  public ElemExsltFunction getOwnerFunction()
  -  {
  -  	ElemTemplateElement elem = this;
  -  	while((elem != null) && !(elem instanceof ElemExsltFunction))
  -  	{
  -    	elem = elem.getParentElem();
  -  	}
  -  	return (ElemExsltFunction)elem;
  -  }
  -  
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message