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: 747062 $
030 */
031 public class SchemaValidationException extends ValidationException {
032 private final Object schema;
033 private final List<SAXParseException> fatalErrors;
034 private final List<SAXParseException> errors;
035 private final List<SAXParseException> warnings;
036
037 public SchemaValidationException(Exchange exchange, Object schema, List<SAXParseException> fatalErrors,
038 List<SAXParseException> errors, List<SAXParseException> warnings) {
039 super(exchange, message(schema, fatalErrors, errors, warnings));
040 this.schema = schema;
041 this.fatalErrors = fatalErrors;
042 this.errors = errors;
043 this.warnings = warnings;
044 }
045
046 /**
047 * Returns the schema that failed
048 */
049 public Object getSchema() {
050 return schema;
051 }
052
053 /**
054 * Returns the validation errors
055 */
056 public List<SAXParseException> getErrors() {
057 return errors;
058 }
059
060 /**
061 * Returns the fatal validation errors
062 */
063 public List<SAXParseException> getFatalErrors() {
064 return fatalErrors;
065 }
066
067 /**
068 * Returns the validation warnings
069 */
070 public List<SAXParseException> getWarnings() {
071 return warnings;
072 }
073
074 protected static String message(Object schema, List<SAXParseException> fatalErrors,
075 List<SAXParseException> errors, List<SAXParseException> warnings) {
076 StringBuffer buffer = new StringBuffer("Validation failed for: " + schema);
077 if (!fatalErrors.isEmpty()) {
078 buffer.append(" fatal errors: ");
079 buffer.append(fatalErrors);
080 }
081 if (!errors.isEmpty()) {
082 buffer.append(" errors: ");
083 buffer.append(errors);
084 }
085 return buffer.toString();
086 }
087 }