14c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/*
24c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
34c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * or more contributor license agreements. See the NOTICE file
44c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * distributed with this work for additional information
54c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * regarding copyright ownership. The ASF licenses this file
64c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
74c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * you may not use this file except in compliance with the License.
84c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * You may obtain a copy of the License at
94c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Unless required by applicable law or agreed to in writing, software
134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * See the License for the specific language governing permissions and
164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * limitations under the License.
174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */
184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/*
194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * $Id: ElemExsltFuncResult.java 468643 2006-10-28 06:56:03Z minchau $
204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */
214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonpackage org.apache.xalan.templates;
224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport javax.xml.transform.TransformerException;
244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xalan.transformer.TransformerImpl;
264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xpath.XPathContext;
274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xpath.objects.XObject;
284c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
294c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/**
304c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Handles the EXSLT result element within an EXSLT function element.
314c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */
324c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonpublic class ElemExsltFuncResult extends ElemVariable
334c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson{
344c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    static final long serialVersionUID = -3478311949388304563L;
354c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /*
364c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * To keep the binary compatibility put those three private global
374c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * variables back, although they are never used in this verison
384c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
394c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    // A flag indicating whether the return result is set
404c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private boolean m_isResultSet = false;
414c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
424c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    // The return result
434c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private XObject m_result = null;
444c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
454c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    // The frame size of the current caller
464c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private int m_callerFrameSize = 0;
474c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
484c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  /**
494c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   * Generate the EXSLT function return value, and assign it to the variable
504c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   * index slot assigned for it in ElemExsltFunction compose().
514c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   *
524c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   */
534c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  public void execute(TransformerImpl transformer) throws TransformerException
544c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  {
554c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    XPathContext context = transformer.getXPathContext();
564c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
574c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    // Verify that result has not already been set by another result
584c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    // element. Recursion is allowed: intermediate results are cleared
594c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    // in the owner ElemExsltFunction execute().
604c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    if (transformer.currentFuncResultSeen()) {
614c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        throw new TransformerException("An EXSLT function cannot set more than one result!");
624c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
634c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
644c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    int sourceNode = context.getCurrentNode();
654c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
664c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    // Set the return value;
674c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    XObject var = getValue(transformer, sourceNode);
684c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    transformer.popCurrentFuncResult();
694c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    transformer.pushCurrentFuncResult(var);
704c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  }
714c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
724c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  /**
734c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   * Get an integer representation of the element type.
744c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   *
754c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   * @return An integer representation of the element, defined in the
764c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   *     Constants class.
774c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   * @see org.apache.xalan.templates.Constants
784c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   */
794c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  public int getXSLToken()
804c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  {
814c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    return Constants.EXSLT_ELEMNAME_FUNCRESULT;
824c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  }
834c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
844c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  /**
854c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   * Return the node name, defined in the
864c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   *     Constants class.
874c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   * @see org.apache.xalan.templates.Constants
884c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   * @return The node name
894c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   *
904c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   */
914c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson   public String getNodeName()
924c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  {
934c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    return Constants.EXSLT_ELEMNAME_FUNCRESULT_STRING;
944c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson  }
954c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson}
96