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