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