Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
SimpleErrorHandler |
|
| 1.75;1.75 |
1 | /* |
|
2 | * |
|
3 | * Copyright 2005 The Apache Software Foundation. |
|
4 | * |
|
5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 | * you may not use this file except in compliance with the License. |
|
7 | * You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | * |
|
17 | */ |
|
18 | package org.apache.commons.scxml.env; |
|
19 | ||
20 | import org.apache.commons.logging.Log; |
|
21 | import org.apache.commons.logging.LogFactory; |
|
22 | ||
23 | import org.xml.sax.ErrorHandler; |
|
24 | import org.xml.sax.SAXParseException; |
|
25 | ||
26 | /** |
|
27 | * Custom error handler that logs the parsing errors in the |
|
28 | * SCXML document. |
|
29 | */ |
|
30 | public class SimpleErrorHandler implements ErrorHandler { |
|
31 | ||
32 | /** Message prefix. */ |
|
33 | private static final String MSG_PREFIX = "SCXML SAX Parsing: "; |
|
34 | /** Message postfix. */ |
|
35 | private static final String MSG_POSTFIX = " Correct the SCXML document."; |
|
36 | ||
37 | /** Log. */ |
|
38 | 37 | private Log log = LogFactory.getLog(getClass()); |
39 | ||
40 | /** |
|
41 | * Constructor. |
|
42 | */ |
|
43 | public SimpleErrorHandler() { |
|
44 | 37 | super(); |
45 | 37 | } |
46 | ||
47 | /** |
|
48 | * @see ErrorHandler#error(SAXParseException) |
|
49 | */ |
|
50 | public void error(final SAXParseException exception) { |
|
51 | 0 | if (log.isErrorEnabled()) { |
52 | 0 | log.error(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX, |
53 | exception); |
|
54 | } |
|
55 | 0 | } |
56 | ||
57 | /** |
|
58 | * @see ErrorHandler#fatalError(SAXParseException) |
|
59 | */ |
|
60 | public void fatalError(final SAXParseException exception) { |
|
61 | 0 | if (log.isFatalEnabled()) { |
62 | 0 | log.fatal(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX, |
63 | exception); |
|
64 | } |
|
65 | 0 | } |
66 | ||
67 | /** |
|
68 | * @see ErrorHandler#warning(SAXParseException) |
|
69 | */ |
|
70 | public void warning(final SAXParseException exception) { |
|
71 | 0 | if (log.isWarnEnabled()) { |
72 | 0 | log.warn(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX, |
73 | exception); |
|
74 | } |
|
75 | 0 | } |
76 | } |
|
77 |