001package apps.jmrit;
002
003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
004
005import java.util.Locale;
006
007import javax.annotation.CheckReturnValue;
008import javax.annotation.CheckForNull;
009import javax.annotation.ParametersAreNonnullByDefault;
010
011@ParametersAreNonnullByDefault
012@CheckReturnValue
013@SuppressFBWarnings(value = {"NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", "HSM_HIDING_METHOD"},
014    justification = "Desired pattern is repeated class names with package-level access to members")
015@javax.annotation.concurrent.Immutable
016
017/**
018 * Provides standard access for resource bundles in a package.
019 *
020 * Convention is to provide a subclass of this name in each package, working off
021 * the local resource bundle name.
022 *
023 * @author Bob Jacobsen Copyright (C) 2012
024 * @since 3.3.1
025 */
026// NOTE: Does not extend apps.Bundle, but extends jmri.jmrit.Bundle, since
027// apps.jmrit is the extension of jmri.jmrit for classes that cannot be under
028// jmri.jmrit due to other architectural rules violations
029public class Bundle extends jmri.jmrit.Bundle {
030
031    @CheckForNull
032    private static final String name = null; // no local bundle
033
034    //
035    // below here is boilerplate to be copied exactly
036    //
037    /**
038     * Provides a translated string for a given key from the package resource
039     * bundle or parent.
040     * <p>
041     * Note that this is intentionally package-local access.
042     *
043     * @param key Bundle key to be translated
044     * @return Internationalized text
045     */
046    static String getMessage(String key) {
047        return getBundle().handleGetMessage(key);
048    }
049
050    /**
051     * Merges user data with a translated string for a given key from the
052     * package resource bundle or parent.
053     * <p>
054     * Uses the transformation conventions of the Java MessageFormat utility.
055     * <p>
056     * Note that this is intentionally package-local access.
057     *
058     * @see java.text.MessageFormat
059     * @param key  Bundle key to be translated
060     * @param subs One or more objects to be inserted into the message
061     * @return Internationalized text
062     */
063    static String getMessage(String key, Object... subs) {
064        return getBundle().handleGetMessage(key, subs);
065    }
066
067    /**
068     * Merges user data with a translated string for a given key in a given
069     * locale from the package resource bundle or parent.
070     * <p>
071     * Uses the transformation conventions of the Java MessageFormat utility.
072     * <p>
073     * Note that this is intentionally package-local access.
074     *
075     * @see java.text.MessageFormat
076     * @param locale The locale to be used
077     * @param key    Bundle key to be translated
078     * @param subs   One or more objects to be inserted into the message
079     * @return Internationalized text
080     */
081    static String getMessage(Locale locale, String key, Object... subs) {
082        return getBundle().handleGetMessage(locale, key, subs);
083    }
084
085    private final static Bundle b = new Bundle();
086
087    @Override
088    @CheckForNull
089    protected String bundleName() {
090        return name;
091    }
092
093    protected static jmri.Bundle getBundle() {
094        return b;
095    }
096
097    @Override
098    protected String retry(Locale locale, String key) {
099        return super.getBundle().handleGetMessage(locale,key);
100    }
101
102}
103