Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
SchemaValidationException |
|
| 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.List; |
|
20 | ||
21 | import org.xml.sax.SAXParseException; |
|
22 | ||
23 | import org.apache.camel.Exchange; |
|
24 | import org.apache.camel.ValidationException; |
|
25 | ||
26 | /** |
|
27 | * A Schema validation exception occurred |
|
28 | * |
|
29 | * @version $Revision: $ |
|
30 | */ |
|
31 | public class SchemaValidationException extends ValidationException { |
|
32 | private final Object schema; |
|
33 | private final List<SAXParseException> fatalErrors; |
|
34 | private final List<SAXParseException> errors; |
|
35 | private final List<SAXParseException> warnings; |
|
36 | ||
37 | public SchemaValidationException(Exchange exchange, Object schema, List<SAXParseException> fatalErrors, |
|
38 | List<SAXParseException> errors, List<SAXParseException> warnings) { |
|
39 | 0 | super(exchange, message(schema, fatalErrors, errors, warnings)); |
40 | 0 | this.schema = schema; |
41 | 0 | this.fatalErrors = fatalErrors; |
42 | 0 | this.errors = errors; |
43 | 0 | this.warnings = warnings; |
44 | 0 | } |
45 | ||
46 | /** |
|
47 | * Returns the schema that failed |
|
48 | * |
|
49 | * @return the schema that failed |
|
50 | */ |
|
51 | public Object getSchema() { |
|
52 | 0 | return schema; |
53 | } |
|
54 | ||
55 | /** |
|
56 | * Returns the validation errors |
|
57 | * |
|
58 | * @return the validation errors |
|
59 | */ |
|
60 | public List<SAXParseException> getErrors() { |
|
61 | 0 | return errors; |
62 | } |
|
63 | ||
64 | /** |
|
65 | * Returns the fatal validation errors |
|
66 | * |
|
67 | * @return the fatal validation errors |
|
68 | */ |
|
69 | public List<SAXParseException> getFatalErrors() { |
|
70 | 0 | return fatalErrors; |
71 | } |
|
72 | ||
73 | /** |
|
74 | * Returns the validation warnings |
|
75 | * |
|
76 | * @return the validation warnings |
|
77 | */ |
|
78 | public List<SAXParseException> getWarnings() { |
|
79 | 0 | return warnings; |
80 | } |
|
81 | ||
82 | protected static String message(Object schema, List<SAXParseException> fatalErrors, |
|
83 | List<SAXParseException> errors, List<SAXParseException> warnings) { |
|
84 | 0 | StringBuffer buffer = new StringBuffer("Validation failed for: " + schema); |
85 | 0 | if (!fatalErrors.isEmpty()) { |
86 | 0 | buffer.append(" fatal errors: "); |
87 | 0 | buffer.append(fatalErrors); |
88 | } |
|
89 | 0 | if (!errors.isEmpty()) { |
90 | 0 | buffer.append(" errors: "); |
91 | 0 | buffer.append(errors); |
92 | } |
|
93 | 0 | return buffer.toString(); |
94 | } |
|
95 | } |