src/share/classes/java/text/DateFormat.java
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)
@@ -48,11 +48,12 @@
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.TimeZone;
import java.util.spi.LocaleServiceProvider;
-import sun.util.LocaleServiceProviderPool;
+import sun.util.locale.provider.LocaleProviderAdapter;
+import sun.util.locale.provider.LocaleServiceProviderPool;
/**
* {@code DateFormat} is an abstract class for date/time formatting subclasses which
* formats and parses dates or time in a language-independent manner.
* The date/time formatting subclass, such as {@link SimpleDateFormat}, allows for
@@ -750,32 +751,33 @@
throw new IllegalArgumentException("Illegal date style " + dateStyle);
}
} else {
dateStyle = -1;
}
- try {
- // 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(DateFormatProvider.class);
- if (pool.hasProviders()) {
- DateFormat providersInstance = pool.getLocalizedObject(
- DateFormatGetter.INSTANCE,
- loc,
- timeStyle,
- dateStyle,
- flags);
- if (providersInstance != null) {
- return providersInstance;
+
+ LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc);
+ DateFormat dateFormat = get(adapter, timeStyle, dateStyle, loc);
+ if (dateFormat == null) {
+ dateFormat = get(LocaleProviderAdapter.forJRE(), timeStyle, dateStyle, loc);
}
+ return dateFormat;
}
- return new SimpleDateFormat(timeStyle, dateStyle, loc);
- } catch (MissingResourceException e) {
- return new SimpleDateFormat("M/d/yy h:mm a");
+ private static DateFormat get(LocaleProviderAdapter adapter, int timeStyle, int dateStyle, Locale loc) {
+ DateFormatProvider provider = adapter.getDateFormatProvider();
+ DateFormat dateFormat;
+ if (timeStyle == -1) {
+ dateFormat = provider.getDateInstance(dateStyle, loc);
+ } else {
+ if (dateStyle == -1) {
+ dateFormat = provider.getTimeInstance(timeStyle, loc);
+ } else {
+ dateFormat = provider.getDateTimeInstance(dateStyle, timeStyle, loc);
}
}
+ return dateFormat;
+ }
/**
* Create a new date format.
*/
protected DateFormat() {}
@@ -869,10 +871,11 @@
*
* @throws InvalidObjectException if the constant could not be
* resolved.
* @return resolved DateFormat.Field constant
*/
+ @Override
protected Object readResolve() throws InvalidObjectException {
if (this.getClass() != DateFormat.Field.class) {
throw new InvalidObjectException("subclass didn't correctly implement readResolve");
}
@@ -992,39 +995,6 @@
/**
* Constant identifying the time zone field.
*/
public final static Field TIME_ZONE = new Field("time zone", -1);
}
-
- /**
- * Obtains a DateFormat instance from a DateFormatProvider
- * implementation.
- */
- private static class DateFormatGetter
- implements LocaleServiceProviderPool.LocalizedObjectGetter<DateFormatProvider, DateFormat> {
- private static final DateFormatGetter INSTANCE = new DateFormatGetter();
-
- public DateFormat getObject(DateFormatProvider dateFormatProvider,
- Locale locale,
- String key,
- Object... params) {
- assert params.length == 3;
-
- int timeStyle = (Integer)params[0];
- int dateStyle = (Integer)params[1];
- int flags = (Integer)params[2];
-
- switch (flags) {
- case 1:
- return dateFormatProvider.getTimeInstance(timeStyle, locale);
- case 2:
- return dateFormatProvider.getDateInstance(dateStyle, locale);
- case 3:
- return dateFormatProvider.getDateTimeInstance(dateStyle, timeStyle, locale);
- default:
- assert false : "should not happen";
- }
-
- return null;
- }
- }
}