Coverage Report - org.apache.camel.processor.validation.DefaultValidationErrorHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultValidationErrorHandler
0% 
0% 
0
 
 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.camel.processor.validation;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.xml.transform.dom.DOMResult;
 23  
 import javax.xml.validation.Schema;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 import org.xml.sax.SAXException;
 28  
 import org.xml.sax.SAXParseException;
 29  
 
 30  
 import org.apache.camel.Exchange;
 31  
 import org.apache.camel.ValidationException;
 32  
 
 33  
 /**
 34  
  * A default error handler which just stores all the errors so they can be reported or transformed.
 35  
  * 
 36  
  * @version $Revision: $
 37  
  */
 38  0
 public class DefaultValidationErrorHandler implements ValidatorErrorHandler {
 39  0
     private static final transient Log log = LogFactory.getLog(DefaultValidationErrorHandler.class);
 40  0
     private List<SAXParseException> warnings = new ArrayList<SAXParseException>();
 41  0
     private List<SAXParseException> errors = new ArrayList<SAXParseException>();
 42  0
     private List<SAXParseException> fatalErrors = new ArrayList<SAXParseException>();
 43  
 
 44  
     public void warning(SAXParseException e) throws SAXException {
 45  0
         if (log.isDebugEnabled()) {
 46  0
             log.debug("warning: " + e, e);
 47  
         }
 48  0
         warnings.add(e);
 49  0
     }
 50  
 
 51  
     public void error(SAXParseException e) throws SAXException {
 52  0
         if (log.isDebugEnabled()) {
 53  0
             log.debug("error: " + e, e);
 54  
         }
 55  0
         errors.add(e);
 56  0
     }
 57  
 
 58  
     public void fatalError(SAXParseException e) throws SAXException {
 59  0
         if (log.isDebugEnabled()) {
 60  0
             log.debug("fatalError: " + e, e);
 61  
         }
 62  0
         fatalErrors.add(e);
 63  0
     }
 64  
 
 65  
     public void reset() {
 66  0
     }
 67  
 
 68  
     public boolean isValid() {
 69  0
         return errors.isEmpty() && fatalErrors.isEmpty();
 70  
     }
 71  
 
 72  
     public void handleErrors(Exchange exchange, Schema schema, DOMResult result) throws ValidationException {
 73  0
         if (!isValid()) {
 74  0
             throw new SchemaValidationException(exchange, schema, fatalErrors, errors, warnings);
 75  
         }
 76  0
     }
 77  
 
 78  
     public void handleErrors(Exchange exchange, Object schema) throws ValidationException {
 79  0
         if (!isValid()) {
 80  0
             throw new SchemaValidationException(exchange, schema, fatalErrors, errors, warnings);
 81  
         }
 82  0
     }
 83  
 }