001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: ElemExsltFuncResult.java 468643 2006-10-28 06:56:03Z minchau $
020     */
021    package org.apache.xalan.templates;
022    
023    import javax.xml.transform.TransformerException;
024    
025    import org.apache.xalan.transformer.TransformerImpl;
026    import org.apache.xpath.XPathContext;
027    import org.apache.xpath.objects.XObject;
028    
029    /**
030     * Handles the EXSLT result element within an EXSLT function element.
031     */
032    public class ElemExsltFuncResult extends ElemVariable
033    {
034        static final long serialVersionUID = -3478311949388304563L;
035        /*
036         * To keep the binary compatibility put those three private global 
037         * variables back, although they are never used in this verison
038         */
039        // A flag indicating whether the return result is set
040        private boolean m_isResultSet = false;
041      
042        // The return result
043        private XObject m_result = null;
044      
045        // The frame size of the current caller
046        private int m_callerFrameSize = 0;
047     
048      /**
049       * Generate the EXSLT function return value, and assign it to the variable
050       * index slot assigned for it in ElemExsltFunction compose().
051       * 
052       */
053      public void execute(TransformerImpl transformer) throws TransformerException
054      {    
055        XPathContext context = transformer.getXPathContext();
056    
057        if (transformer.getDebug())
058          transformer.getTraceManager().fireTraceEvent(this);
059        
060        // Verify that result has not already been set by another result
061        // element. Recursion is allowed: intermediate results are cleared 
062        // in the owner ElemExsltFunction execute().
063        if (transformer.currentFuncResultSeen()) {
064            throw new TransformerException("An EXSLT function cannot set more than one result!");
065        }
066    
067        int sourceNode = context.getCurrentNode();
068    
069        // Set the return value;
070        XObject var = getValue(transformer, sourceNode);
071        transformer.popCurrentFuncResult();
072        transformer.pushCurrentFuncResult(var);
073    
074        if (transformer.getDebug())
075          transformer.getTraceManager().fireTraceEndEvent(this);    
076      }
077    
078      /**
079       * Get an integer representation of the element type.
080       *
081       * @return An integer representation of the element, defined in the
082       *     Constants class.
083       * @see org.apache.xalan.templates.Constants
084       */
085      public int getXSLToken()
086      {
087        return Constants.EXSLT_ELEMNAME_FUNCRESULT;
088      }
089      
090      /**
091       * Return the node name, defined in the
092       *     Constants class.
093       * @see org.apache.xalan.templates.Constants
094       * @return The node name
095       * 
096       */
097       public String getNodeName()
098      {
099        return Constants.EXSLT_ELEMNAME_FUNCRESULT_STRING;
100      }
101    }