1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.exolab.castor.types;
36
37 import java.text.SimpleDateFormat;
38 import java.text.ParseException;
39
40
41
42
43
44
45
46
47
48
49
50 public class GDay extends DateTimeBase {
51
52
53 private static final long serialVersionUID = 8571596440117087631L;
54
55
56 private static final String DAY_FORMAT = "---dd";
57
58 private static final String BAD_GDAY = "Bad gDay format: ";
59
60
61
62
63 public GDay() {
64
65 }
66
67
68
69
70
71
72
73 public GDay(short day) {
74 setDay(day);
75 }
76
77
78
79
80
81
82
83 public GDay(int day) {
84 setDay((short) day);
85 }
86
87
88
89
90
91
92
93
94 public GDay(String gday) throws ParseException {
95 parseGDayInternal(gday, this);
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109
110 public void setValues(short[] values) {
111 if (values.length != 1) {
112 throw new IllegalArgumentException("GDay#setValues: not the right number of values");
113 }
114 this.setDay(values[0]);
115 }
116
117
118
119
120
121
122
123
124 public short[] getValues() {
125 short[] result = new short[1];
126 result[0] = this.getDay();
127 return result;
128 }
129
130
131
132
133
134
135 public java.util.Date toDate() {
136 SimpleDateFormat df = new SimpleDateFormat(DAY_FORMAT);
137 setDateFormatTimeZone(df);
138
139 java.util.Date date = null;
140 try {
141 date = df.parse(this.toString());
142 } catch (ParseException e) {
143
144 e.printStackTrace();
145 return null;
146 }
147
148 return date;
149 }
150
151
152
153
154
155
156
157 public String toString() {
158 StringBuffer result = new StringBuffer("---");
159
160 if ((this.getDay() / 10) == 0) {
161 result.append(0);
162 }
163 result.append(this.getDay());
164
165 appendTimeZoneString(result);
166
167 return result.toString();
168 }
169
170
171
172
173
174
175
176
177
178 public static Object parse(String str) throws ParseException {
179 return parseGDay(str);
180 }
181
182
183
184
185
186
187
188
189
190 public static GDay parseGDay(String str) throws ParseException {
191 GDay result = new GDay();
192 return parseGDayInternal(str, result);
193 }
194
195 private static GDay parseGDayInternal(String str, GDay result) throws ParseException {
196 if (str == null) {
197 throw new IllegalArgumentException("The string to be parsed must not be null.");
198 }
199
200 if (result == null) {
201 result = new GDay();
202 }
203
204 char[] chars = str.toCharArray();
205 if (chars[0] != '-' || chars[1] != '-' || chars[2] != '-') {
206 throw new ParseException(
207 BAD_GDAY + str + "\nA gDay must follow the pattern ---DD(Z|((+|-)hh:mm)).", 0);
208 }
209
210 int idx = 2;
211 idx = parseDay(str, result, chars, idx, BAD_GDAY);
212 parseTimeZone(str, result, chars, idx, BAD_GDAY);
213
214 return result;
215 }
216
217
218
219 public boolean hasIsNegative() {
220 return false;
221 }
222
223 public boolean isNegative() {
224 String err = "org.exolab.castor.types.GDay does not have a 'negative' field.";
225 throw new UnsupportedOperationException(err);
226 }
227
228 public void setNegative() {
229 String err = "org.exolab.castor.types.GDay cannot be negative.";
230 throw new UnsupportedOperationException(err);
231 }
232
233 public boolean hasCentury() {
234 return false;
235 }
236
237 public short getCentury() {
238 String err = "org.exolab.castor.types.GDay does not have a Century field.";
239 throw new UnsupportedOperationException(err);
240 }
241
242 public void setCentury(short century) {
243 String err = "org.exolab.castor.types.GDay does not have a Century field.";
244 throw new UnsupportedOperationException(err);
245 }
246
247 public boolean hasYear() {
248 return false;
249 }
250
251 public short getYear() {
252 String err = "org.exolab.castor.types.GDay does not have a Year field.";
253 throw new UnsupportedOperationException(err);
254 }
255
256 public void setYear(short year) {
257 String err = "org.exolab.castor.types.GDay does not have a Year field.";
258 throw new UnsupportedOperationException(err);
259 }
260
261 public boolean hasMonth() {
262 return false;
263 }
264
265 public short getMonth() {
266 String err = "org.exolab.castor.types.GDay does not have a Month field.";
267 throw new UnsupportedOperationException(err);
268 }
269
270 public void setMonth(short month) {
271 String err = "org.exolab.castor.types.GDay does not have a Month field.";
272 throw new UnsupportedOperationException(err);
273 }
274
275 public boolean hasHour() {
276 return false;
277 }
278
279 public short getHour() {
280 String err = "org.exolab.castor.types.GDay does not have an Hour field.";
281 throw new UnsupportedOperationException(err);
282 }
283
284 public void setHour(short hour) {
285 String err = "org.exolab.castor.types.GDay does not have an Hour field.";
286 throw new UnsupportedOperationException(err);
287 }
288
289 public boolean hasMinute() {
290 return false;
291 }
292
293 public short getMinute() {
294 String err = "org.exolab.castor.types.GDay does not have a Minute field.";
295 throw new UnsupportedOperationException(err);
296 }
297
298 public void setMinute(short minute) {
299 String err = "org.exolab.castor.types.GDay does not have a Minute field.";
300 throw new UnsupportedOperationException(err);
301 }
302
303 public boolean hasSeconds() {
304 return false;
305 }
306
307 public short getSeconds() {
308 String err = "org.exolab.castor.types.GDay does not have a Seconds field.";
309 throw new UnsupportedOperationException(err);
310 }
311
312 public void setSecond(short second) {
313 String err = "org.exolab.castor.types.GDay does not have a Seconds field.";
314 throw new UnsupportedOperationException(err);
315 }
316
317 public boolean hasMilli() {
318 return false;
319 }
320
321 public short getMilli() {
322 String err = "org.exolab.castor.types.GDay does not have a Milliseconds field.";
323 throw new UnsupportedOperationException(err);
324 }
325
326 public void setMilliSecond(short millisecond) {
327 String err = "org.exolab.castor.types.GDay does not have a Milliseconds field.";
328 throw new UnsupportedOperationException(err);
329 }
330
331 }