src/share/classes/sun/util/locale/provider/CollatorProviderImpl.java

Print this page
rev 6352 : imported patch 7162007


  28  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  29  * (C) Copyright IBM Corp. 1996 - 2002 - All Rights Reserved
  30  *
  31  * The original version of this source code and documentation
  32  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  33  * subsidiary of IBM. These materials are provided under terms
  34  * of a License Agreement between Taligent and Sun. This technology
  35  * is protected by multiple US and International patents.
  36  *
  37  * This notice and attribution to Taligent may not be removed.
  38  * Taligent is a registered trademark of Taligent, Inc.
  39  */
  40 
  41 package sun.util.locale.provider;
  42 
  43 import java.text.Collator;
  44 import java.text.ParseException;
  45 import java.text.RuleBasedCollator;
  46 import java.text.spi.CollatorProvider;
  47 import java.util.Locale;
  48 import java.util.MissingResourceException;
  49 import java.util.ResourceBundle;
  50 import java.util.Set;
  51 
  52 /**
  53  * Concrete implementation of the
  54  * {@link java.text.spi.CollatorProvider CollatorProvider} class
  55  * for the JRE LocaleProviderAdapter.
  56  */
  57 public class CollatorProviderImpl extends CollatorProvider implements AvailableLanguageTags {
  58     private final LocaleProviderAdapter.Type type;
  59     private final Set<String> langtags;
  60 
  61     public CollatorProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
  62         this.type = type;
  63         this.langtags = langtags;
  64     }
  65 
  66     /**
  67      * Returns an array of all locales for which this locale service provider
  68      * can provide localized objects or names.
  69      *


  85      * @param locale the desired locale.
  86      * @return the <code>Collator</code> for the desired locale.
  87      * @exception NullPointerException if
  88      * <code>locale</code> is null
  89      * @exception IllegalArgumentException if <code>locale</code> isn't
  90      *     one of the locales returned from
  91      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
  92      *     getAvailableLocales()}.
  93      * @see java.text.Collator#getInstance(java.util.Locale)
  94      */
  95     @Override
  96     public Collator getInstance(Locale locale) {
  97         if (locale == null) {
  98             throw new NullPointerException();
  99         }
 100 
 101         Collator result = null;
 102 
 103         // Load the resource of the desired locale from resource
 104         // manager.
 105         String colString = "";
 106         try {
 107             ResourceBundle resource = LocaleProviderAdapter.forType(type).getLocaleData().getCollationData(locale);
 108 
 109             colString = resource.getString("Rule");
 110         } catch (MissingResourceException e) {
 111             // Use default values
 112         }
 113         try
 114         {
 115             result = new RuleBasedCollator(CollationRules.DEFAULTRULES +
 116                                            colString);
 117         }
 118         catch(ParseException foo)
 119         {
 120             // predefined tables should contain correct grammar
 121             try {
 122                 result = new RuleBasedCollator(CollationRules.DEFAULTRULES);
 123             } catch (ParseException bar) {
 124                 // the default rules should always be parsable.
 125                 throw new InternalError(bar);
 126             }
 127         }
 128         // Now that RuleBasedCollator adds expansions for pre-composed characters
 129         // into their decomposed equivalents, the default collators don't need
 130         // to have decomposition turned on.  Laura, 5/5/98, bug 4114077
 131         result.setDecomposition(Collator.NO_DECOMPOSITION);
 132 


  28  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  29  * (C) Copyright IBM Corp. 1996 - 2002 - All Rights Reserved
  30  *
  31  * The original version of this source code and documentation
  32  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  33  * subsidiary of IBM. These materials are provided under terms
  34  * of a License Agreement between Taligent and Sun. This technology
  35  * is protected by multiple US and International patents.
  36  *
  37  * This notice and attribution to Taligent may not be removed.
  38  * Taligent is a registered trademark of Taligent, Inc.
  39  */
  40 
  41 package sun.util.locale.provider;
  42 
  43 import java.text.Collator;
  44 import java.text.ParseException;
  45 import java.text.RuleBasedCollator;
  46 import java.text.spi.CollatorProvider;
  47 import java.util.Locale;


  48 import java.util.Set;
  49 
  50 /**
  51  * Concrete implementation of the
  52  * {@link java.text.spi.CollatorProvider CollatorProvider} class
  53  * for the JRE LocaleProviderAdapter.
  54  */
  55 public class CollatorProviderImpl extends CollatorProvider implements AvailableLanguageTags {
  56     private final LocaleProviderAdapter.Type type;
  57     private final Set<String> langtags;
  58 
  59     public CollatorProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
  60         this.type = type;
  61         this.langtags = langtags;
  62     }
  63 
  64     /**
  65      * Returns an array of all locales for which this locale service provider
  66      * can provide localized objects or names.
  67      *


  83      * @param locale the desired locale.
  84      * @return the <code>Collator</code> for the desired locale.
  85      * @exception NullPointerException if
  86      * <code>locale</code> is null
  87      * @exception IllegalArgumentException if <code>locale</code> isn't
  88      *     one of the locales returned from
  89      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
  90      *     getAvailableLocales()}.
  91      * @see java.text.Collator#getInstance(java.util.Locale)
  92      */
  93     @Override
  94     public Collator getInstance(Locale locale) {
  95         if (locale == null) {
  96             throw new NullPointerException();
  97         }
  98 
  99         Collator result = null;
 100 
 101         // Load the resource of the desired locale from resource
 102         // manager.
 103         String colString = LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCollationData();







 104         try
 105         {
 106             result = new RuleBasedCollator(CollationRules.DEFAULTRULES +
 107                                            colString);
 108         }
 109         catch(ParseException foo)
 110         {
 111             // predefined tables should contain correct grammar
 112             try {
 113                 result = new RuleBasedCollator(CollationRules.DEFAULTRULES);
 114             } catch (ParseException bar) {
 115                 // the default rules should always be parsable.
 116                 throw new InternalError(bar);
 117             }
 118         }
 119         // Now that RuleBasedCollator adds expansions for pre-composed characters
 120         // into their decomposed equivalents, the default collators don't need
 121         // to have decomposition turned on.  Laura, 5/5/98, bug 4114077
 122         result.setDecomposition(Collator.NO_DECOMPOSITION);
 123