KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > validation > CountingErrorHandler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.servicemix.components.validation;
18
19 import javax.jbi.messaging.MessagingException;
20
21 import org.xml.sax.ErrorHandler JavaDoc;
22 import org.xml.sax.SAXParseException JavaDoc;
23 import org.xml.sax.SAXException JavaDoc;
24
25 /**
26  * A simple implementation of {@link ErrorHandler} which just counts the number of warnings, errors and fatal errors.
27  *
28  * @version $Revision: 430194 $
29  */

30 public class CountingErrorHandler implements MessageAwareErrorHandler {
31     private int warningCount;
32     private int errorCount;
33     private int fatalErrorCount;
34
35     /* (non-Javadoc)
36      * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#hasErrors()
37      */

38     public boolean hasErrors() {
39         return getErrorCount() > 0 || getFatalErrorCount() > 0;
40     }
41
42     /* (non-Javadoc)
43      * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getWarningCount()
44      */

45     public int getWarningCount() {
46         return warningCount;
47     }
48
49     /* (non-Javadoc)
50      * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getErrorCount()
51      */

52     public int getErrorCount() {
53         return errorCount;
54     }
55
56     /* (non-Javadoc)
57      * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getFatalErrorCount()
58      */

59     public int getFatalErrorCount() {
60         return fatalErrorCount;
61     }
62
63     /* (non-Javadoc)
64      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
65      */

66     public void warning(SAXParseException JavaDoc e) throws SAXException JavaDoc {
67         ++warningCount;
68     }
69
70     /* (non-Javadoc)
71      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
72      */

73     public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc {
74         ++errorCount;
75     }
76
77     /* (non-Javadoc)
78      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
79      */

80     public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc {
81         ++fatalErrorCount;
82     }
83     
84     /* (non-Javadoc)
85      * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#capturesMessages()
86      */

87     public boolean capturesMessages() {
88         return false;
89     }
90
91     /* (non-Javadoc)
92      * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getMessagesAs(java.lang.Class)
93      */

94     public Object JavaDoc getMessagesAs(Class JavaDoc format) throws MessagingException {
95         throw new MessagingException("Unsupported message format: " + format.getName());
96     }
97
98     /* (non-Javadoc)
99      * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#supportsMessageFormat(java.lang.Class)
100      */

101     public boolean supportsMessageFormat(Class JavaDoc format) {
102         return false;
103     }
104     
105 }
106
Popular Tags