KickJava   Java API By Example, From Geeks To Geeks.

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


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: KeyDeclaration.java,v 1.13 2004/02/16 20:32:33 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import org.apache.xml.utils.QName;
22 import org.apache.xpath.XPath;
23
24 /**
25  * Holds the attribute declarations for the xsl:keys element.
26  * A stylesheet declares a set of keys for each document using
27  * the xsl:key element. When this set of keys contains a member
28  * with node x, name y and value z, we say that node x has a key
29  * with name y and value z.
30  * @see <a HREF="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
31  * @xsl.usage internal
32  */

33 public class KeyDeclaration extends ElemTemplateElement
34 {
35
36   /**
37    * Constructs a new element representing the xsl:key. The parameters
38    * are needed to prioritize this key element as part of the recomposing
39    * process. For this element, they are not automatically created
40    * because the element is never added on to the stylesheet parent.
41    */

42   public KeyDeclaration(Stylesheet parentNode, int docOrderNumber)
43   {
44     m_parentNode = parentNode;
45     setUid(docOrderNumber);
46   }
47
48   /**
49    * The "name" property.
50    * @serial
51    */

52   private QName m_name;
53
54   /**
55    * Set the "name" attribute.
56    * The name attribute specifies the name of the key. The value
57    * of the name attribute is a QName, which is expanded as
58    * described in [2.4 Qualified Names].
59    *
60    * @param name Value to set for the "name" attribute.
61    */

62   public void setName(QName name)
63   {
64     m_name = name;
65   }
66
67   /**
68    * Get the "name" attribute.
69    * The name attribute specifies the name of the key. The value
70    * of the name attribute is a QName, which is expanded as
71    * described in [2.4 Qualified Names].
72    *
73    * @return Value of the "name" attribute.
74    */

75   public QName getName()
76   {
77     return m_name;
78   }
79   
80   /**
81    * Return the node name.
82    *
83    * @return the element's name
84    */

85   public String JavaDoc getNodeName()
86   {
87     return Constants.ELEMNAME_KEY_STRING;
88   }
89
90
91   /**
92    * The "match" attribute.
93    * @serial
94    */

95   private XPath m_matchPattern = null;
96
97   /**
98    * Set the "match" attribute.
99    * The match attribute is a Pattern; an xsl:key element gives
100    * information about the keys of any node that matches the
101    * pattern specified in the match attribute.
102    * @see <a HREF="http://www.w3.org/TR/xslt#patterns">patterns in XSLT Specification</a>
103    *
104    * @param v Value to set for the "match" attribute.
105    */

106   public void setMatch(XPath v)
107   {
108     m_matchPattern = v;
109   }
110
111   /**
112    * Get the "match" attribute.
113    * The match attribute is a Pattern; an xsl:key element gives
114    * information about the keys of any node that matches the
115    * pattern specified in the match attribute.
116    * @see <a HREF="http://www.w3.org/TR/xslt#patterns">patterns in XSLT Specification</a>
117    *
118    * @return Value of the "match" attribute.
119    */

120   public XPath getMatch()
121   {
122     return m_matchPattern;
123   }
124
125   /**
126    * The "use" attribute.
127    * @serial
128    */

129   private XPath m_use;
130
131   /**
132    * Set the "use" attribute.
133    * The use attribute is an expression specifying the values
134    * of the key; the expression is evaluated once for each node
135    * that matches the pattern.
136    *
137    * @param v Value to set for the "use" attribute.
138    */

139   public void setUse(XPath v)
140   {
141     m_use = v;
142   }
143
144   /**
145    * Get the "use" attribute.
146    * The use attribute is an expression specifying the values
147    * of the key; the expression is evaluated once for each node
148    * that matches the pattern.
149    *
150    * @return Value of the "use" attribute.
151    */

152   public XPath getUse()
153   {
154     return m_use;
155   }
156   
157   /**
158    * Get an int constant identifying the type of element.
159    * @see org.apache.xalan.templates.Constants
160    *
161    * @return The token ID for this element
162    */

163   public int getXSLToken()
164   {
165     return Constants.ELEMNAME_KEY;
166   }
167   
168   /**
169    * This function is called after everything else has been
170    * recomposed, and allows the template to set remaining
171    * values that may be based on some other property that
172    * depends on recomposition.
173    */

174   public void compose(StylesheetRoot sroot)
175     throws javax.xml.transform.TransformerException JavaDoc
176   {
177     super.compose(sroot);
178     java.util.Vector JavaDoc vnames = sroot.getComposeState().getVariableNames();
179     if(null != m_matchPattern)
180       m_matchPattern.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
181     if(null != m_use)
182       m_use.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
183   }
184
185   /**
186    * This function is called during recomposition to
187    * control how this element is composed.
188    * @param root The root stylesheet for this transformation.
189    */

190   public void recompose(StylesheetRoot root)
191   {
192     root.recomposeKeys(this);
193   }
194
195 }
196
Popular Tags