1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
26
26
*
27
27
* <p>Spring provides two out-of-the-box implementations for production:
28
28
* <ul>
29
- * <li>{@link org.springframework.context.support.ResourceBundleMessageSource},
30
- * built on top of the standard {@link java.util.ResourceBundle}
31
- * <li>{@link org.springframework.context.support.ReloadableResourceBundleMessageSource},
32
- * being able to reload message definitions without restarting the VM
29
+ * <li>{@link org.springframework.context.support.ResourceBundleMessageSource}: built
30
+ * on top of the standard {@link java.util.ResourceBundle}, sharing its limitations.
31
+ * <li>{@link org.springframework.context.support.ReloadableResourceBundleMessageSource}:
32
+ * highly configurable, in particular with respect to reloading message definitions.
33
33
* </ul>
34
34
*
35
35
* @author Rod Johnson
@@ -41,30 +41,34 @@ public interface MessageSource {
41
41
42
42
/**
43
43
* Try to resolve the message. Return default message if no message was found.
44
- * @param code the code to lookup up, such as 'calculator.noRateSet'. Users of
45
- * this class are encouraged to base message names on the relevant fully
46
- * qualified class name, thus avoiding conflict and ensuring maximum clarity.
44
+ * @param code the code to lookup up, e.g. 'calculator.noRateSet'.
45
+ * MessageSource users are encouraged to base message names on qualified class
46
+ * or package names, avoiding potential conflicts and ensuring maximum clarity.
47
47
* @param args an array of arguments that will be filled in for params within
48
48
* the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
49
- * or {@code null} if none.
49
+ * or {@code null} if none
50
50
* @param defaultMessage a default message to return if the lookup fails
51
51
* @param locale the locale in which to do the lookup
52
- * @return the resolved message if the lookup was successful;
53
- * otherwise the default message passed as a parameter
52
+ * @return the resolved message if the lookup was successful, otherwise
53
+ * the default message passed as a parameter (which may be {@code null})
54
+ * @see #getMessage(MessageSourceResolvable, Locale)
54
55
* @see java.text.MessageFormat
55
56
*/
56
57
@ Nullable
57
58
String getMessage (String code , @ Nullable Object [] args , @ Nullable String defaultMessage , Locale locale );
58
59
59
60
/**
60
61
* Try to resolve the message. Treat as an error if the message can't be found.
61
- * @param code the code to lookup up, such as 'calculator.noRateSet'
62
+ * @param code the code to lookup up, e.g. 'calculator.noRateSet'.
63
+ * MessageSource users are encouraged to base message names on qualified class
64
+ * or package names, avoiding potential conflicts and ensuring maximum clarity.
62
65
* @param args an array of arguments that will be filled in for params within
63
66
* the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
64
- * or {@code null} if none.
67
+ * or {@code null} if none
65
68
* @param locale the locale in which to do the lookup
66
- * @return the resolved message
67
- * @throws NoSuchMessageException if the message wasn't found
69
+ * @return the resolved message (never {@code null})
70
+ * @throws NoSuchMessageException if no corresponding message was found
71
+ * @see #getMessage(MessageSourceResolvable, Locale)
68
72
* @see java.text.MessageFormat
69
73
*/
70
74
String getMessage (String code , @ Nullable Object [] args , Locale locale ) throws NoSuchMessageException ;
@@ -76,9 +80,15 @@ public interface MessageSource {
76
80
* since at the time of calling this method we aren't able to determine if the
77
81
* {@code defaultMessage} property of the resolvable is {@code null} or not.
78
82
* @param resolvable the value object storing attributes required to resolve a message
83
+ * (may include a default message)
79
84
* @param locale the locale in which to do the lookup
80
- * @return the resolved message
81
- * @throws NoSuchMessageException if the message wasn't found
85
+ * @return the resolved message (never {@code null} since even a
86
+ * {@code MessageSourceResolvable}-provided default message needs to be non-null)
87
+ * @throws NoSuchMessageException if no corresponding message was found
88
+ * (and no default message was provided by the {@code MessageSourceResolvable})
89
+ * @see MessageSourceResolvable#getCodes()
90
+ * @see MessageSourceResolvable#getArguments()
91
+ * @see MessageSourceResolvable#getDefaultMessage()
82
92
* @see java.text.MessageFormat
83
93
*/
84
94
String getMessage (MessageSourceResolvable resolvable , Locale locale ) throws NoSuchMessageException ;
0 commit comments