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.camel.processor.validation;
018
019 import java.util.List;
020
021 import org.xml.sax.SAXParseException;
022
023 import org.apache.camel.Exchange;
024 import org.apache.camel.ValidationException;
025
026 /**
027 * A Schema validation exception occurred
028 *
029 * @version $Revision: 835531 $
030 */
031 public class SchemaValidationException extends ValidationException {
032 private static final long serialVersionUID = 2656907296674888684L;
033
034 private final Object schema;
035 private final List<SAXParseException> fatalErrors;
036 private final List<SAXParseException> errors;
037 private final List<SAXParseException> warnings;
038
039 public SchemaValidationException(Exchange exchange, Object schema, List<SAXParseException> fatalErrors,
040 List<SAXParseException> errors, List<SAXParseException> warnings) {
041 super(exchange, message(schema, fatalErrors, errors, warnings));
042 this.schema = schema;
043 this.fatalErrors = fatalErrors;
044 this.errors = errors;
045 this.warnings = warnings;
046 }
047
048 /**
049 * Returns the schema that failed
050 */
051 public Object getSchema() {
052 return schema;
053 }
054
055 /**
056 * Returns the validation errors
057 */
058 public List<SAXParseException> getErrors() {
059 return errors;
060 }
061
062 /**
063 * Returns the fatal validation errors
064 */
065 public List<SAXParseException> getFatalErrors() {
066 return fatalErrors;
067 }
068
069 /**
070 * Returns the validation warnings
071 */
072 public List<SAXParseException> getWarnings() {
073 return warnings;
074 }
075
076 protected static String message(Object schema, List<SAXParseException> fatalErrors,
077 List<SAXParseException> errors, List<SAXParseException> warnings) {
078 StringBuffer buffer = new StringBuffer("Validation failed for: ");
079 buffer.append(schema);
080
081 if (!fatalErrors.isEmpty()) {
082 buffer.append(" fatal errors: ");
083 buffer.append(fatalErrors);
084 }
085 if (!errors.isEmpty()) {
086 buffer.append(" errors: ");
087 buffer.append(errors);
088 }
089
090 return buffer.toString();
091 }
092 }