KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xpath > internal > compiler > Keywords


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: Keywords.java,v 1.10 2004/02/17 04:32:48 minchau Exp $
18  */

19 package com.sun.org.apache.xpath.internal.compiler;
20
21 import java.util.Hashtable JavaDoc;
22
23 /**
24  * Table of strings to operation code lookups.
25  * @xsl.usage internal
26  */

27 public class Keywords
28 {
29
30   /** Table of keywords to opcode associations. */
31   static Hashtable JavaDoc m_keywords = new Hashtable JavaDoc();
32
33   /** Table of axes names to opcode associations. */
34   static Hashtable JavaDoc m_axisnames = new Hashtable JavaDoc();
35
36   /** Table of function name to function ID associations. */
37   static Hashtable JavaDoc m_functions = new Hashtable JavaDoc();
38
39   /** Table of node type strings to opcode associations. */
40   static Hashtable JavaDoc m_nodetypes = new Hashtable JavaDoc();
41
42   /** ancestor axes string. */
43   private static final String JavaDoc FROM_ANCESTORS_STRING = "ancestor";
44
45   /** ancestor-or-self axes string. */
46   private static final String JavaDoc FROM_ANCESTORS_OR_SELF_STRING =
47     "ancestor-or-self";
48
49   /** attribute axes string. */
50   private static final String JavaDoc FROM_ATTRIBUTES_STRING = "attribute";
51
52   /** child axes string. */
53   private static final String JavaDoc FROM_CHILDREN_STRING = "child";
54
55   /** descendant-or-self axes string. */
56   private static final String JavaDoc FROM_DESCENDANTS_STRING = "descendant";
57
58   /** ancestor axes string. */
59   private static final String JavaDoc FROM_DESCENDANTS_OR_SELF_STRING =
60     "descendant-or-self";
61
62   /** following axes string. */
63   private static final String JavaDoc FROM_FOLLOWING_STRING = "following";
64
65   /** following-sibling axes string. */
66   private static final String JavaDoc FROM_FOLLOWING_SIBLINGS_STRING =
67     "following-sibling";
68
69   /** parent axes string. */
70   private static final String JavaDoc FROM_PARENT_STRING = "parent";
71
72   /** preceding axes string. */
73   private static final String JavaDoc FROM_PRECEDING_STRING = "preceding";
74
75   /** preceding-sibling axes string. */
76   private static final String JavaDoc FROM_PRECEDING_SIBLINGS_STRING =
77     "preceding-sibling";
78
79   /** self axes string. */
80   private static final String JavaDoc FROM_SELF_STRING = "self";
81
82   /** namespace axes string. */
83   private static final String JavaDoc FROM_NAMESPACE_STRING = "namespace";
84
85   /** self axes abreviated string. */
86   private static final String JavaDoc FROM_SELF_ABBREVIATED_STRING = ".";
87
88   /** comment node test string. */
89   private static final String JavaDoc NODETYPE_COMMENT_STRING = "comment";
90
91   /** text node test string. */
92   private static final String JavaDoc NODETYPE_TEXT_STRING = "text";
93
94   /** processing-instruction node test string. */
95   private static final String JavaDoc NODETYPE_PI_STRING = "processing-instruction";
96
97   /** Any node test string. */
98   private static final String JavaDoc NODETYPE_NODE_STRING = "node";
99
100   /** Wildcard element string. */
101   private static final String JavaDoc NODETYPE_ANYELEMENT_STRING = "*";
102
103   /** current function string. */
104   private static final String JavaDoc FUNC_CURRENT_STRING = "current";
105
106   /** last function string. */
107   private static final String JavaDoc FUNC_LAST_STRING = "last";
108
109   /** position function string. */
110   private static final String JavaDoc FUNC_POSITION_STRING = "position";
111
112   /** count function string. */
113   private static final String JavaDoc FUNC_COUNT_STRING = "count";
114
115   /** id function string. */
116   static final String JavaDoc FUNC_ID_STRING = "id";
117
118   /** key function string (XSLT). */
119   public static final String JavaDoc FUNC_KEY_STRING = "key";
120
121   /** local-name function string. */
122   private static final String JavaDoc FUNC_LOCAL_PART_STRING = "local-name";
123
124   /** namespace-uri function string. */
125   private static final String JavaDoc FUNC_NAMESPACE_STRING = "namespace-uri";
126
127   /** name function string. */
128   private static final String JavaDoc FUNC_NAME_STRING = "name";
129
130   /** generate-id function string (XSLT). */
131   private static final String JavaDoc FUNC_GENERATE_ID_STRING = "generate-id";
132
133   /** not function string. */
134   private static final String JavaDoc FUNC_NOT_STRING = "not";
135
136   /** true function string. */
137   private static final String JavaDoc FUNC_TRUE_STRING = "true";
138
139   /** false function string. */
140   private static final String JavaDoc FUNC_FALSE_STRING = "false";
141
142   /** boolean function string. */
143   private static final String JavaDoc FUNC_BOOLEAN_STRING = "boolean";
144
145   /** lang function string. */
146   private static final String JavaDoc FUNC_LANG_STRING = "lang";
147
148   /** number function string. */
149   private static final String JavaDoc FUNC_NUMBER_STRING = "number";
150
151   /** floor function string. */
152   private static final String JavaDoc FUNC_FLOOR_STRING = "floor";
153
154   /** ceiling function string. */
155   private static final String JavaDoc FUNC_CEILING_STRING = "ceiling";
156
157   /** round function string. */
158   private static final String JavaDoc FUNC_ROUND_STRING = "round";
159
160   /** sum function string. */
161   private static final String JavaDoc FUNC_SUM_STRING = "sum";
162
163   /** string function string. */
164   private static final String JavaDoc FUNC_STRING_STRING = "string";
165
166   /** starts-with function string. */
167   private static final String JavaDoc FUNC_STARTS_WITH_STRING = "starts-with";
168
169   /** contains function string. */
170   private static final String JavaDoc FUNC_CONTAINS_STRING = "contains";
171
172   /** substring-before function string. */
173   private static final String JavaDoc FUNC_SUBSTRING_BEFORE_STRING =
174     "substring-before";
175
176   /** substring-after function string. */
177   private static final String JavaDoc FUNC_SUBSTRING_AFTER_STRING = "substring-after";
178
179   /** normalize-space function string. */
180   private static final String JavaDoc FUNC_NORMALIZE_SPACE_STRING = "normalize-space";
181
182   /** translate function string. */
183   private static final String JavaDoc FUNC_TRANSLATE_STRING = "translate";
184
185   /** concat function string. */
186   private static final String JavaDoc FUNC_CONCAT_STRING = "concat";
187
188   /** system-property function string. */
189   private static final String JavaDoc FUNC_SYSTEM_PROPERTY_STRING = "system-property";
190
191   /** function-available function string (XSLT). */
192   private static final String JavaDoc FUNC_EXT_FUNCTION_AVAILABLE_STRING =
193     "function-available";
194
195   /** element-available function string (XSLT). */
196   private static final String JavaDoc FUNC_EXT_ELEM_AVAILABLE_STRING =
197     "element-available";
198
199   /** substring function string. */
200   private static final String JavaDoc FUNC_SUBSTRING_STRING = "substring";
201
202   /** string-length function string. */
203   private static final String JavaDoc FUNC_STRING_LENGTH_STRING = "string-length";
204
205   /** unparsed-entity-uri function string (XSLT). */
206   private static final String JavaDoc FUNC_UNPARSED_ENTITY_URI_STRING =
207     "unparsed-entity-uri";
208
209   // Proprietary, built in functions
210

211   /** current function string (Proprietary). */
212   private static final String JavaDoc FUNC_DOCLOCATION_STRING = "document-location";
213
214   static
215   {
216     m_axisnames.put(FROM_ANCESTORS_STRING,
217                     new Integer JavaDoc(OpCodes.FROM_ANCESTORS));
218     m_axisnames.put(FROM_ANCESTORS_OR_SELF_STRING,
219                     new Integer JavaDoc(OpCodes.FROM_ANCESTORS_OR_SELF));
220     m_axisnames.put(FROM_ATTRIBUTES_STRING,
221                     new Integer JavaDoc(OpCodes.FROM_ATTRIBUTES));
222     m_axisnames.put(FROM_CHILDREN_STRING,
223                     new Integer JavaDoc(OpCodes.FROM_CHILDREN));
224     m_axisnames.put(FROM_DESCENDANTS_STRING,
225                     new Integer JavaDoc(OpCodes.FROM_DESCENDANTS));
226     m_axisnames.put(FROM_DESCENDANTS_OR_SELF_STRING,
227                     new Integer JavaDoc(OpCodes.FROM_DESCENDANTS_OR_SELF));
228     m_axisnames.put(FROM_FOLLOWING_STRING,
229                     new Integer JavaDoc(OpCodes.FROM_FOLLOWING));
230     m_axisnames.put(FROM_FOLLOWING_SIBLINGS_STRING,
231                     new Integer JavaDoc(OpCodes.FROM_FOLLOWING_SIBLINGS));
232     m_axisnames.put(FROM_PARENT_STRING,
233                     new Integer JavaDoc(OpCodes.FROM_PARENT));
234     m_axisnames.put(FROM_PRECEDING_STRING,
235                     new Integer JavaDoc(OpCodes.FROM_PRECEDING));
236     m_axisnames.put(FROM_PRECEDING_SIBLINGS_STRING,
237                     new Integer JavaDoc(OpCodes.FROM_PRECEDING_SIBLINGS));
238     m_axisnames.put(FROM_SELF_STRING,
239                     new Integer JavaDoc(OpCodes.FROM_SELF));
240     m_axisnames.put(FROM_NAMESPACE_STRING,
241                     new Integer JavaDoc(OpCodes.FROM_NAMESPACE));
242     m_nodetypes.put(NODETYPE_COMMENT_STRING,
243                     new Integer JavaDoc(OpCodes.NODETYPE_COMMENT));
244     m_nodetypes.put(NODETYPE_TEXT_STRING,
245                     new Integer JavaDoc(OpCodes.NODETYPE_TEXT));
246     m_nodetypes.put(NODETYPE_PI_STRING,
247                     new Integer JavaDoc(OpCodes.NODETYPE_PI));
248     m_nodetypes.put(NODETYPE_NODE_STRING,
249                     new Integer JavaDoc(OpCodes.NODETYPE_NODE));
250     m_nodetypes.put(NODETYPE_ANYELEMENT_STRING,
251                     new Integer JavaDoc(OpCodes.NODETYPE_ANYELEMENT));
252     m_keywords.put(FROM_SELF_ABBREVIATED_STRING,
253                    new Integer JavaDoc(OpCodes.FROM_SELF));
254     m_keywords.put(FUNC_ID_STRING,
255                    new Integer JavaDoc(FunctionTable.FUNC_ID));
256     m_keywords.put(FUNC_KEY_STRING,
257                    new Integer JavaDoc(FunctionTable.FUNC_KEY));
258     m_functions.put(FUNC_CURRENT_STRING,
259                     new Integer JavaDoc(FunctionTable.FUNC_CURRENT));
260     m_functions.put(FUNC_LAST_STRING,
261                     new Integer JavaDoc(FunctionTable.FUNC_LAST));
262     m_functions.put(FUNC_POSITION_STRING,
263                     new Integer JavaDoc(FunctionTable.FUNC_POSITION));
264     m_functions.put(FUNC_COUNT_STRING,
265                     new Integer JavaDoc(FunctionTable.FUNC_COUNT));
266     m_functions.put(FUNC_ID_STRING,
267                     new Integer JavaDoc(FunctionTable.FUNC_ID));
268     m_functions.put(FUNC_KEY_STRING,
269                     new Integer JavaDoc(FunctionTable.FUNC_KEY));
270     m_functions.put(FUNC_LOCAL_PART_STRING,
271                     new Integer JavaDoc(FunctionTable.FUNC_LOCAL_PART));
272     m_functions.put(FUNC_NAMESPACE_STRING,
273                     new Integer JavaDoc(FunctionTable.FUNC_NAMESPACE));
274     m_functions.put(FUNC_NAME_STRING,
275                     new Integer JavaDoc(FunctionTable.FUNC_QNAME));
276     m_functions.put(FUNC_GENERATE_ID_STRING,
277                     new Integer JavaDoc(FunctionTable.FUNC_GENERATE_ID));
278     m_functions.put(FUNC_NOT_STRING,
279                     new Integer JavaDoc(FunctionTable.FUNC_NOT));
280     m_functions.put(FUNC_TRUE_STRING,
281                     new Integer JavaDoc(FunctionTable.FUNC_TRUE));
282     m_functions.put(FUNC_FALSE_STRING,
283                     new Integer JavaDoc(FunctionTable.FUNC_FALSE));
284     m_functions.put(FUNC_BOOLEAN_STRING,
285                     new Integer JavaDoc(FunctionTable.FUNC_BOOLEAN));
286     m_functions.put(FUNC_LANG_STRING,
287                     new Integer JavaDoc(FunctionTable.FUNC_LANG));
288     m_functions.put(FUNC_NUMBER_STRING,
289                     new Integer JavaDoc(FunctionTable.FUNC_NUMBER));
290     m_functions.put(FUNC_FLOOR_STRING,
291                     new Integer JavaDoc(FunctionTable.FUNC_FLOOR));
292     m_functions.put(FUNC_CEILING_STRING,
293                     new Integer JavaDoc(FunctionTable.FUNC_CEILING));
294     m_functions.put(FUNC_ROUND_STRING,
295                     new Integer JavaDoc(FunctionTable.FUNC_ROUND));
296     m_functions.put(FUNC_SUM_STRING,
297                     new Integer JavaDoc(FunctionTable.FUNC_SUM));
298     m_functions.put(FUNC_STRING_STRING,
299                     new Integer JavaDoc(FunctionTable.FUNC_STRING));
300     m_functions.put(FUNC_STARTS_WITH_STRING,
301                     new Integer JavaDoc(FunctionTable.FUNC_STARTS_WITH));
302     m_functions.put(FUNC_CONTAINS_STRING,
303                     new Integer JavaDoc(FunctionTable.FUNC_CONTAINS));
304     m_functions.put(FUNC_SUBSTRING_BEFORE_STRING,
305                     new Integer JavaDoc(FunctionTable.FUNC_SUBSTRING_BEFORE));
306     m_functions.put(FUNC_SUBSTRING_AFTER_STRING,
307                     new Integer JavaDoc(FunctionTable.FUNC_SUBSTRING_AFTER));
308     m_functions.put(FUNC_NORMALIZE_SPACE_STRING,
309                     new Integer JavaDoc(FunctionTable.FUNC_NORMALIZE_SPACE));
310     m_functions.put(FUNC_TRANSLATE_STRING,
311                     new Integer JavaDoc(FunctionTable.FUNC_TRANSLATE));
312     m_functions.put(FUNC_CONCAT_STRING,
313                     new Integer JavaDoc(FunctionTable.FUNC_CONCAT));
314
315     //m_functions.put(FUNC_FORMAT_NUMBER_STRING, new Integer(FunctionTable.FUNC_FORMAT_NUMBER));
316
m_functions.put(FUNC_SYSTEM_PROPERTY_STRING,
317                     new Integer JavaDoc(FunctionTable.FUNC_SYSTEM_PROPERTY));
318     m_functions.put(FUNC_EXT_FUNCTION_AVAILABLE_STRING,
319                     new Integer JavaDoc(FunctionTable.FUNC_EXT_FUNCTION_AVAILABLE));
320     m_functions.put(FUNC_EXT_ELEM_AVAILABLE_STRING,
321                     new Integer JavaDoc(FunctionTable.FUNC_EXT_ELEM_AVAILABLE));
322     m_functions.put(FUNC_SUBSTRING_STRING,
323                     new Integer JavaDoc(FunctionTable.FUNC_SUBSTRING));
324     m_functions.put(FUNC_STRING_LENGTH_STRING,
325                     new Integer JavaDoc(FunctionTable.FUNC_STRING_LENGTH));
326     m_functions.put(FUNC_UNPARSED_ENTITY_URI_STRING,
327                     new Integer JavaDoc(FunctionTable.FUNC_UNPARSED_ENTITY_URI));
328
329     // These aren't really functions.
330
m_functions.put(NODETYPE_COMMENT_STRING,
331                     new Integer JavaDoc(OpCodes.NODETYPE_COMMENT));
332     m_functions.put(NODETYPE_TEXT_STRING,
333                     new Integer JavaDoc(OpCodes.NODETYPE_TEXT));
334     m_functions.put(NODETYPE_PI_STRING,
335                     new Integer JavaDoc(OpCodes.NODETYPE_PI));
336     m_functions.put(NODETYPE_NODE_STRING,
337                     new Integer JavaDoc(OpCodes.NODETYPE_NODE));
338     m_functions.put(FUNC_DOCLOCATION_STRING,
339                     new Integer JavaDoc(FunctionTable.FUNC_DOCLOCATION));
340   }
341
342   /**
343    * Tell if a built-in, non-namespaced function is available.
344    *
345    * @param methName The local name of the function.
346    *
347    * @return True if the function can be executed.
348    */

349   public static boolean functionAvailable(String JavaDoc methName)
350   {
351
352     try
353     {
354       Object JavaDoc tblEntry = m_functions.get(methName);
355
356       if (null == tblEntry)
357         return false;
358
359       int funcType = ((Integer JavaDoc) tblEntry).intValue();
360
361       switch (funcType)
362       {
363       case OpCodes.NODETYPE_COMMENT :
364       case OpCodes.NODETYPE_TEXT :
365       case OpCodes.NODETYPE_PI :
366       case OpCodes.NODETYPE_NODE :
367         return false; // These look like functions but they're NodeTests.
368
default :
369         return true;
370       }
371     }
372     catch (Exception JavaDoc e)
373     {
374       return false;
375     }
376   }
377 }
378
Popular Tags