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.i18n;
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 Alexander Klein
26 * @since 2.0.0
27 */
28 public class NoSuchMessageException extends RuntimeException {
29 private static final long serialVersionUID = -74043113109264466L;
30
31 private final String key;
32 private final Locale locale;
33
34 /**
35 * Create a new exception.
36 *
37 * @param key message that could not be resolved for given locale
38 * @param locale locale that was used to search for the code within
39 */
40 public NoSuchMessageException(@Nonnull String key, @Nonnull Locale locale) {
41 super("No message found under key '" + requireNonBlank(key, "key") + "' for locale '" + requireNonNull(locale, "locale") + "'.");
42 this.key = key;
43 this.locale = locale;
44 }
45
46 /**
47 * Create a new exception.
48 *
49 * @param key key that could not be resolved for given locale
50 */
51 public NoSuchMessageException(@Nonnull String key) {
52 this(key, Locale.getDefault());
53 }
54
55 /**
56 * Get the key without a valid value
57 *
58 * @return The key
59 */
60 @Nonnull
61 public String getKey() {
62 return key;
63 }
64
65 /**
66 * Get the locale without a valid value
67 *
68 * @return The locale
69 */
70 @Nonnull
71 public Locale getLocale() {
72 return locale;
73 }
74 }
|