Jonathan Hart | bc7a8bf | 2016-03-26 20:37:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.net.config; |
| 18 | |
| 19 | /** |
| 20 | * Indicates an invalid configuration was supplied by the user. |
| 21 | */ |
| 22 | public class InvalidConfigException extends RuntimeException { |
| 23 | |
| 24 | private final String subjectKey; |
| 25 | private final String subject; |
| 26 | private final String configKey; |
| 27 | |
| 28 | /** |
| 29 | * Creates a new invalid config exception about a specific config. |
| 30 | * |
| 31 | * @param subjectKey config's subject key |
| 32 | * @param subject config's subject |
| 33 | * @param configKey config's config key |
| 34 | */ |
| 35 | public InvalidConfigException(String subjectKey, String subject, String configKey) { |
| 36 | this(subjectKey, subject, configKey, null); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Creates a new invalid config exception about a specific config with an |
| 41 | * exception regarding the cause of the invalidity. |
| 42 | * |
| 43 | * @param subjectKey config's subject key |
| 44 | * @param subject config's subject |
| 45 | * @param configKey config's config key |
| 46 | * @param cause cause of the invalidity |
| 47 | */ |
| 48 | public InvalidConfigException(String subjectKey, String subject, String configKey, Throwable cause) { |
| 49 | super(message(subjectKey, subject, configKey, cause), cause); |
| 50 | this.subjectKey = subjectKey; |
| 51 | this.subject = subject; |
| 52 | this.configKey = configKey; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the subject key of the config. |
| 57 | * |
| 58 | * @return subject key |
| 59 | */ |
| 60 | public String subjectKey() { |
| 61 | return subjectKey; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the string representation of the subject of the config. |
| 66 | * |
| 67 | * @return subject |
| 68 | */ |
| 69 | public String subject() { |
| 70 | return subject; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the config key of the config. |
| 75 | * |
| 76 | * @return config key |
| 77 | */ |
| 78 | public String configKey() { |
| 79 | return configKey; |
| 80 | } |
| 81 | |
| 82 | private static String message(String subjectKey, String subject, String configKey, Throwable cause) { |
| 83 | String error = "Error parsing config " + subjectKey + "/" + subject + "/" + configKey; |
| 84 | if (cause != null) { |
| 85 | error = error + ": " + cause.getMessage(); |
| 86 | } |
| 87 | return error; |
| 88 | } |
| 89 | } |