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: 630591 $
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 * @return the schema that failed
050 */
051 public Object getSchema() {
052 return schema;
053 }
054
055 /**
056 * Returns the validation errors
057 *
058 * @return the validation errors
059 */
060 public List<SAXParseException> getErrors() {
061 return errors;
062 }
063
064 /**
065 * Returns the fatal validation errors
066 *
067 * @return the fatal validation errors
068 */
069 public List<SAXParseException> getFatalErrors() {
070 return fatalErrors;
071 }
072
073 /**
074 * Returns the validation warnings
075 *
076 * @return the validation warnings
077 */
078 public List<SAXParseException> getWarnings() {
079 return warnings;
080 }
081
082 protected static String message(Object schema, List<SAXParseException> fatalErrors,
083 List<SAXParseException> errors, List<SAXParseException> warnings) {
084 StringBuffer buffer = new StringBuffer("Validation failed for: " + schema);
085 if (!fatalErrors.isEmpty()) {
086 buffer.append(" fatal errors: ");
087 buffer.append(fatalErrors);
088 }
089 if (!errors.isEmpty()) {
090 buffer.append(" errors: ");
091 buffer.append(errors);
092 }
093 return buffer.toString();
094 }
095 }