1 package net.sourceforge.harness.xml.jaxb;
2
3 import net.sourceforge.harness.xml.jaxb.Description;
4 import net.sourceforge.harness.xml.jaxb.Execution;
5 import net.sourceforge.harness.xml.jaxb.Messages;
6 import net.sourceforge.harness.xml.jaxb.Property;
7 import net.sourceforge.harness.xml.jaxb.ResultEnum;
8
9 import java.io.IOException;
10 import java.io.InputStream;
11
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
15
16 import javax.xml.bind.ConversionException;
17 import javax.xml.bind.Dispatcher;
18 import javax.xml.bind.DuplicateAttributeException;
19 import javax.xml.bind.Element;
20 import javax.xml.bind.InvalidAttributeException;
21 import javax.xml.bind.InvalidContentObjectException;
22 import javax.xml.bind.LocalValidationException;
23 import javax.xml.bind.MarshallableObject;
24 import javax.xml.bind.Marshaller;
25 import javax.xml.bind.MissingAttributeException;
26 import javax.xml.bind.PredicatedLists;
27 import javax.xml.bind.PredicatedLists.Predicate;
28 import javax.xml.bind.StructureValidationException;
29 import javax.xml.bind.UnmarshalException;
30 import javax.xml.bind.Unmarshaller;
31 import javax.xml.bind.ValidatableObject;
32 import javax.xml.bind.Validator;
33 import javax.xml.marshal.XMLScanner;
34 import javax.xml.marshal.XMLWriter;
35
36
37 public class TestCase extends MarshallableObject implements Element {
38 private Description _Description;
39 private Execution _Execution;
40 private List _PropertyList = PredicatedLists.createInvalidating(this,
41 new PropertyListPredicate(), new ArrayList());
42 private PredicatedLists.Predicate pred_PropertyList = new PropertyListPredicate();
43 private Messages _Messages;
44 private String _Name;
45 private String _ClassName;
46 private ResultEnum _Result;
47
48 public Description getDescription() {
49 return _Description;
50 }
51
52 public void setDescription(Description _Description) {
53 this._Description = _Description;
54
55 if (_Description == null) {
56 invalidate();
57 }
58 }
59
60 public Execution getExecution() {
61 return _Execution;
62 }
63
64 public void setExecution(Execution _Execution) {
65 this._Execution = _Execution;
66
67 if (_Execution == null) {
68 invalidate();
69 }
70 }
71
72 public List getPropertyList() {
73 return _PropertyList;
74 }
75
76 public void deletePropertyList() {
77 _PropertyList = null;
78 invalidate();
79 }
80
81 public void emptyPropertyList() {
82 _PropertyList = PredicatedLists.createInvalidating(this,
83 pred_PropertyList, new ArrayList());
84 }
85
86 public Messages getMessages() {
87 return _Messages;
88 }
89
90 public void setMessages(Messages _Messages) {
91 this._Messages = _Messages;
92
93 if (_Messages == null) {
94 invalidate();
95 }
96 }
97
98 public String getName() {
99 return _Name;
100 }
101
102 public void setName(String _Name) {
103 this._Name = _Name;
104
105 if (_Name == null) {
106 invalidate();
107 }
108 }
109
110 public String getClassName() {
111 return _ClassName;
112 }
113
114 public void setClassName(String _ClassName) {
115 this._ClassName = _ClassName;
116
117 if (_ClassName == null) {
118 invalidate();
119 }
120 }
121
122 public ResultEnum getResult() {
123 return _Result;
124 }
125
126 public void setResult(ResultEnum _Result) {
127 this._Result = _Result;
128
129 if (_Result == null) {
130 invalidate();
131 }
132 }
133
134 public void validateThis() throws LocalValidationException {
135 if (_Name == null) {
136 throw new MissingAttributeException("name");
137 }
138
139 if (_ClassName == null) {
140 throw new MissingAttributeException("className");
141 }
142 }
143
144 /**
145 * JAXB 1.0 EA bug fix for handling optional elements
146 */
147 public void validate(Validator v) throws StructureValidationException {
148 if (_Description != null) {
149 v.validate(_Description);
150 }
151
152 if (_Execution != null) {
153 v.validate(_Execution);
154 }
155
156 for (Iterator i = _PropertyList.iterator(); i.hasNext();) {
157 v.validate(((ValidatableObject) i.next()));
158 }
159
160 v.validate(_Messages);
161 }
162
163 public void marshal(Marshaller m) throws IOException {
164 XMLWriter w = m.writer();
165 w.start("testCase");
166 w.attribute("name", _Name.toString());
167 w.attribute("className", _ClassName.toString());
168
169 if (_Result != null) {
170 w.attribute("result", _Result.toString());
171 }
172
173 if (_Description != null) {
174 m.marshal(_Description);
175 }
176
177 if (_Execution != null) {
178 m.marshal(_Execution);
179 }
180
181 if (_PropertyList.size() > 0) {
182 for (Iterator i = _PropertyList.iterator(); i.hasNext();) {
183 m.marshal(((MarshallableObject) i.next()));
184 }
185 }
186
187 if (_Messages != null) {
188 m.marshal(_Messages);
189 }
190
191 w.end("testCase");
192 }
193
194 public void unmarshal(Unmarshaller u) throws UnmarshalException {
195 XMLScanner xs = u.scanner();
196 Validator v = u.validator();
197 xs.takeStart("testCase");
198
199 while (xs.atAttribute()) {
200 String an = xs.takeAttributeName();
201
202 if (an.equals("name")) {
203 if (_Name != null) {
204 throw new DuplicateAttributeException(an);
205 }
206
207 _Name = xs.takeAttributeValue();
208
209 continue;
210 }
211
212 if (an.equals("className")) {
213 if (_ClassName != null) {
214 throw new DuplicateAttributeException(an);
215 }
216
217 _ClassName = xs.takeAttributeValue();
218
219 continue;
220 }
221
222 if (an.equals("result")) {
223 if (_Result != null) {
224 throw new DuplicateAttributeException(an);
225 }
226
227 try {
228 _Result = ResultEnum.parse(xs.takeAttributeValue());
229 } catch (Exception x) {
230 throw new ConversionException(an, x);
231 }
232
233 continue;
234 }
235
236 throw new InvalidAttributeException(an);
237 }
238
239 if (xs.atStart("description")) {
240 _Description = ((Description) u.unmarshal());
241 }
242
243 if (xs.atStart("execution")) {
244 _Execution = ((Execution) u.unmarshal());
245 }
246
247 {
248 List l = PredicatedLists.create(this, pred_PropertyList,
249 new ArrayList());
250
251 while (xs.atStart("property")) {
252 l.add(((Property) u.unmarshal()));
253 }
254
255 _PropertyList = PredicatedLists.createInvalidating(this,
256 pred_PropertyList, l);
257 }
258
259 if (xs.atStart("messages")) {
260 _Messages = ((Messages) u.unmarshal());
261 }
262
263 xs.takeEnd("testCase");
264 }
265
266 public static TestCase unmarshal(InputStream in) throws UnmarshalException {
267 return unmarshal(XMLScanner.open(in));
268 }
269
270 public static TestCase unmarshal(XMLScanner xs) throws UnmarshalException {
271 return unmarshal(xs, newDispatcher());
272 }
273
274 public static TestCase unmarshal(XMLScanner xs, Dispatcher d)
275 throws UnmarshalException {
276 return ((TestCase) d.unmarshal(xs, (TestCase.class)));
277 }
278
279 public boolean equals(Object ob) {
280 if (this == ob) {
281 return true;
282 }
283
284 if (!(ob instanceof TestCase)) {
285 return false;
286 }
287
288 TestCase tob = ((TestCase) ob);
289
290 if (_Description != null) {
291 if (tob._Description == null) {
292 return false;
293 }
294
295 if (!_Description.equals(tob._Description)) {
296 return false;
297 }
298 } else {
299 if (tob._Description != null) {
300 return false;
301 }
302 }
303
304 if (_Execution != null) {
305 if (tob._Execution == null) {
306 return false;
307 }
308
309 if (!_Execution.equals(tob._Execution)) {
310 return false;
311 }
312 } else {
313 if (tob._Execution != null) {
314 return false;
315 }
316 }
317
318 if (_PropertyList != null) {
319 if (tob._PropertyList == null) {
320 return false;
321 }
322
323 if (!_PropertyList.equals(tob._PropertyList)) {
324 return false;
325 }
326 } else {
327 if (tob._PropertyList != null) {
328 return false;
329 }
330 }
331
332 if (_Messages != null) {
333 if (tob._Messages == null) {
334 return false;
335 }
336
337 if (!_Messages.equals(tob._Messages)) {
338 return false;
339 }
340 } else {
341 if (tob._Messages != null) {
342 return false;
343 }
344 }
345
346 if (_Name != null) {
347 if (tob._Name == null) {
348 return false;
349 }
350
351 if (!_Name.equals(tob._Name)) {
352 return false;
353 }
354 } else {
355 if (tob._Name != null) {
356 return false;
357 }
358 }
359
360 if (_ClassName != null) {
361 if (tob._ClassName == null) {
362 return false;
363 }
364
365 if (!_ClassName.equals(tob._ClassName)) {
366 return false;
367 }
368 } else {
369 if (tob._ClassName != null) {
370 return false;
371 }
372 }
373
374 if (_Result != null) {
375 if (tob._Result == null) {
376 return false;
377 }
378
379 if (!_Result.equals(tob._Result)) {
380 return false;
381 }
382 } else {
383 if (tob._Result != null) {
384 return false;
385 }
386 }
387
388 return true;
389 }
390
391 public int hashCode() {
392 int h = 0;
393 h = ((127 * h) +
394 ((_Description != null) ? _Description.hashCode() : 0));
395 h = ((127 * h) + ((_Execution != null) ? _Execution.hashCode() : 0));
396 h = ((127 * h) +
397 ((_PropertyList != null) ? _PropertyList.hashCode() : 0));
398 h = ((127 * h) + ((_Messages != null) ? _Messages.hashCode() : 0));
399 h = ((127 * h) + ((_Name != null) ? _Name.hashCode() : 0));
400 h = ((127 * h) + ((_ClassName != null) ? _ClassName.hashCode() : 0));
401 h = ((127 * h) + ((_Result != null) ? _Result.hashCode() : 0));
402
403 return h;
404 }
405
406 public String toString() {
407 StringBuffer sb = new StringBuffer("<<testCase");
408
409 if (_Description != null) {
410 sb.append(" description=");
411 sb.append(_Description.toString());
412 }
413
414 if (_Execution != null) {
415 sb.append(" execution=");
416 sb.append(_Execution.toString());
417 }
418
419 if (_PropertyList != null) {
420 sb.append(" property=");
421 sb.append(_PropertyList.toString());
422 }
423
424 if (_Messages != null) {
425 sb.append(" messages=");
426 sb.append(_Messages.toString());
427 }
428
429 if (_Name != null) {
430 sb.append(" name=");
431 sb.append(_Name.toString());
432 }
433
434 if (_ClassName != null) {
435 sb.append(" className=");
436 sb.append(_ClassName.toString());
437 }
438
439 if (_Result != null) {
440 sb.append(" result=");
441 sb.append(_Result.toString());
442 }
443
444 sb.append(">>");
445
446 return sb.toString();
447 }
448
449 public static Dispatcher newDispatcher() {
450 return Author.newDispatcher();
451 }
452
453 private static class PropertyListPredicate
454 implements PredicatedLists.Predicate {
455 public void check(Object ob) {
456 if (!(ob instanceof Property)) {
457 throw new InvalidContentObjectException(ob, (Property.class));
458 }
459 }
460 }
461 }