KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > misc > ReservedWords


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.core.misc;
66
67 import com.jcorporate.expresso.core.controller.Controller;
68
69 import java.util.TreeSet JavaDoc;
70
71
72 /**
73  * This class is the central repository for reserved words for known/tested
74  * databases. By doublechecking against this list, you're pretty much in the
75  * clear for making sure that your field names will work in various databases.<br />
76  * <p/>
77  * Current sets that are checked against are:<br />
78  * SQL 99 Standard <br />
79  * Expresso Reserved Words <br />
80  *
81  * @author Michael Rimov
82  */

83 public class ReservedWords {
84
85     /**
86      * The set of case insensitive reserved words. These are all stored in lower
87      * case, and are usually SQL words.
88      */

89     protected TreeSet JavaDoc caseInsensitiveWords;
90
91     /**
92      * The set of case insensitive reserved words. Yhese usually are specific
93      * words that would interfere with the expresso framework, and thus are
94      * prohibited.
95      */

96     protected TreeSet JavaDoc caseSensitiveWords;
97
98     /**
99      * singleton instance. Instantiated with first call to getInstance()
100      */

101     static protected volatile ReservedWords theInstance = null;
102
103     /**
104      * Singleton instance pattern.
105      */

106     public static synchronized ReservedWords getInstance() {
107         if (theInstance == null) {
108             theInstance = new ReservedWords();
109         }
110
111         return theInstance;
112     }
113
114     /**
115      * Returns whether a field or table name, can be used with a database. This
116      * does not guarantee that a DBObject will be compatibile with a database,
117      * but it does attempt to catch the most common/known errors.
118      *
119      * @param testWord the word to test.
120      * @return True if the would should not be used in a database.
121      */

122     public boolean isReservedWord(String JavaDoc testWord) {
123         if (caseSensitiveWords.contains(testWord)) {
124             return true;
125         } else if (caseInsensitiveWords.contains(testWord.toLowerCase())) {
126             return true;
127         } else {
128             return false;
129         }
130     }
131
132     /**
133      * Returns whether or not a word that shouldn't be used in web page
134      * parameters should exists
135      */

136     public boolean isExpressoReservedWord(String JavaDoc testWord) {
137         return caseSensitiveWords.contains(testWord);
138     }
139
140     protected ReservedWords() {
141         caseInsensitiveWords = new TreeSet JavaDoc();
142         caseSensitiveWords = new TreeSet JavaDoc();
143         buildCaseInsensitiveList();
144         buildCaseSensitiveList();
145     }
146
147     protected void buildCaseSensitiveList() {
148
149         //Expresso Reserved Words - Can't have parameters with these names in
150
//them. If you have for example, "State" field name, you're ok, you
151
//just can't have lower case "state"
152
caseSensitiveWords.add(Controller.STATE_PARAM_KEY);
153         caseSensitiveWords.add(Controller.CONTROLLER_PARAM_KEY);
154         caseSensitiveWords.add("page");
155         caseSensitiveWords.add("style");
156         caseSensitiveWords.add("xsl");
157         caseSensitiveWords.add("fields");
158         caseSensitiveWords.add("search");
159         caseSensitiveWords.add("db");
160     }
161
162     protected void buildCaseInsensitiveList() {
163
164         //SQL-99 Reserved Words
165
caseInsensitiveWords.add("absolute");
166         caseInsensitiveWords.add("action");
167         caseInsensitiveWords.add("add");
168         caseInsensitiveWords.add("admin");
169         caseInsensitiveWords.add("after");
170         caseInsensitiveWords.add("aggregate");
171         caseInsensitiveWords.add("alias");
172         caseInsensitiveWords.add("all");
173         caseInsensitiveWords.add("allocate");
174         caseInsensitiveWords.add("alter");
175         caseInsensitiveWords.add("and");
176         caseInsensitiveWords.add("any");
177         caseInsensitiveWords.add("are");
178         caseInsensitiveWords.add("array");
179         caseInsensitiveWords.add("as");
180         caseInsensitiveWords.add("asc");
181         caseInsensitiveWords.add("assertion");
182         caseInsensitiveWords.add("at");
183         caseInsensitiveWords.add("authorization");
184         caseInsensitiveWords.add("before");
185         caseInsensitiveWords.add("begin");
186         caseInsensitiveWords.add("binary");
187         caseInsensitiveWords.add("bit");
188         caseInsensitiveWords.add("blob");
189         caseInsensitiveWords.add("boolean");
190         caseInsensitiveWords.add("both");
191         caseInsensitiveWords.add("breadth");
192         caseInsensitiveWords.add("by");
193         caseInsensitiveWords.add("call");
194         caseInsensitiveWords.add("cascade");
195         caseInsensitiveWords.add("cascaded");
196         caseInsensitiveWords.add("case");
197         caseInsensitiveWords.add("cast");
198         caseInsensitiveWords.add("catalog");
199         caseInsensitiveWords.add("char");
200         caseInsensitiveWords.add("character");
201         caseInsensitiveWords.add("check");
202         caseInsensitiveWords.add("class");
203         caseInsensitiveWords.add("clob");
204         caseInsensitiveWords.add("close");
205         caseInsensitiveWords.add("collate");
206         caseInsensitiveWords.add("collation");
207         caseInsensitiveWords.add("column");
208         caseInsensitiveWords.add("commit");
209         caseInsensitiveWords.add("completion");
210         caseInsensitiveWords.add("connect");
211         caseInsensitiveWords.add("connection");
212         caseInsensitiveWords.add("constraint");
213         caseInsensitiveWords.add("constraints");
214         caseInsensitiveWords.add("constructor");
215         caseInsensitiveWords.add("continue");
216         caseInsensitiveWords.add("corresponding");
217         caseInsensitiveWords.add("create");
218         caseInsensitiveWords.add("cross");
219         caseInsensitiveWords.add("cube");
220         caseInsensitiveWords.add("current");
221         caseInsensitiveWords.add("current_date");
222         caseInsensitiveWords.add("current_path");
223         caseInsensitiveWords.add("current_role");
224         caseInsensitiveWords.add("current_time");
225         caseInsensitiveWords.add("current_timestamp");
226         caseInsensitiveWords.add("current_user");
227         caseInsensitiveWords.add("cursor");
228         caseInsensitiveWords.add("cycle");
229         caseInsensitiveWords.add("data");
230         caseInsensitiveWords.add("date");
231         caseInsensitiveWords.add("day");
232         caseInsensitiveWords.add("deallocate");
233         caseInsensitiveWords.add("dec");
234         caseInsensitiveWords.add("decimal");
235         caseInsensitiveWords.add("declare");
236         caseInsensitiveWords.add("default");
237         caseInsensitiveWords.add("deferrable");
238         caseInsensitiveWords.add("deferred");
239         caseInsensitiveWords.add("delete");
240         caseInsensitiveWords.add("depth");
241         caseInsensitiveWords.add("deref");
242         caseInsensitiveWords.add("desc");
243         caseInsensitiveWords.add("describe");
244         caseInsensitiveWords.add("descriptor");
245         caseInsensitiveWords.add("destroy");
246         caseInsensitiveWords.add("destructor");
247         caseInsensitiveWords.add("deterministic");
248         caseInsensitiveWords.add("diagnostics");
249         caseInsensitiveWords.add("dictionary");
250         caseInsensitiveWords.add("disconnect");
251         caseInsensitiveWords.add("distinct");
252         caseInsensitiveWords.add("domain");
253         caseInsensitiveWords.add("double");
254         caseInsensitiveWords.add("drop");
255         caseInsensitiveWords.add("dynamic");
256         caseInsensitiveWords.add("each");
257         caseInsensitiveWords.add("else");
258         caseInsensitiveWords.add("end");
259         caseInsensitiveWords.add("end-exec");
260         caseInsensitiveWords.add("equals");
261         caseInsensitiveWords.add("escape");
262         caseInsensitiveWords.add("every");
263         caseInsensitiveWords.add("except");
264         caseInsensitiveWords.add("exception");
265         caseInsensitiveWords.add("exec");
266         caseInsensitiveWords.add("execute");
267         caseInsensitiveWords.add("external");
268         caseInsensitiveWords.add("false");
269         caseInsensitiveWords.add("fetch");
270         caseInsensitiveWords.add("first");
271         caseInsensitiveWords.add("float");
272         caseInsensitiveWords.add("for");
273         caseInsensitiveWords.add("foreign");
274         caseInsensitiveWords.add("found");
275         caseInsensitiveWords.add("free");
276         caseInsensitiveWords.add("from");
277         caseInsensitiveWords.add("full");
278         caseInsensitiveWords.add("function");
279         caseInsensitiveWords.add("general");
280         caseInsensitiveWords.add("get");
281         caseInsensitiveWords.add("global");
282         caseInsensitiveWords.add("go");
283         caseInsensitiveWords.add("goto");
284         caseInsensitiveWords.add("grant");
285         caseInsensitiveWords.add("group");
286         caseInsensitiveWords.add("grouping");
287         caseInsensitiveWords.add("having");
288         caseInsensitiveWords.add("host");
289         caseInsensitiveWords.add("hour");
290         caseInsensitiveWords.add("identity");
291         caseInsensitiveWords.add("ignore");
292         caseInsensitiveWords.add("immediate");
293         caseInsensitiveWords.add("in");
294         caseInsensitiveWords.add("indicator");
295         caseInsensitiveWords.add("initialize");
296         caseInsensitiveWords.add("initially");
297         caseInsensitiveWords.add("inner");
298         caseInsensitiveWords.add("inout");
299         caseInsensitiveWords.add("input");
300         caseInsensitiveWords.add("insert");
301         caseInsensitiveWords.add("int");
302         caseInsensitiveWords.add("integer");
303         caseInsensitiveWords.add("intersect");
304         caseInsensitiveWords.add("interval");
305         caseInsensitiveWords.add("into");
306         caseInsensitiveWords.add("is");
307         caseInsensitiveWords.add("isolation");
308         caseInsensitiveWords.add("iterate");
309         caseInsensitiveWords.add("join");
310         caseInsensitiveWords.add("key");
311         caseInsensitiveWords.add("language");
312         caseInsensitiveWords.add("large");
313         caseInsensitiveWords.add("last");
314         caseInsensitiveWords.add("lateral");
315         caseInsensitiveWords.add("leading");
316         caseInsensitiveWords.add("left");
317         caseInsensitiveWords.add("less");
318         caseInsensitiveWords.add("level");
319         caseInsensitiveWords.add("like");
320         caseInsensitiveWords.add("limit");
321         caseInsensitiveWords.add("local");
322         caseInsensitiveWords.add("localtime");
323         caseInsensitiveWords.add("localtimestamp");
324         caseInsensitiveWords.add("locator");
325         caseInsensitiveWords.add("map");
326         caseInsensitiveWords.add("match");
327         caseInsensitiveWords.add("minute");
328         caseInsensitiveWords.add("modifies");
329         caseInsensitiveWords.add("modify");
330         caseInsensitiveWords.add("module");
331         caseInsensitiveWords.add("month");
332         caseInsensitiveWords.add("names");
333         caseInsensitiveWords.add("national");
334         caseInsensitiveWords.add("natural");
335         caseInsensitiveWords.add("nchar");
336         caseInsensitiveWords.add("nclob");
337         caseInsensitiveWords.add("new");
338         caseInsensitiveWords.add("next");
339         caseInsensitiveWords.add("no");
340         caseInsensitiveWords.add("none");
341         caseInsensitiveWords.add("not");
342         caseInsensitiveWords.add("null");
343         caseInsensitiveWords.add("numeric");
344         caseInsensitiveWords.add("object");
345         caseInsensitiveWords.add("of");
346         caseInsensitiveWords.add("off");
347         caseInsensitiveWords.add("old");
348         caseInsensitiveWords.add("on");
349         caseInsensitiveWords.add("only");
350         caseInsensitiveWords.add("open");
351         caseInsensitiveWords.add("operation");
352         caseInsensitiveWords.add("option");
353         caseInsensitiveWords.add("or");
354         caseInsensitiveWords.add("order");
355         caseInsensitiveWords.add("ordinality");
356         caseInsensitiveWords.add("out");
357         caseInsensitiveWords.add("outer");
358         caseInsensitiveWords.add("output");
359         caseInsensitiveWords.add("pad");
360         caseInsensitiveWords.add("parameter");
361         caseInsensitiveWords.add("parameters");
362         caseInsensitiveWords.add("partial");
363         caseInsensitiveWords.add("path");
364         caseInsensitiveWords.add("postfix");
365         caseInsensitiveWords.add("precision");
366         caseInsensitiveWords.add("prefix");
367         caseInsensitiveWords.add("preorder");
368         caseInsensitiveWords.add("prepare");
369         caseInsensitiveWords.add("preserve");
370         caseInsensitiveWords.add("primary");
371         caseInsensitiveWords.add("prior");
372         caseInsensitiveWords.add("procedure");
373         caseInsensitiveWords.add("public");
374         caseInsensitiveWords.add("read");
375         caseInsensitiveWords.add("reads");
376         caseInsensitiveWords.add("real");
377         caseInsensitiveWords.add("recursive");
378         caseInsensitiveWords.add("ref");
379         caseInsensitiveWords.add("references");
380         caseInsensitiveWords.add("referencing");
381         caseInsensitiveWords.add("relative");
382         caseInsensitiveWords.add("restrict");
383         caseInsensitiveWords.add("result");
384         caseInsensitiveWords.add("return");
385         caseInsensitiveWords.add("returns");
386         caseInsensitiveWords.add("revoke");
387         caseInsensitiveWords.add("right");
388         caseInsensitiveWords.add("role");
389         caseInsensitiveWords.add("rollback");
390         caseInsensitiveWords.add("rolleup");
391         caseInsensitiveWords.add("routine");
392         caseInsensitiveWords.add("row");
393         caseInsensitiveWords.add("rows");
394         caseInsensitiveWords.add("savepoint");
395         caseInsensitiveWords.add("schema");
396         caseInsensitiveWords.add("scope");
397         caseInsensitiveWords.add("scroll");
398         caseInsensitiveWords.add("search");
399         caseInsensitiveWords.add("second");
400         caseInsensitiveWords.add("section");
401         caseInsensitiveWords.add("select");
402         caseInsensitiveWords.add("sequence");
403         caseInsensitiveWords.add("session");
404         caseInsensitiveWords.add("session_user");
405         caseInsensitiveWords.add("set");
406         caseInsensitiveWords.add("sets");
407         caseInsensitiveWords.add("similar");
408         caseInsensitiveWords.add("simple");
409         caseInsensitiveWords.add("size");
410         caseInsensitiveWords.add("smallint");
411         caseInsensitiveWords.add("some");
412         caseInsensitiveWords.add("space");
413         caseInsensitiveWords.add("specific");
414         caseInsensitiveWords.add("specifictype");
415         caseInsensitiveWords.add("sql");
416         caseInsensitiveWords.add("sqlexception");
417         caseInsensitiveWords.add("sqlstate");
418         caseInsensitiveWords.add("sqlwarning");
419         caseInsensitiveWords.add("start");
420         caseInsensitiveWords.add(Controller.STATE_PARAM_KEY);
421         caseInsensitiveWords.add("statement");
422         caseInsensitiveWords.add("static");
423         caseInsensitiveWords.add("structure");
424         caseInsensitiveWords.add("system_user");
425         caseInsensitiveWords.add("table");
426         caseInsensitiveWords.add("temporary");
427         caseInsensitiveWords.add("terminate");
428         caseInsensitiveWords.add("than");
429         caseInsensitiveWords.add("then");
430         caseInsensitiveWords.add("time");
431         caseInsensitiveWords.add("timestamp");
432         caseInsensitiveWords.add("timezone_Hour");
433         caseInsensitiveWords.add("timezone_Minute");
434         caseInsensitiveWords.add("to");
435         caseInsensitiveWords.add("trailing");
436         caseInsensitiveWords.add("transaction");
437         caseInsensitiveWords.add("translation");
438         caseInsensitiveWords.add("treat");
439         caseInsensitiveWords.add("trigger");
440         caseInsensitiveWords.add("true");
441         caseInsensitiveWords.add("under");
442         caseInsensitiveWords.add("union");
443         caseInsensitiveWords.add("unique");
444         caseInsensitiveWords.add("unknown");
445         caseInsensitiveWords.add("unnest");
446         caseInsensitiveWords.add("update");
447         caseInsensitiveWords.add("usage");
448         caseInsensitiveWords.add("user");
449         caseInsensitiveWords.add("using");
450         caseInsensitiveWords.add("value");
451         caseInsensitiveWords.add("values");
452         caseInsensitiveWords.add("varchar");
453         caseInsensitiveWords.add("variable");
454         caseInsensitiveWords.add("varying");
455         caseInsensitiveWords.add("view");
456         caseInsensitiveWords.add("when");
457         caseInsensitiveWords.add("whenever");
458         caseInsensitiveWords.add("where");
459         caseInsensitiveWords.add("with");
460         caseInsensitiveWords.add("without");
461         caseInsensitiveWords.add("work");
462         caseInsensitiveWords.add("write");
463         caseInsensitiveWords.add("year");
464         caseInsensitiveWords.add("zone");
465
466         //InterBase Reserved Words
467
//PostgreSQL Reserved Words
468
}
469 }
Popular Tags