01 /*
02 * SPDX-License-Identifier: Apache-2.0
03 *
04 * Copyright 2008-2017 the original author or authors.
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package griffon.core.resources;
19
20 import javax.annotation.Nonnull;
21 import java.util.Locale;
22
23 import static griffon.util.GriffonNameUtils.requireNonBlank;
24 import static java.util.Objects.requireNonNull;
25
26 /**
27 * @author Andres Almiray
28 * @author Alexander Klein
29 * @since 2.0.0
30 */
31 public class NoSuchResourceException extends RuntimeException {
32 private static final long serialVersionUID = -8111520682896523405L;
33
34 private final String key;
35 private final Locale locale;
36
37 /**
38 * Create a new exception.
39 *
40 * @param key key that could not be resolved for given locale
41 * @param locale locale that was used to search for the code within
42 */
43 public NoSuchResourceException(@Nonnull String key, @Nonnull Locale locale) {
44 this(key, locale, null);
45 }
46
47 /**
48 * Create a new exception.
49 *
50 * @param key key that could not be resolved for given locale
51 */
52 public NoSuchResourceException(@Nonnull String key) {
53 this(key, Locale.getDefault());
54 }
55
56 /**
57 * Create a new exception.
58 *
59 * @param key key that could not be resolved for given locale
60 * @param cause throwable that caused this exception
61 */
62 public NoSuchResourceException(@Nonnull String key, @Nonnull Throwable cause) {
63 this(key, Locale.getDefault(), cause);
64 }
65
66 /**
67 * Create a new exception.
68 *
69 * @param key key that could not be resolved for given locale
70 * @param locale locale that was used to search for the code within
71 * @param cause throwable that caused this exception
72 */
73 public NoSuchResourceException(@Nonnull String key, @Nonnull Locale locale, @Nonnull Throwable cause) {
74 super("No resource found under key '" + requireNonBlank(key, "key") + "' for locale '" + requireNonNull(locale, "locale") + "'.", cause);
75 this.key = key;
76 this.locale = locale;
77 }
78
79 /**
80 * Get the key without a valid value
81 *
82 * @return The key
83 */
84 @Nonnull
85 public String getKey() {
86 return key;
87 }
88
89 /**
90 * Get the locale without a valid value
91 *
92 * @return The locale
93 */
94 @Nonnull
95 public Locale getLocale() {
96 return locale;
97 }
98 }
|