/*
  * This method find the appropriate Manifest Localization file inside the
  * bundle. If not found, return null.
  */
 ResourceBundle getResourceBundle(String localeString, boolean isDefaultLocale) {
   BundleResourceBundle resourceBundle = lookupResourceBundle(localeString);
   if (isDefaultLocale) return (ResourceBundle) resourceBundle;
   // need to determine if this is resource bundle is an empty stem
   // if it is then the default locale should be used
   if (resourceBundle == null || resourceBundle.isStemEmpty())
     return (ResourceBundle) lookupResourceBundle(Locale.getDefault().toString());
   return (ResourceBundle) resourceBundle;
 }
  private BundleResourceBundle lookupResourceBundle(String localeString) {
    // get the localization header as late as possible to avoid accessing the raw headers
    // getting the first value from the raw headers forces the manifest to be parsed (bug 332039)
    String localizationHeader = rawHeaders.get(Constants.BUNDLE_LOCALIZATION);
    if (localizationHeader == null)
      localizationHeader = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;

    BundleResourceBundle result = cache.get(localeString);
    if (result != null) return result.isEmpty() ? null : result;

    // Collect all the necessary inputstreams to create the resource bundle without
    // holding any locks.  Finding resources and inputstreams from the wirings requires a
    // read lock on the module database.  We must not hold the cache lock while doing this;
    // otherwise out of order locks will be possible when the resolver needs to clear the cache
    String[] nlVarients = buildNLVariants(localeString);
    InputStream[] nlStreams = new InputStream[nlVarients.length];
    for (int i = nlVarients.length - 1; i >= 0; i--) {

      URL url =
          findResource(
              localizationHeader
                  + (nlVarients[i].equals("") ? nlVarients[i] : '_' + nlVarients[i])
                  + ".properties"); //$NON-NLS-1$ //$NON-NLS-2$
      if (url != null) {
        try {
          nlStreams[i] = url.openStream();
        } catch (IOException e) {
          // ignore
        }
      }
    }

    synchronized (cache) {
      BundleResourceBundle parent = null;
      for (int i = nlVarients.length - 1; i >= 0; i--) {
        BundleResourceBundle varientBundle = null;
        InputStream varientStream = nlStreams[i];
        if (varientStream == null) {
          varientBundle = cache.get(nlVarients[i]);
        } else {
          try {
            varientBundle = new LocalizationResourceBundle(varientStream);
          } catch (IOException e) {
            // ignore and continue
          } finally {
            if (varientStream != null) {
              try {
                varientStream.close();
              } catch (IOException e3) {
                // Ignore exception
              }
            }
          }
        }

        if (varientBundle == null) {
          varientBundle = new EmptyResouceBundle(nlVarients[i]);
        }
        if (parent != null) varientBundle.setParent((ResourceBundle) parent);
        cache.put(nlVarients[i], varientBundle);
        parent = varientBundle;
      }
      result = cache.get(localeString);
      return result.isEmpty() ? null : result;
    }
  }