01 /*
02 * Copyright 2008-2014 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 = -8457840608859745331L;
31
32 private final String key;
33 private final Locale locale;
34
35 /**
36 * Create a new exception.
37 *
38 * @param key message 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 super("No resource found under key '" + requireNonBlank(key, "key") + "' for locale '" + requireNonNull(locale, "locale") + "'.");
43 this.key = key;
44 this.locale = locale;
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 * Get the key without a valid value
58 *
59 * @return The key
60 */
61 @Nonnull
62 public String getKey() {
63 return key;
64 }
65
66 /**
67 * Get the locale without a valid value
68 *
69 * @return The locale
70 */
71 @Nonnull
72 public Locale getLocale() {
73 return locale;
74 }
75 }
|