/**
   * Gets the Collator for the desired locale.
   *
   * @param desiredLocale the desired locale.
   * @return the Collator for the desired locale.
   * @see java.util.Locale
   * @see java.util.ResourceBundle
   */
  public static synchronized Collator getInstance(Locale desiredLocale) {
    Collator result = (Collator) cache.get(desiredLocale);
    if (result != null) {
      return (Collator) result.clone(); // make the world safe
    }

    // Check whether a provider can provide an implementation that's closer
    // to the requested locale than what the Java runtime itself can provide.
    LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(CollatorProvider.class);
    if (pool.hasProviders()) {
      Collator providersInstance =
          pool.getLocalizedObject(CollatorGetter.INSTANCE, desiredLocale, desiredLocale);
      if (providersInstance != null) {
        return providersInstance;
      }
    }

    // Load the resource of the desired locale from resource
    // manager.
    String colString = "";
    try {
      ResourceBundle resource = LocaleData.getCollationData(desiredLocale);

      colString = resource.getString("Rule");
    } catch (MissingResourceException e) {
      // Use default values
    }
    try {
      result =
          new RuleBasedCollator(CollationRules.DEFAULTRULES + colString, CANONICAL_DECOMPOSITION);
    } catch (ParseException foo) {
      // predefined tables should contain correct grammar
      try {
        result = new RuleBasedCollator(CollationRules.DEFAULTRULES);
      } catch (ParseException bar) {
        // do nothing
      }
    }
    // Now that RuleBasedCollator adds expansions for pre-composed characters
    // into their decomposed equivalents, the default collators don't need
    // to have decomposition turned on.  Laura, 5/5/98, bug 4114077
    result.setDecomposition(NO_DECOMPOSITION);

    cache.put(desiredLocale, result);
    return (Collator) result.clone();
  }
 /**
  * Returns an array of all locales for which the <code>getInstance</code> methods of this class
  * can return localized instances. The returned array represents the union of locales supported by
  * the Java runtime and by installed {@link java.text.spi.CollatorProvider CollatorProvider}
  * implementations. It must contain at least a Locale instance equal to {@link java.util.Locale#US
  * Locale.US}.
  *
  * @return An array of locales for which localized <code>Collator</code> instances are available.
  */
 public static synchronized Locale[] getAvailableLocales() {
   LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(CollatorProvider.class);
   return pool.getAvailableLocales();
 }