OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / dom / src / test / java / org / w3c / domts / DOMErrorMonitor.java
1 /*
2  * Copyright (c) 2004 World Wide Web Consortium,
3  * (Massachusetts Institute of Technology, Institut National de
4  * Recherche en Informatique et en Automatique, Keio University). All
5  * Rights Reserved. This program is distributed under the W3C's Software
6  * Intellectual Property License. This program is distributed in the
7  * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  * PURPOSE.
10  * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
11  */
12
13 package org.w3c.domts;
14
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.Iterator;
18
19 import org.w3c.dom.DOMError;
20 import org.w3c.dom.DOMErrorHandler;
21
22 /**
23  *   This is a utility implementation of EventListener
24  *      that captures all events and provides access
25  *      to lists of all events by mode
26  */
27 public class DOMErrorMonitor
28     implements DOMErrorHandler {
29   private final List errors = new ArrayList();
30
31   /**
32    * Public constructor
33    *
34    */
35   public DOMErrorMonitor() {
36   }
37
38   /**
39    * Implementation of DOMErrorHandler.handleError that
40    * adds copy of error to list for later retrieval.
41    *
42    */
43   public boolean handleError(DOMError error) {
44     errors.add(new DOMErrorImpl(error));
45     return true;
46   }
47
48   /**
49    * Gets list of errors
50    *
51    * @return return errors
52    */
53   public List getAllErrors() {
54     return new ArrayList(errors);
55   }
56
57   public void assertLowerSeverity(DOMTestCase testCase, String id, int severity) {
58     Iterator iter = errors.iterator();
59     while (iter.hasNext()) {
60       DOMError error = (DOMError) iter.next();
61       if (error.getSeverity() >= severity) {
62         testCase.fail(id + error.getMessage());
63       }
64     }
65   }
66 }