001package jmri.jmris.simpleserver;
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
013@javax.annotation.concurrent.Immutable
014
015/**
016 * Provides standard access for resource bundles in a package.
017 *
018 * Convention is to provide a subclass of this name in each package, working off
019 * the local resource bundle name.
020 *
021 * @author Bob Jacobsen Copyright (C) 2012
022 * @since 3.3.1
023 */
024public class Bundle extends jmri.jmris.Bundle {
025
026    @CheckForNull
027    private static final String name = "jmri.jmris.simpleserver.SimpleServerBundle"; // NOI18N
028
029    //
030    // below here is boilerplate to be copied exactly
031    //
032    /**
033     * Provides a translated string for a given key from the package resource
034     * bundle or parent.
035     * <p>
036     * Note that this is intentionally package-local access.
037     *
038     * @param key Bundle key to be translated
039     * @return Internationalized text
040     */
041    static String getMessage(String key) {
042        return getBundle().handleGetMessage(key);
043    }
044
045    /**
046     * Provides a translated string for a given key in a given locale from the
047     * package resource bundle or parent.
048     * <p>
049     * Note that this is intentionally package-local access.
050     *
051     * @param locale The locale to be used
052     * @param key    Bundle key to be translated
053     * @return Internationalized text
054     */
055    static String getMessage(Locale locale, String key) {
056        return getBundle().handleGetMessage(locale, key);
057    }
058
059    /**
060     * Merges user data with a translated string for a given key from the
061     * package resource bundle or parent.
062     * <p>
063     * Uses the transformation conventions of the Java MessageFormat utility.
064     * <p>
065     * Note that this is intentionally package-local access.
066     *
067     * @see java.text.MessageFormat
068     * @param key  Bundle key to be translated
069     * @param subs One or more objects to be inserted into the message
070     * @return Internationalized text
071     */
072    static String getMessage(String key, Object... subs) {
073        return getBundle().handleGetMessage(key, subs);
074    }
075
076    /**
077     * Merges user data with a translated string for a given key in a given
078     * locale from the package resource bundle or parent.
079     * <p>
080     * Uses the transformation conventions of the Java MessageFormat utility.
081     * <p>
082     * Note that this is intentionally package-local access.
083     *
084     * @see java.text.MessageFormat
085     * @param locale The locale to be used
086     * @param key    Bundle key to be translated
087     * @param subs   One or more objects to be inserted into the message
088     * @return Internationalized text
089     */
090    static String getMessage(Locale locale, String key, Object... subs) {
091        return getBundle().handleGetMessage(locale, key, subs);
092    }
093
094    private final static Bundle b = new Bundle();
095
096    @Override
097    @CheckForNull
098    protected String bundleName() {
099        return name;
100    }
101
102    protected static jmri.Bundle getBundle() {
103        return b;
104    }
105
106    @Override
107    protected String retry(Locale locale, String key) {
108        return super.getBundle().handleGetMessage(locale, key);
109    }
110
111}