blob: e3c9be42bf48a7673d2cfb1ae6c5c36af22c5f32 [file] [log] [blame]
Jonathan Hart54b83e82016-03-26 20:37:20 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hart54b83e82016-03-26 20:37:20 -07003 *
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
17package org.onosproject.net.config;
18
19/**
20 * Indicates an invalid configuration was supplied by the user.
21 */
22public 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}