001: /*
002: * Copyright 1999-2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: Keywords.java,v 1.12 2005/05/17 21:25:46 jycli Exp $
018: */
019: package org.apache.xpath.compiler;
020:
021: import java.util.Hashtable;
022:
023: /**
024: * Table of strings to operation code lookups.
025: * @xsl.usage internal
026: */
027: public class Keywords {
028:
029: /** Table of keywords to opcode associations. */
030: private static Hashtable m_keywords = new Hashtable();
031:
032: /** Table of axes names to opcode associations. */
033: private static Hashtable m_axisnames = new Hashtable();
034:
035: /** Table of function name to function ID associations. */
036: private static Hashtable m_nodetests = new Hashtable();
037:
038: /** Table of node type strings to opcode associations. */
039: private static Hashtable m_nodetypes = new Hashtable();
040:
041: /** ancestor axes string. */
042: private static final String FROM_ANCESTORS_STRING = "ancestor";
043:
044: /** ancestor-or-self axes string. */
045: private static final String FROM_ANCESTORS_OR_SELF_STRING = "ancestor-or-self";
046:
047: /** attribute axes string. */
048: private static final String FROM_ATTRIBUTES_STRING = "attribute";
049:
050: /** child axes string. */
051: private static final String FROM_CHILDREN_STRING = "child";
052:
053: /** descendant-or-self axes string. */
054: private static final String FROM_DESCENDANTS_STRING = "descendant";
055:
056: /** ancestor axes string. */
057: private static final String FROM_DESCENDANTS_OR_SELF_STRING = "descendant-or-self";
058:
059: /** following axes string. */
060: private static final String FROM_FOLLOWING_STRING = "following";
061:
062: /** following-sibling axes string. */
063: private static final String FROM_FOLLOWING_SIBLINGS_STRING = "following-sibling";
064:
065: /** parent axes string. */
066: private static final String FROM_PARENT_STRING = "parent";
067:
068: /** preceding axes string. */
069: private static final String FROM_PRECEDING_STRING = "preceding";
070:
071: /** preceding-sibling axes string. */
072: private static final String FROM_PRECEDING_SIBLINGS_STRING = "preceding-sibling";
073:
074: /** self axes string. */
075: private static final String FROM_SELF_STRING = "self";
076:
077: /** namespace axes string. */
078: private static final String FROM_NAMESPACE_STRING = "namespace";
079:
080: /** self axes abreviated string. */
081: private static final String FROM_SELF_ABBREVIATED_STRING = ".";
082:
083: /** comment node test string. */
084: private static final String NODETYPE_COMMENT_STRING = "comment";
085:
086: /** text node test string. */
087: private static final String NODETYPE_TEXT_STRING = "text";
088:
089: /** processing-instruction node test string. */
090: private static final String NODETYPE_PI_STRING = "processing-instruction";
091:
092: /** Any node test string. */
093: private static final String NODETYPE_NODE_STRING = "node";
094:
095: /** Wildcard element string. */
096: private static final String NODETYPE_ANYELEMENT_STRING = "*";
097:
098: /** current function string. */
099: public static final String FUNC_CURRENT_STRING = "current";
100:
101: /** last function string. */
102: public static final String FUNC_LAST_STRING = "last";
103:
104: /** position function string. */
105: public static final String FUNC_POSITION_STRING = "position";
106:
107: /** count function string. */
108: public static final String FUNC_COUNT_STRING = "count";
109:
110: /** id function string. */
111: static final String FUNC_ID_STRING = "id";
112:
113: /** key function string (XSLT). */
114: public static final String FUNC_KEY_STRING = "key";
115:
116: /** local-name function string. */
117: public static final String FUNC_LOCAL_PART_STRING = "local-name";
118:
119: /** namespace-uri function string. */
120: public static final String FUNC_NAMESPACE_STRING = "namespace-uri";
121:
122: /** name function string. */
123: public static final String FUNC_NAME_STRING = "name";
124:
125: /** generate-id function string (XSLT). */
126: public static final String FUNC_GENERATE_ID_STRING = "generate-id";
127:
128: /** not function string. */
129: public static final String FUNC_NOT_STRING = "not";
130:
131: /** true function string. */
132: public static final String FUNC_TRUE_STRING = "true";
133:
134: /** false function string. */
135: public static final String FUNC_FALSE_STRING = "false";
136:
137: /** boolean function string. */
138: public static final String FUNC_BOOLEAN_STRING = "boolean";
139:
140: /** lang function string. */
141: public static final String FUNC_LANG_STRING = "lang";
142:
143: /** number function string. */
144: public static final String FUNC_NUMBER_STRING = "number";
145:
146: /** floor function string. */
147: public static final String FUNC_FLOOR_STRING = "floor";
148:
149: /** ceiling function string. */
150: public static final String FUNC_CEILING_STRING = "ceiling";
151:
152: /** round function string. */
153: public static final String FUNC_ROUND_STRING = "round";
154:
155: /** sum function string. */
156: public static final String FUNC_SUM_STRING = "sum";
157:
158: /** string function string. */
159: public static final String FUNC_STRING_STRING = "string";
160:
161: /** starts-with function string. */
162: public static final String FUNC_STARTS_WITH_STRING = "starts-with";
163:
164: /** contains function string. */
165: public static final String FUNC_CONTAINS_STRING = "contains";
166:
167: /** substring-before function string. */
168: public static final String FUNC_SUBSTRING_BEFORE_STRING = "substring-before";
169:
170: /** substring-after function string. */
171: public static final String FUNC_SUBSTRING_AFTER_STRING = "substring-after";
172:
173: /** normalize-space function string. */
174: public static final String FUNC_NORMALIZE_SPACE_STRING = "normalize-space";
175:
176: /** translate function string. */
177: public static final String FUNC_TRANSLATE_STRING = "translate";
178:
179: /** concat function string. */
180: public static final String FUNC_CONCAT_STRING = "concat";
181:
182: /** system-property function string. */
183: public static final String FUNC_SYSTEM_PROPERTY_STRING = "system-property";
184:
185: /** function-available function string (XSLT). */
186: public static final String FUNC_EXT_FUNCTION_AVAILABLE_STRING = "function-available";
187:
188: /** element-available function string (XSLT). */
189: public static final String FUNC_EXT_ELEM_AVAILABLE_STRING = "element-available";
190:
191: /** substring function string. */
192: public static final String FUNC_SUBSTRING_STRING = "substring";
193:
194: /** string-length function string. */
195: public static final String FUNC_STRING_LENGTH_STRING = "string-length";
196:
197: /** unparsed-entity-uri function string (XSLT). */
198: public static final String FUNC_UNPARSED_ENTITY_URI_STRING = "unparsed-entity-uri";
199:
200: // Proprietary, built in functions
201:
202: /** current function string (Proprietary). */
203: public static final String FUNC_DOCLOCATION_STRING = "document-location";
204:
205: static {
206: m_axisnames.put(FROM_ANCESTORS_STRING, new Integer(
207: OpCodes.FROM_ANCESTORS));
208: m_axisnames.put(FROM_ANCESTORS_OR_SELF_STRING, new Integer(
209: OpCodes.FROM_ANCESTORS_OR_SELF));
210: m_axisnames.put(FROM_ATTRIBUTES_STRING, new Integer(
211: OpCodes.FROM_ATTRIBUTES));
212: m_axisnames.put(FROM_CHILDREN_STRING, new Integer(
213: OpCodes.FROM_CHILDREN));
214: m_axisnames.put(FROM_DESCENDANTS_STRING, new Integer(
215: OpCodes.FROM_DESCENDANTS));
216: m_axisnames.put(FROM_DESCENDANTS_OR_SELF_STRING, new Integer(
217: OpCodes.FROM_DESCENDANTS_OR_SELF));
218: m_axisnames.put(FROM_FOLLOWING_STRING, new Integer(
219: OpCodes.FROM_FOLLOWING));
220: m_axisnames.put(FROM_FOLLOWING_SIBLINGS_STRING, new Integer(
221: OpCodes.FROM_FOLLOWING_SIBLINGS));
222: m_axisnames.put(FROM_PARENT_STRING, new Integer(
223: OpCodes.FROM_PARENT));
224: m_axisnames.put(FROM_PRECEDING_STRING, new Integer(
225: OpCodes.FROM_PRECEDING));
226: m_axisnames.put(FROM_PRECEDING_SIBLINGS_STRING, new Integer(
227: OpCodes.FROM_PRECEDING_SIBLINGS));
228: m_axisnames.put(FROM_SELF_STRING,
229: new Integer(OpCodes.FROM_SELF));
230: m_axisnames.put(FROM_NAMESPACE_STRING, new Integer(
231: OpCodes.FROM_NAMESPACE));
232: m_nodetypes.put(NODETYPE_COMMENT_STRING, new Integer(
233: OpCodes.NODETYPE_COMMENT));
234: m_nodetypes.put(NODETYPE_TEXT_STRING, new Integer(
235: OpCodes.NODETYPE_TEXT));
236: m_nodetypes.put(NODETYPE_PI_STRING, new Integer(
237: OpCodes.NODETYPE_PI));
238: m_nodetypes.put(NODETYPE_NODE_STRING, new Integer(
239: OpCodes.NODETYPE_NODE));
240: m_nodetypes.put(NODETYPE_ANYELEMENT_STRING, new Integer(
241: OpCodes.NODETYPE_ANYELEMENT));
242: m_keywords.put(FROM_SELF_ABBREVIATED_STRING, new Integer(
243: OpCodes.FROM_SELF));
244: m_keywords.put(FUNC_ID_STRING, new Integer(
245: FunctionTable.FUNC_ID));
246: m_keywords.put(FUNC_KEY_STRING, new Integer(
247: FunctionTable.FUNC_KEY));
248:
249: m_nodetests.put(NODETYPE_COMMENT_STRING, new Integer(
250: OpCodes.NODETYPE_COMMENT));
251: m_nodetests.put(NODETYPE_TEXT_STRING, new Integer(
252: OpCodes.NODETYPE_TEXT));
253: m_nodetests.put(NODETYPE_PI_STRING, new Integer(
254: OpCodes.NODETYPE_PI));
255: m_nodetests.put(NODETYPE_NODE_STRING, new Integer(
256: OpCodes.NODETYPE_NODE));
257: }
258:
259: static Object getAxisName(String key) {
260: return m_axisnames.get(key);
261: }
262:
263: static Object lookupNodeTest(String key) {
264: return m_nodetests.get(key);
265: }
266:
267: static Object getKeyWord(String key) {
268: return m_keywords.get(key);
269: }
270:
271: static Object getNodeType(String key) {
272: return m_nodetypes.get(key);
273: }
274: }
|