1 | |
package org.melati.admin; |
2 | |
|
3 | |
import java.lang.IllegalArgumentException; |
4 | |
import java.util.HashMap; |
5 | |
import java.util.Map; |
6 | |
|
7 | |
import org.melati.poem.PoemTypeFactory; |
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | 42 | public enum PoemGvisType { |
16 | 1 | TROID(PoemTypeFactory.TROID.getCode()) { |
17 | |
@Override |
18 | |
public |
19 | |
String gvisJsonTypeName() { |
20 | 3 | return "number"; |
21 | |
} |
22 | |
|
23 | |
@Override |
24 | |
public |
25 | |
String jsonValue(Object value) { |
26 | 3 | if (value == null ) |
27 | 2 | return "null"; |
28 | |
else |
29 | 1 | return "\"" + value.toString() + "\""; |
30 | |
} |
31 | |
}, |
32 | 1 | DELETED(PoemTypeFactory.DELETED.getCode()) { |
33 | |
@Override |
34 | |
public |
35 | |
String gvisJsonTypeName() { |
36 | 2 | return "boolean"; |
37 | |
} |
38 | |
public String jsonValue(Object value) { |
39 | 3 | if (value == null ) |
40 | 2 | return "null"; |
41 | |
else |
42 | 1 | return value.toString(); |
43 | |
} |
44 | |
}, |
45 | 1 | TYPE(PoemTypeFactory.TYPE.getCode()) { |
46 | |
@Override |
47 | |
public |
48 | |
String gvisJsonTypeName() { |
49 | 1 | return "number"; |
50 | |
} |
51 | |
}, |
52 | |
|
53 | |
|
54 | 1 | BOOLEAN(PoemTypeFactory.BOOLEAN.getCode()) { |
55 | |
@Override |
56 | |
public |
57 | |
String gvisJsonTypeName() { |
58 | 1 | return "boolean"; |
59 | |
} |
60 | |
}, |
61 | 1 | INTEGER(PoemTypeFactory.INTEGER.getCode()) { |
62 | |
@Override |
63 | |
public |
64 | |
String gvisJsonTypeName() { |
65 | 1 | return "number"; |
66 | |
} |
67 | |
|
68 | |
@Override |
69 | |
public |
70 | |
String jsonValue(Object value) { |
71 | 3 | if (value == null ) |
72 | 2 | return "null"; |
73 | |
else |
74 | 1 | return value.toString(); |
75 | |
} |
76 | |
}, |
77 | 1 | DOUBLE(PoemTypeFactory.DOUBLE.getCode()) { |
78 | |
@Override |
79 | |
public |
80 | |
String gvisJsonTypeName() { |
81 | 1 | return "number"; |
82 | |
} |
83 | |
@Override |
84 | |
public String jsonValue(Object value) { |
85 | 5 | if (value == null ) |
86 | 2 | return "null"; |
87 | |
else |
88 | 3 | return value.toString(); |
89 | |
} |
90 | |
}, |
91 | 1 | LONG(PoemTypeFactory.LONG.getCode()) { |
92 | |
@Override |
93 | |
public |
94 | |
String gvisJsonTypeName() { |
95 | 1 | return "number"; |
96 | |
} |
97 | |
@Override |
98 | |
public String jsonValue(Object value) { |
99 | 3 | if (value == null ) |
100 | 2 | return "null"; |
101 | |
else |
102 | 1 | return value.toString(); |
103 | |
} |
104 | |
}, |
105 | 1 | BIGDECIMAL(PoemTypeFactory.BIGDECIMAL.getCode()) { |
106 | |
@Override |
107 | |
public |
108 | |
String gvisJsonTypeName() { |
109 | 1 | return "number"; |
110 | |
} |
111 | |
@Override |
112 | |
public String jsonValue(Object value) { |
113 | 3 | if (value == null ) |
114 | 2 | return "null"; |
115 | |
else |
116 | 1 | return value.toString(); |
117 | |
} |
118 | |
}, |
119 | 1 | STRING(PoemTypeFactory.STRING.getCode()) { |
120 | |
@Override |
121 | |
public |
122 | |
String gvisJsonTypeName() { |
123 | 5 | return "string"; |
124 | |
} |
125 | |
}, |
126 | 1 | PASSWORD(PoemTypeFactory.PASSWORD.getCode()) { |
127 | |
@Override |
128 | |
public |
129 | |
String gvisJsonTypeName() { |
130 | 1 | return "string"; |
131 | |
} |
132 | |
}, |
133 | 1 | DATE(PoemTypeFactory.DATE.getCode()) { |
134 | |
@Override |
135 | |
public |
136 | |
String gvisJsonTypeName() { |
137 | 1 | return "date"; |
138 | |
} |
139 | |
}, |
140 | 1 | TIMESTAMP(PoemTypeFactory.TIMESTAMP.getCode()) { |
141 | |
@Override |
142 | |
public |
143 | |
String gvisJsonTypeName() { |
144 | 1 | return "datetime"; |
145 | |
} |
146 | |
}, |
147 | 1 | TIME(PoemTypeFactory.TIME.getCode()) { |
148 | |
@Override |
149 | |
public |
150 | |
String gvisJsonTypeName() { |
151 | 1 | return "timeofday"; |
152 | |
} |
153 | |
}, |
154 | 1 | BINARY(PoemTypeFactory.BINARY.getCode()) { |
155 | |
@Override |
156 | |
public |
157 | |
String gvisJsonTypeName() { |
158 | 1 | throw new IllegalArgumentException("Binary poem type cannot be exported to google viualisation API."); |
159 | |
} |
160 | |
}, |
161 | |
|
162 | |
|
163 | 1 | DISPLAYLEVEL(PoemTypeFactory.DISPLAYLEVEL.getCode()) { |
164 | |
@Override |
165 | |
public |
166 | |
String gvisJsonTypeName() { |
167 | 1 | return "number"; |
168 | |
} |
169 | |
}, |
170 | 1 | SEARCHABILITY(PoemTypeFactory.SEARCHABILITY.getCode()) { |
171 | |
@Override |
172 | |
public |
173 | |
String gvisJsonTypeName() { |
174 | 1 | return "number"; |
175 | |
} |
176 | |
}, |
177 | 1 | INTEGRITYFIX(PoemTypeFactory.INTEGRITYFIX.getCode()) { |
178 | |
@Override |
179 | |
public |
180 | |
String gvisJsonTypeName() { |
181 | 1 | return "number"; |
182 | |
} |
183 | |
}; |
184 | |
|
185 | |
final Integer poemType; |
186 | 17 | PoemGvisType(Integer poemType) { |
187 | 17 | this.poemType = poemType; |
188 | 17 | } |
189 | |
|
190 | |
public Integer getPoemType(){ |
191 | 17 | return poemType; |
192 | |
} |
193 | |
public PoemTypeFactory getPeomTypeFactory() { |
194 | 17 | return PoemTypeFactory.forCode(null, poemType); |
195 | |
} |
196 | |
|
197 | |
public abstract String gvisJsonTypeName(); |
198 | |
|
199 | |
public String jsonValue(Object value) { |
200 | 24 | if (value == null ) |
201 | 22 | return "null"; |
202 | |
else |
203 | 2 | return "\"" + value.toString() + "\""; |
204 | |
} |
205 | |
|
206 | |
public static PoemGvisType from(Integer poemType){ |
207 | 17 | return typeCodeToPoemGvisType.get(poemType); |
208 | |
} |
209 | |
private static Map<Integer, PoemGvisType> typeCodeToPoemGvisType; |
210 | |
static { |
211 | 1 | typeCodeToPoemGvisType = new HashMap<Integer,PoemGvisType>(); |
212 | 18 | for (PoemGvisType type : PoemGvisType.values()) { |
213 | 17 | typeCodeToPoemGvisType.put(type.poemType, type); |
214 | |
} |
215 | 1 | } |
216 | |
|
217 | |
} |