| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SchemaValidationErrorHandler |
|
| 1.25;1.25 |
| 1 | /* | |
| 2 | * Copyright 2007-2010 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl2.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.core.xml.schema; | |
| 17 | ||
| 18 | import org.xml.sax.ErrorHandler; | |
| 19 | import org.xml.sax.SAXException; | |
| 20 | import org.xml.sax.SAXParseException; | |
| 21 | ||
| 22 | /** | |
| 23 | * This is a the default error handler used by the RiceXmlSchemaFactory. | |
| 24 | * | |
| 25 | * | |
| 26 | * The class contains counters for compileErrors and compileWarnings. | |
| 27 | * * | |
| 28 | * Note: Since the current behavior of this ErrorHanlder is to throw | |
| 29 | * SAXParseExceptions on error() or fatalError(), the compileError count | |
| 30 | * is not very useful). However, custom errorHandler classes that extend | |
| 31 | * this class may find them useful. | |
| 32 | * | |
| 33 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 34 | * | |
| 35 | */ | |
| 36 | public class SchemaValidationErrorHandler implements ErrorHandler { | |
| 37 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SchemaValidationErrorHandler.class); |
| 38 | ||
| 39 | 0 | protected int compileErrors = 0; |
| 40 | 0 | protected int compileWarnings = 0; |
| 41 | ||
| 42 | 0 | public SchemaValidationErrorHandler(){ |
| 43 | 0 | } |
| 44 | ||
| 45 | /** | |
| 46 | * | |
| 47 | * This method is called when an error is encountered during schema parsing. | |
| 48 | * It's current behavior is to log and re-throw any exceptions. | |
| 49 | * | |
| 50 | * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) | |
| 51 | */ | |
| 52 | public void error(org.xml.sax.SAXParseException sAXParseException) throws org.xml.sax.SAXException { | |
| 53 | 0 | LOG.error(sAXParseException.toString(), sAXParseException); |
| 54 | 0 | compileErrors++; |
| 55 | 0 | throw sAXParseException; |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * This method is called when fatal error is encountered during schema parsing. | |
| 60 | * It's current behavior is to log and re-throw any exceptions. | |
| 61 | * | |
| 62 | * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) | |
| 63 | */ | |
| 64 | public void fatalError(org.xml.sax.SAXParseException sAXParseException) throws org.xml.sax.SAXException { | |
| 65 | 0 | LOG.fatal(sAXParseException.toString(), sAXParseException); |
| 66 | 0 | compileErrors++; |
| 67 | 0 | throw sAXParseException; |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * This method is called when warning is encountered during schema parsing. | |
| 72 | * It's current behavior is to log the error, increment the warning count, | |
| 73 | * and continue parsing. | |
| 74 | * | |
| 75 | * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) | |
| 76 | */ | |
| 77 | public void warning(org.xml.sax.SAXParseException sAXParseException) throws org.xml.sax.SAXException { | |
| 78 | 0 | LOG.warn(sAXParseException.toString(), sAXParseException); |
| 79 | 0 | compileWarnings++; |
| 80 | 0 | } |
| 81 | ||
| 82 | ||
| 83 | public int getCompileErrors() { | |
| 84 | 0 | return this.compileErrors; |
| 85 | } | |
| 86 | ||
| 87 | ||
| 88 | public void setCompileErrors(int compileErrors) { | |
| 89 | 0 | this.compileErrors = compileErrors; |
| 90 | 0 | } |
| 91 | ||
| 92 | ||
| 93 | public int getCompileWarnings() { | |
| 94 | 0 | return this.compileWarnings; |
| 95 | } | |
| 96 | ||
| 97 | ||
| 98 | public void setCompileWarnings(int compileWarnings) { | |
| 99 | 0 | this.compileWarnings = compileWarnings; |
| 100 | 0 | } |
| 101 | ||
| 102 | ||
| 103 | } |