01: package org.makumba.commons;
02:
03: import java.util.HashSet;
04: import java.util.Iterator;
05: import java.util.Set;
06:
07: /**
08: * Utility class containing all kind of reserved words which may cause problems if used as e.g. field names
09: *
10: * @author Manuel Gay
11: * @author Rudolf Mayer
12: * @version $Id: ReservedKeywords.java 2061 2007-11-19 10:13:18Z manuel_gay $
13: */
14: public class ReservedKeywords {
15:
16: private static Set<String> reservedKeywords;
17:
18: private static String[] javaReserved = { "abstract", "continue",
19: "for", "new", "switch", "assert", "default", "goto",
20: "package", "synchronized", "boolean", "do", "if",
21: "private", "this", "break", "double", "implements",
22: "protected", "throw", "byte", "else", "import", "public",
23: "throws", "case", "enum", "instanceof", "return",
24: "transient", "catch", "extends", "int", "short", "try",
25: "char", "final", "interface", "static", "void", "class",
26: "finally", "long", "strictfp", "volatile", "const",
27: "float", "native", "super", "while" };
28:
29: private static String[] hibernateReserved = {}; /*"id"*/
30:
31: // not sure if this list should be including all SQL keywords, or just such that can cause problems in the SQL
32: // statements.
33: // chose for now to just list those that would cause problems, list is for sure not complete
34: private static String[] sqlReserved = { "avg", "count", "distinct",
35: "group", "order", "sum" };
36:
37: static {
38: ReservedKeywords.reservedKeywords = new HashSet<String>();
39: for (int i = 0; i < ReservedKeywords.javaReserved.length; i++) {
40: ReservedKeywords.reservedKeywords
41: .add(ReservedKeywords.javaReserved[i]);
42: }
43: for (int i = 0; i < ReservedKeywords.hibernateReserved.length; i++) {
44: ReservedKeywords.reservedKeywords
45: .add(ReservedKeywords.hibernateReserved[i]);
46: }
47: for (int i = 0; i < ReservedKeywords.sqlReserved.length; i++) {
48: ReservedKeywords.reservedKeywords
49: .add(ReservedKeywords.sqlReserved[i]);
50: }
51: }
52:
53: public static Set getReservedKeywords() {
54: return reservedKeywords;
55: }
56:
57: public static boolean isReservedKeyword(String s) {
58: return (reservedKeywords.contains(s));
59: }
60:
61: public static String getKeywordsAsString() {
62: String reserved = new String();
63: Iterator i = reservedKeywords.iterator();
64: while (i.hasNext()) {
65: reserved += (String) i.next();
66: if (i.hasNext()) {
67: reserved += ", ";
68: }
69: }
70: return reserved;
71: }
72:
73: }
|