001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.validation.handler;
018
019 import javax.jbi.messaging.MessagingException;
020
021 import org.xml.sax.SAXException;
022 import org.xml.sax.SAXParseException;
023
024 /**
025 * A simple implementation of {@link ErrorHandler} which just counts the number of warnings, errors and fatal errors.
026 *
027 * @version $Revision: 430194 $
028 */
029 public class CountingErrorHandler implements MessageAwareErrorHandler {
030 private int warningCount;
031 private int errorCount;
032 private int fatalErrorCount;
033
034 /* (non-Javadoc)
035 * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#hasErrors()
036 */
037 public boolean hasErrors() {
038 return getErrorCount() > 0 || getFatalErrorCount() > 0;
039 }
040
041 /* (non-Javadoc)
042 * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getWarningCount()
043 */
044 public int getWarningCount() {
045 return warningCount;
046 }
047
048 /* (non-Javadoc)
049 * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getErrorCount()
050 */
051 public int getErrorCount() {
052 return errorCount;
053 }
054
055 /* (non-Javadoc)
056 * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getFatalErrorCount()
057 */
058 public int getFatalErrorCount() {
059 return fatalErrorCount;
060 }
061
062 /* (non-Javadoc)
063 * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
064 */
065 public void warning(SAXParseException e) throws SAXException {
066 ++warningCount;
067 }
068
069 /* (non-Javadoc)
070 * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
071 */
072 public void error(SAXParseException e) throws SAXException {
073 ++errorCount;
074 }
075
076 /* (non-Javadoc)
077 * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
078 */
079 public void fatalError(SAXParseException e) throws SAXException {
080 ++fatalErrorCount;
081 }
082
083 /* (non-Javadoc)
084 * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#capturesMessages()
085 */
086 public boolean capturesMessages() {
087 return false;
088 }
089
090 /*
091 * (non-Javadoc)
092 *
093 * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getMessagesAs(java.lang.Class)
094 */
095 public Object getMessagesAs(Class format) throws MessagingException {
096 throw new MessagingException("Unsupported message format: " + format.getName());
097 }
098
099 /*
100 * (non-Javadoc)
101 *
102 * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#supportsMessageFormat(java.lang.Class)
103 */
104 public boolean supportsMessageFormat(Class format) {
105 return false;
106 }
107
108 }