Пример #1
0
  // This method is synchronized so that the cache is properly
  // handled.
  public static synchronized ResourceBundle getBundle(
      String baseName, Locale locale, ClassLoader classLoader) {
    Locale defaultLocale = Locale.getDefault();
    // This will throw NullPointerException if any arguments are null.
    lookupKey.set(defaultLocale, baseName, locale, classLoader);
    Object obj = bundleCache.get(lookupKey);
    if (obj instanceof ResourceBundle) return (ResourceBundle) obj;

    if (obj == nullEntry)
      throw new MissingResourceException(
          "Bundle "
              + baseName
              + " not found for locale "
              + locale
              + " by classloader "
              + classLoader,
          baseName,
          "");
    // First, look for a bundle for the specified locale. We don't want
    // the base bundle this time.
    boolean wantBase = locale.equals(defaultLocale);
    ResourceBundle bundle = tryBundle(baseName, locale, classLoader, wantBase);
    // Try the default locale if neccessary.
    if (bundle == null && !wantBase) bundle = tryBundle(baseName, defaultLocale, classLoader, true);

    BundleKey key = new BundleKey(defaultLocale, baseName, locale, classLoader);
    if (bundle == null) {
      // Cache the fact that this lookup has previously failed.
      bundleCache.put(key, nullEntry);
      throw new MissingResourceException(
          "Bundle "
              + baseName
              + " not found for locale "
              + locale
              + " by classloader "
              + classLoader,
          baseName,
          "");
    }
    // Cache the result and return it.
    bundleCache.put(key, bundle);
    return bundle;
  }