1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the  "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18/*
19 * $Id: ElemExsltFuncResult.java 468643 2006-10-28 06:56:03Z minchau $
20 */
21package org.apache.xalan.templates;
22
23import javax.xml.transform.TransformerException;
24
25import org.apache.xalan.transformer.TransformerImpl;
26import org.apache.xpath.XPathContext;
27import org.apache.xpath.objects.XObject;
28
29/**
30 * Handles the EXSLT result element within an EXSLT function element.
31 */
32public class ElemExsltFuncResult extends ElemVariable
33{
34    static final long serialVersionUID = -3478311949388304563L;
35    /*
36     * To keep the binary compatibility put those three private global
37     * variables back, although they are never used in this verison
38     */
39    // A flag indicating whether the return result is set
40    private boolean m_isResultSet = false;
41
42    // The return result
43    private XObject m_result = null;
44
45    // The frame size of the current caller
46    private int m_callerFrameSize = 0;
47
48  /**
49   * Generate the EXSLT function return value, and assign it to the variable
50   * index slot assigned for it in ElemExsltFunction compose().
51   *
52   */
53  public void execute(TransformerImpl transformer) throws TransformerException
54  {
55    XPathContext context = transformer.getXPathContext();
56
57    // Verify that result has not already been set by another result
58    // element. Recursion is allowed: intermediate results are cleared
59    // in the owner ElemExsltFunction execute().
60    if (transformer.currentFuncResultSeen()) {
61        throw new TransformerException("An EXSLT function cannot set more than one result!");
62    }
63
64    int sourceNode = context.getCurrentNode();
65
66    // Set the return value;
67    XObject var = getValue(transformer, sourceNode);
68    transformer.popCurrentFuncResult();
69    transformer.pushCurrentFuncResult(var);
70  }
71
72  /**
73   * Get an integer representation of the element type.
74   *
75   * @return An integer representation of the element, defined in the
76   *     Constants class.
77   * @see org.apache.xalan.templates.Constants
78   */
79  public int getXSLToken()
80  {
81    return Constants.EXSLT_ELEMNAME_FUNCRESULT;
82  }
83
84  /**
85   * Return the node name, defined in the
86   *     Constants class.
87   * @see org.apache.xalan.templates.Constants
88   * @return The node name
89   *
90   */
91   public String getNodeName()
92  {
93    return Constants.EXSLT_ELEMNAME_FUNCRESULT_STRING;
94  }
95}
96