Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)

Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/text/DateFormat.java
          +++ new/src/share/classes/java/text/DateFormat.java
↓ open down ↓ 42 lines elided ↑ open up ↑
  43   43  import java.util.Calendar;
  44   44  import java.util.Date;
  45   45  import java.util.GregorianCalendar;
  46   46  import java.util.HashMap;
  47   47  import java.util.Locale;
  48   48  import java.util.Map;
  49   49  import java.util.MissingResourceException;
  50   50  import java.util.ResourceBundle;
  51   51  import java.util.TimeZone;
  52   52  import java.util.spi.LocaleServiceProvider;
  53      -import sun.util.LocaleServiceProviderPool;
       53 +import sun.util.locale.provider.LocaleProviderAdapter;
       54 +import sun.util.locale.provider.LocaleServiceProviderPool;
  54   55  
  55   56  /**
  56   57   * {@code DateFormat} is an abstract class for date/time formatting subclasses which
  57   58   * formats and parses dates or time in a language-independent manner.
  58   59   * The date/time formatting subclass, such as {@link SimpleDateFormat}, allows for
  59   60   * formatting (i.e., date -> text), parsing (text -> date), and
  60   61   * normalization.  The date is represented as a <code>Date</code> object or
  61   62   * as the milliseconds since January 1, 1970, 00:00:00 GMT.
  62   63   *
  63   64   * <p>{@code DateFormat} provides many class methods for obtaining default date/time
↓ open down ↓ 681 lines elided ↑ open up ↑
 745  746          } else {
 746  747              timeStyle = -1;
 747  748          }
 748  749          if ((flags & 2) != 0) {
 749  750              if (dateStyle < 0 || dateStyle > 3) {
 750  751                  throw new IllegalArgumentException("Illegal date style " + dateStyle);
 751  752              }
 752  753          } else {
 753  754              dateStyle = -1;
 754  755          }
 755      -        try {
 756      -            // Check whether a provider can provide an implementation that's closer
 757      -            // to the requested locale than what the Java runtime itself can provide.
 758      -            LocaleServiceProviderPool pool =
 759      -                LocaleServiceProviderPool.getPool(DateFormatProvider.class);
 760      -            if (pool.hasProviders()) {
 761      -                DateFormat providersInstance = pool.getLocalizedObject(
 762      -                                                    DateFormatGetter.INSTANCE,
 763      -                                                    loc,
 764      -                                                    timeStyle,
 765      -                                                    dateStyle,
 766      -                                                    flags);
 767      -                if (providersInstance != null) {
 768      -                    return providersInstance;
 769      -                }
 770      -            }
 771  756  
 772      -            return new SimpleDateFormat(timeStyle, dateStyle, loc);
 773      -        } catch (MissingResourceException e) {
 774      -            return new SimpleDateFormat("M/d/yy h:mm a");
      757 +        LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc);
      758 +        DateFormat dateFormat = get(adapter, timeStyle, dateStyle, loc);
      759 +        if (dateFormat == null) {
      760 +            dateFormat = get(LocaleProviderAdapter.forJRE(), timeStyle, dateStyle, loc);
 775  761          }
      762 +        return dateFormat;
 776  763      }
 777  764  
      765 +    private static DateFormat get(LocaleProviderAdapter adapter, int timeStyle, int dateStyle, Locale loc) {
      766 +        DateFormatProvider provider = adapter.getDateFormatProvider();
      767 +        DateFormat dateFormat;
      768 +        if (timeStyle == -1) {
      769 +            dateFormat = provider.getDateInstance(dateStyle, loc);
      770 +        } else {
      771 +            if (dateStyle == -1) {
      772 +                dateFormat = provider.getTimeInstance(timeStyle, loc);
      773 +            } else {
      774 +                dateFormat = provider.getDateTimeInstance(dateStyle, timeStyle, loc);
      775 +            }
      776 +        }
      777 +        return dateFormat;
      778 +    }
      779 +
 778  780      /**
 779  781       * Create a new date format.
 780  782       */
 781  783      protected DateFormat() {}
 782  784  
 783  785      /**
 784  786       * Defines constants that are used as attribute keys in the
 785  787       * <code>AttributedCharacterIterator</code> returned
 786  788       * from <code>DateFormat.formatToCharacterIterator</code> and as
 787  789       * field identifiers in <code>FieldPosition</code>.
↓ open down ↓ 76 lines elided ↑ open up ↑
 864  866              return calendarField;
 865  867          }
 866  868  
 867  869          /**
 868  870           * Resolves instances being deserialized to the predefined constants.
 869  871           *
 870  872           * @throws InvalidObjectException if the constant could not be
 871  873           *         resolved.
 872  874           * @return resolved DateFormat.Field constant
 873  875           */
      876 +        @Override
 874  877          protected Object readResolve() throws InvalidObjectException {
 875  878              if (this.getClass() != DateFormat.Field.class) {
 876  879                  throw new InvalidObjectException("subclass didn't correctly implement readResolve");
 877  880              }
 878  881  
 879  882              Object instance = instanceMap.get(getName());
 880  883              if (instance != null) {
 881  884                  return instance;
 882  885              } else {
 883  886                  throw new InvalidObjectException("unknown attribute name");
↓ open down ↓ 103 lines elided ↑ open up ↑
 987  990           * 0 to 11.
 988  991           */
 989  992          public final static Field HOUR0 = new
 990  993                              Field("hour", Calendar.HOUR);
 991  994  
 992  995          /**
 993  996           * Constant identifying the time zone field.
 994  997           */
 995  998          public final static Field TIME_ZONE = new Field("time zone", -1);
 996  999      }
 997      -
 998      -    /**
 999      -     * Obtains a DateFormat instance from a DateFormatProvider
1000      -     * implementation.
1001      -     */
1002      -    private static class DateFormatGetter
1003      -        implements LocaleServiceProviderPool.LocalizedObjectGetter<DateFormatProvider, DateFormat> {
1004      -        private static final DateFormatGetter INSTANCE = new DateFormatGetter();
1005      -
1006      -        public DateFormat getObject(DateFormatProvider dateFormatProvider,
1007      -                                Locale locale,
1008      -                                String key,
1009      -                                Object... params) {
1010      -            assert params.length == 3;
1011      -
1012      -            int timeStyle = (Integer)params[0];
1013      -            int dateStyle = (Integer)params[1];
1014      -            int flags = (Integer)params[2];
1015      -
1016      -            switch (flags) {
1017      -            case 1:
1018      -                return dateFormatProvider.getTimeInstance(timeStyle, locale);
1019      -            case 2:
1020      -                return dateFormatProvider.getDateInstance(dateStyle, locale);
1021      -            case 3:
1022      -                return dateFormatProvider.getDateTimeInstance(dateStyle, timeStyle, locale);
1023      -            default:
1024      -                assert false : "should not happen";
1025      -            }
1026      -
1027      -            return null;
1028      -        }
1029      -    }
1030 1000  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX