1 | |
package net.sf.jolene.constants; |
2 | |
|
3 | |
import org.apache.log4j.LogManager; |
4 | |
import org.apache.log4j.Logger; |
5 | |
|
6 | |
import java.lang.reflect.Field; |
7 | |
import java.util.HashMap; |
8 | |
import java.util.Map; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
public class Prefs { |
17 | |
|
18 | 1 | private static final Logger log = LogManager.getLogger(Prefs.class); |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | 1 | public static final Prefs CacheSize = new Prefs("CacheSize", 32); |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 1 | public static final Prefs DocumentCaching = new Prefs("DocumentCaching", true); |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 1 | public static final Prefs GenerateLocaleStrings = new Prefs("GenerateLocaleStrings", false); |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 1 | public static final Prefs SelectValueSeperator = new Prefs("SelectValueSeperator", ","); |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 1 | public static final Prefs StreamLabelTags = new Prefs("StreamLabelTags", true); |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | 1 | public static final Prefs XHTMLStrict = new Prefs("XHTMLStrict", false); |
60 | |
|
61 | 1 | private static Map<String, Prefs> prefMap = null; |
62 | |
|
63 | |
|
64 | |
private final String name; |
65 | |
private Object value; |
66 | |
|
67 | 6 | private Prefs(String name, Object value) { |
68 | 6 | this.name = name; |
69 | 6 | this.value = value; |
70 | 6 | } |
71 | |
|
72 | |
@Override |
73 | |
public String toString() { |
74 | 0 | return name; |
75 | |
} |
76 | |
|
77 | |
public String getValue() { |
78 | 129645 | return value.toString(); |
79 | |
} |
80 | |
|
81 | |
public void setValue(Object value) { |
82 | 0 | this.value = value; |
83 | 0 | } |
84 | |
|
85 | |
public static Prefs valueOf(String name) throws IllegalArgumentException { |
86 | 2 | if (name == null) { |
87 | 0 | throw new IllegalArgumentException("valueOf parameter is null"); |
88 | |
} |
89 | |
|
90 | 2 | if (prefMap == null) { |
91 | 1 | initPrefMap(); |
92 | |
} |
93 | 2 | return prefMap.get(name.toLowerCase()); |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
private static void initPrefMap() { |
100 | 1 | Object o = new Object(); |
101 | 1 | synchronized (o) { |
102 | 1 | prefMap = new HashMap<String, Prefs>(12); |
103 | |
|
104 | 1 | Field[] fields = Prefs.class.getFields(); |
105 | 7 | for (int j = 0; j < fields.length; j++) { |
106 | |
|
107 | |
try { |
108 | 6 | if (Prefs.class.equals(fields[j].getType())) { |
109 | 6 | prefMap.put(fields[j].getName().toLowerCase(), (Prefs) fields[j].get(j)); |
110 | |
} |
111 | 0 | } catch (IllegalAccessException e) { |
112 | 0 | log.error(e.getMessage(), e); |
113 | 6 | } |
114 | |
} |
115 | 1 | } |
116 | 1 | } |
117 | |
} |
118 | |
|