Home | History | Annotate | Download | only in templates
      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: ElemParam.java 468643 2006-10-28 06:56:03Z minchau $
     20  */
     21 package org.apache.xalan.templates;
     22 
     23 import javax.xml.transform.TransformerException;
     24 
     25 import org.apache.xalan.transformer.TransformerImpl;
     26 import org.apache.xpath.VariableStack;
     27 import org.apache.xpath.objects.XObject;
     28 
     29 /**
     30  * Implement xsl:param.
     31  * <pre>
     32  * <!ELEMENT xsl:param %template;>
     33  * <!ATTLIST xsl:param
     34  *   name %qname; #REQUIRED
     35  *   select %expr; #IMPLIED
     36  * >
     37  * </pre>
     38  * @see <a href="http://www.w3.org/TR/xslt#variables">variables in XSLT Specification</a>
     39  * @xsl.usage advanced
     40  */
     41 public class ElemParam extends ElemVariable
     42 {
     43     static final long serialVersionUID = -1131781475589006431L;
     44   int m_qnameID;
     45 
     46   /**
     47    * Constructor ElemParam
     48    *
     49    */
     50   public ElemParam(){}
     51 
     52   /**
     53    * Get an int constant identifying the type of element.
     54    * @see org.apache.xalan.templates.Constants
     55    *
     56    * @return The token ID of the element
     57    */
     58   public int getXSLToken()
     59   {
     60     return Constants.ELEMNAME_PARAMVARIABLE;
     61   }
     62 
     63   /**
     64    * Return the node name.
     65    *
     66    * @return The element's name
     67    */
     68   public String getNodeName()
     69   {
     70     return Constants.ELEMNAME_PARAMVARIABLE_STRING;
     71   }
     72 
     73   /**
     74    * Copy constructor.
     75    *
     76    * @param param Element from an xsl:param
     77    *
     78    * @throws TransformerException
     79    */
     80   public ElemParam(ElemParam param) throws TransformerException
     81   {
     82     super(param);
     83   }
     84 
     85   /**
     86    * This function is called after everything else has been
     87    * recomposed, and allows the template to set remaining
     88    * values that may be based on some other property that
     89    * depends on recomposition.
     90    */
     91   public void compose(StylesheetRoot sroot) throws TransformerException
     92   {
     93     super.compose(sroot);
     94     m_qnameID = sroot.getComposeState().getQNameID(m_qname);
     95     int parentToken = m_parentNode.getXSLToken();
     96     if (parentToken == Constants.ELEMNAME_TEMPLATE
     97         || parentToken == Constants.EXSLT_ELEMNAME_FUNCTION)
     98       ((ElemTemplate)m_parentNode).m_inArgsSize++;
     99   }
    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     VariableStack vars = transformer.getXPathContext().getVarStack();
    112 
    113     if(!vars.isLocalSet(m_index))
    114     {
    115 
    116       int sourceNode = transformer.getXPathContext().getCurrentNode();
    117       XObject var = getValue(transformer, sourceNode);
    118 
    119       // transformer.getXPathContext().getVarStack().pushVariable(m_qname, var);
    120       transformer.getXPathContext().getVarStack().setLocalVariable(m_index, var);
    121     }
    122   }
    123 
    124 }
    125