src/share/classes/java/text/DateFormat.java
Print this page
rev 5615 : 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 Jigsaw. by Naoto Sato and Masayoshi Okutsu)
*** 48,58 ****
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;
/**
* {@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
--- 48,59 ----
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.TimeZone;
import java.util.spi.LocaleServiceProvider;
! 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,780 ****
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;
}
}
!
! return new SimpleDateFormat(timeStyle, dateStyle, loc);
! } catch (MissingResourceException e) {
! return new SimpleDateFormat("M/d/yy h:mm a");
}
}
/**
* Create a new date format.
*/
--- 751,777 ----
throw new IllegalArgumentException("Illegal date style " + dateStyle);
}
} else {
dateStyle = -1;
}
!
! LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, 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);
}
}
! if (dateFormat == null) {
! throw new RuntimeException("DateFormat instance creation failed.");
}
+ return dateFormat;
}
/**
* Create a new date format.
*/
*** 869,878 ****
--- 866,876 ----
*
* @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,1030 ****
/**
* 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;
- }
- }
}
--- 990,995 ----