KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > ElemParam


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ElemParam.java,v 1.17 2004/02/16 20:32:32 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22
23 import org.apache.xalan.transformer.TransformerImpl;
24 import org.apache.xpath.VariableStack;
25 import org.apache.xpath.objects.XObject;
26
27 /**
28  * Implement xsl:param.
29  * <pre>
30  * <!ELEMENT xsl:param %template;>
31  * <!ATTLIST xsl:param
32  * name %qname; #REQUIRED
33  * select %expr; #IMPLIED
34  * >
35  * </pre>
36  * @see <a HREF="http://www.w3.org/TR/xslt#variables">variables in XSLT Specification</a>
37  * @xsl.usage advanced
38  */

39 public class ElemParam extends ElemVariable
40 {
41   int m_qnameID;
42
43   /**
44    * Constructor ElemParam
45    *
46    */

47   public ElemParam(){}
48
49   /**
50    * Get an int constant identifying the type of element.
51    * @see org.apache.xalan.templates.Constants
52    *
53    * @return The token ID of the element
54    */

55   public int getXSLToken()
56   {
57     return Constants.ELEMNAME_PARAMVARIABLE;
58   }
59
60   /**
61    * Return the node name.
62    *
63    * @return The element's name
64    */

65   public String JavaDoc getNodeName()
66   {
67     return Constants.ELEMNAME_PARAMVARIABLE_STRING;
68   }
69
70   /**
71    * Copy constructor.
72    *
73    * @param param Element from an xsl:param
74    *
75    * @throws TransformerException
76    */

77   public ElemParam(ElemParam param) throws TransformerException JavaDoc
78   {
79     super(param);
80   }
81
82   /**
83    * This function is called after everything else has been
84    * recomposed, and allows the template to set remaining
85    * values that may be based on some other property that
86    * depends on recomposition.
87    */

88   public void compose(StylesheetRoot sroot) throws TransformerException JavaDoc
89   {
90     super.compose(sroot);
91     m_qnameID = sroot.getComposeState().getQNameID(m_qname);
92     int parentToken = m_parentNode.getXSLToken();
93     if (parentToken == Constants.ELEMNAME_TEMPLATE
94         || parentToken == Constants.EXSLT_ELEMNAME_FUNCTION)
95       ((ElemTemplate)m_parentNode).m_inArgsSize++;
96   }
97   
98   /**
99    * Execute a variable declaration and push it onto the variable stack.
100    * @see <a HREF="http://www.w3.org/TR/xslt#variables">variables in XSLT Specification</a>
101    *
102    * @param transformer non-null reference to the the current transform-time state.
103    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
104    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
105    *
106    * @throws TransformerException
107    */

108   public void execute(TransformerImpl transformer) throws TransformerException JavaDoc
109   {
110     if (TransformerImpl.S_DEBUG)
111       transformer.getTraceManager().fireTraceEvent(this);
112       
113     VariableStack vars = transformer.getXPathContext().getVarStack();
114     
115     if(!vars.isLocalSet(m_index))
116     {
117
118       int sourceNode = transformer.getXPathContext().getCurrentNode();
119       XObject var = getValue(transformer, sourceNode);
120   
121       // transformer.getXPathContext().getVarStack().pushVariable(m_qname, var);
122
transformer.getXPathContext().getVarStack().setLocalVariable(m_index, var);
123     }
124     
125     if (TransformerImpl.S_DEBUG)
126       transformer.getTraceManager().fireTraceEndEvent(this);
127   }
128   
129 }
130
Popular Tags