1b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov/** 211a89b445f3bde56bf07e6a0d04f0b0256dcb215Andrey Somov * Copyright (c) 2008, http://www.snakeyaml.org 3b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * 4b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * Licensed under the Apache License, Version 2.0 (the "License"); 5b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * you may not use this file except in compliance with the License. 6b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * You may obtain a copy of the License at 7b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * 8b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * http://www.apache.org/licenses/LICENSE-2.0 9b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * 10b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * Unless required by applicable law or agreed to in writing, software 11b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * distributed under the License is distributed on an "AS IS" BASIS, 12b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * See the License for the specific language governing permissions and 14b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * limitations under the License. 15b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov */ 16b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somovpackage org.yaml.snakeyaml.error; 17b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 18b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somovpublic class MarkedYAMLException extends YAMLException { 19b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 20b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov private static final long serialVersionUID = -9119388488683035101L; 21b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov private String context; 22b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov private Mark contextMark; 23b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov private String problem; 24b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov private Mark problemMark; 25b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov private String note; 26b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 27b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov protected MarkedYAMLException(String context, Mark contextMark, String problem, 28b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov Mark problemMark, String note) { 29b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov this(context, contextMark, problem, problemMark, note, null); 30b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 31b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 32b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov protected MarkedYAMLException(String context, Mark contextMark, String problem, 33b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov Mark problemMark, String note, Throwable cause) { 34ff29b153da457acf677a48bd948f7307491678bcAndrey Somov super(context + "; " + problem + "; " + problemMark, cause); 35b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov this.context = context; 36b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov this.contextMark = contextMark; 37b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov this.problem = problem; 38b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov this.problemMark = problemMark; 39b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov this.note = note; 40b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 41b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 42b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov protected MarkedYAMLException(String context, Mark contextMark, String problem, Mark problemMark) { 43b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov this(context, contextMark, problem, problemMark, null, null); 44b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 45b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 46b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov protected MarkedYAMLException(String context, Mark contextMark, String problem, 47b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov Mark problemMark, Throwable cause) { 48b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov this(context, contextMark, problem, problemMark, null, cause); 49b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 50b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 51b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov @Override 528d3a3b28be441119d38004b605b7e7c010b1665bAndrey Somov public String getMessage() { 538d3a3b28be441119d38004b605b7e7c010b1665bAndrey Somov return toString(); 548d3a3b28be441119d38004b605b7e7c010b1665bAndrey Somov } 558d3a3b28be441119d38004b605b7e7c010b1665bAndrey Somov 568d3a3b28be441119d38004b605b7e7c010b1665bAndrey Somov @Override 57b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov public String toString() { 58b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov StringBuilder lines = new StringBuilder(); 59b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov if (context != null) { 60b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append(context); 61b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append("\n"); 62b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 63b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov if (contextMark != null 64b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov && (problem == null || problemMark == null 6525ac3b280b35ddb9167e0528626e2ec14488f173Andrey Somov || contextMark.getName().equals(problemMark.getName()) 66b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov || (contextMark.getLine() != problemMark.getLine()) || (contextMark 67b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov .getColumn() != problemMark.getColumn()))) { 68b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append(contextMark.toString()); 69b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append("\n"); 70b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 71b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov if (problem != null) { 72b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append(problem); 73b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append("\n"); 74b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 75b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov if (problemMark != null) { 76b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append(problemMark.toString()); 77b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append("\n"); 78b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 79b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov if (note != null) { 80b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append(note); 81b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov lines.append("\n"); 82b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 83b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov return lines.toString(); 84b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 85b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 86b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov public String getContext() { 87b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov return context; 88b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 89b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 90b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov public Mark getContextMark() { 91b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov return contextMark; 92b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 93b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 94b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov public String getProblem() { 95b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov return problem; 96b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 97b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov 98b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov public Mark getProblemMark() { 99b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov return problemMark; 100b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov } 101b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov} 102