| | |
| | | |
| | | import java.util.Locale; |
| | | import java.util.ResourceBundle; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Base class for all Message descriptor classes. |
| | |
| | | */ |
| | | private Message message; |
| | | |
| | | private boolean requiresFormat; |
| | | |
| | | /** |
| | | * Creates a parameterized instance. |
| | | * @param rbBase base of the backing resource bundle |
| | |
| | | Severity severity, int ordinal, ClassLoader classLoader) { |
| | | super(rbBase, key, category, severity, ordinal, classLoader); |
| | | message = new Message(this); |
| | | requiresFormat = containsArgumentLiterals(getFormatString()); |
| | | } |
| | | |
| | | /** |
| | |
| | | Severity severity, int ordinal, ClassLoader classLoader) { |
| | | super(rbBase, key, mask, severity, ordinal, classLoader); |
| | | message = new Message(this); |
| | | requiresFormat = containsArgumentLiterals(getFormatString()); |
| | | } |
| | | |
| | | /** |
| | |
| | | return message; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return requiresFormat; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3, a4); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3, a4, a5); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3, a4, a5, a6); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3, a4, a5, a6, a7); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3, a4, a5, a6, a7, a8); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3, a4, a5, a6, a7, a8, a9); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return new Message(this, args); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | private String formatString; |
| | | |
| | | private boolean requiresFormatter; |
| | | |
| | | /** |
| | | * Creates a parameterized instance. |
| | | * @param formatString for created messages |
| | |
| | | Severity severity) { |
| | | super(null, null, category, severity, null, null); |
| | | this.formatString = formatString != null ? formatString.toString() : ""; |
| | | this.requiresFormatter = formatString.toString().matches(".*%.*"); |
| | | } |
| | | |
| | | /** |
| | |
| | | return this.formatString; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | boolean requiresFormatter() { |
| | | return this.requiresFormatter; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** String for accessing backing resource bundle. */ |
| | |
| | | */ |
| | | protected ClassLoader classLoader; |
| | | |
| | | |
| | | private Map<Locale,String> formatStrMap = new HashMap<Locale,String>(); |
| | | |
| | | /** |
| | | * Obtains the category of this descriptor. Gauranteed not to be null. |
| | | * @return Category of this message |
| | |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether or not this descriptor format string should |
| | | * be processed by Formatter during string rendering. |
| | | * @return boolean where true means Formatter should be used; false otherwise |
| | | * @see java.util.Formatter |
| | | */ |
| | | abstract boolean requiresFormatter(); |
| | | |
| | | /** |
| | | * Obtains the format string for constructing the string |
| | | * value of this message according to the default |
| | | * locale. |
| | |
| | | * @return format string |
| | | */ |
| | | String getFormatString(Locale locale) { |
| | | ResourceBundle bundle = getBundle(locale); |
| | | return bundle.getString(this.key); |
| | | String fmtStr = formatStrMap.get(locale); |
| | | if (fmtStr == null) { |
| | | ResourceBundle bundle = getBundle(locale); |
| | | fmtStr = bundle.getString(this.key); |
| | | formatStrMap.put(locale, fmtStr); |
| | | } |
| | | return fmtStr; |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether or not formatting should be applied |
| | | * to the given format string. Note that a format string |
| | | * might have literal specifiers (%% or %n for example) that |
| | | * require formatting but are not replaced by arguments. |
| | | * @param s candiate for formatting |
| | | * @return boolean where true indicates that the format |
| | | * string requires formatting |
| | | */ |
| | | protected boolean containsArgumentLiterals(String s) { |
| | | return s.matches(".*%[n|%].*"); // match Formatter literals |
| | | } |
| | | |
| | | private ResourceBundle getBundle(Locale locale) { |
| | |
| | | this.mask = mask; |
| | | } |
| | | |
| | | |
| | | } |