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: ElemParam.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.VariableStack;
027    import org.apache.xpath.objects.XObject;
028    
029    /**
030     * Implement xsl:param.
031     * <pre>
032     * <!ELEMENT xsl:param %template;>
033     * <!ATTLIST xsl:param
034     *   name %qname; #REQUIRED
035     *   select %expr; #IMPLIED
036     * >
037     * </pre>
038     * @see <a href="http://www.w3.org/TR/xslt#variables">variables in XSLT Specification</a>
039     * @xsl.usage advanced
040     */
041    public class ElemParam extends ElemVariable
042    {
043        static final long serialVersionUID = -1131781475589006431L;
044      int m_qnameID;
045    
046      /**
047       * Constructor ElemParam
048       *
049       */
050      public ElemParam(){}
051    
052      /**
053       * Get an int constant identifying the type of element.
054       * @see org.apache.xalan.templates.Constants
055       *
056       * @return The token ID of the element
057       */
058      public int getXSLToken()
059      {
060        return Constants.ELEMNAME_PARAMVARIABLE;
061      }
062    
063      /**
064       * Return the node name.
065       *
066       * @return The element's name
067       */
068      public String getNodeName()
069      {
070        return Constants.ELEMNAME_PARAMVARIABLE_STRING;
071      }
072    
073      /**
074       * Copy constructor.
075       *
076       * @param param Element from an xsl:param
077       *
078       * @throws TransformerException
079       */
080      public ElemParam(ElemParam param) throws TransformerException
081      {
082        super(param);
083      }
084    
085      /**
086       * This function is called after everything else has been
087       * recomposed, and allows the template to set remaining
088       * values that may be based on some other property that
089       * depends on recomposition.
090       */
091      public void compose(StylesheetRoot sroot) throws TransformerException
092      {
093        super.compose(sroot);
094        m_qnameID = sroot.getComposeState().getQNameID(m_qname);
095        int parentToken = m_parentNode.getXSLToken();
096        if (parentToken == Constants.ELEMNAME_TEMPLATE
097            || parentToken == Constants.EXSLT_ELEMNAME_FUNCTION)
098          ((ElemTemplate)m_parentNode).m_inArgsSize++;
099      }
100      
101      /**
102       * Execute a variable declaration and push it onto the variable stack.
103       * @see <a href="http://www.w3.org/TR/xslt#variables">variables in XSLT Specification</a>
104       *
105       * @param transformer non-null reference to the the current transform-time state.
106       *
107       * @throws TransformerException
108       */
109      public void execute(TransformerImpl transformer) throws TransformerException
110      {
111        if (transformer.getDebug())
112          transformer.getTraceManager().fireTraceEvent(this);
113          
114        VariableStack vars = transformer.getXPathContext().getVarStack();
115        
116        if(!vars.isLocalSet(m_index))
117        {
118    
119          int sourceNode = transformer.getXPathContext().getCurrentNode();
120          XObject var = getValue(transformer, sourceNode);
121      
122          // transformer.getXPathContext().getVarStack().pushVariable(m_qname, var);
123          transformer.getXPathContext().getVarStack().setLocalVariable(m_index, var);
124        }
125        
126        if (transformer.getDebug())
127          transformer.getTraceManager().fireTraceEndEvent(this);
128      }
129      
130    }