1/*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23package javax.xml.parsers.ptests;
24
25import org.xml.sax.SAXParseException;
26import org.xml.sax.helpers.DefaultHandler;
27
28/**
29 * Customized DefaultHandler used for SAXParseException testing.
30 */
31class MyErrorHandler extends DefaultHandler {
32    /**
33     * Flag whether any event was received.
34     */
35    private volatile boolean errorOccured;
36
37    /**
38     * Set no event received on constructor.
39     */
40    private MyErrorHandler() {
41        errorOccured = false;
42    }
43
44    /**
45     * Factory method to create a MyErrorHandler instance.
46     * @return a MyErrorHandler instance.
47     */
48    public static MyErrorHandler newInstance() {
49        return new MyErrorHandler();
50    }
51
52    /**
53     * Receive notification of a recoverable error.
54     * @param e a recoverable parser exception error.
55     */
56    @Override
57    public void error(SAXParseException e) {
58        errorOccured = true;
59    }
60
61    /**
62     * Receive notification of a parser warning.
63     * @param e a parser warning  event.
64     */
65    @Override
66    public void warning(SAXParseException e) {
67        errorOccured = true;
68    }
69
70    /**
71     * Report a fatal XML parsing error.
72     * @param e The error information encoded as an exception.
73     */
74    @Override
75    public void fatalError(SAXParseException e) {
76        errorOccured = true;
77    }
78
79    /**
80     * Has any event been received.
81     *
82     * @return true if any event has been received.
83     *         false if no event has been received.
84     */
85    public boolean isErrorOccured() {
86        return errorOccured;
87    }
88}
89