--- old/src/share/classes/java/text/DateFormatSymbols.java Fri Jul 20 11:43:19 2012 +++ new/src/share/classes/java/text/DateFormatSymbols.java Fri Jul 20 11:43:18 2012 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,16 +44,14 @@ import java.lang.ref.SoftReference; import java.text.spi.DateFormatSymbolsProvider; import java.util.Arrays; -import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.TimeZone; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.spi.LocaleServiceProvider; -import sun.util.LocaleServiceProviderPool; -import sun.util.TimeZoneNameUtility; -import sun.util.calendar.ZoneInfo; +import sun.util.locale.provider.LocaleProviderAdapter; +import sun.util.locale.provider.LocaleServiceProviderPool; +import sun.util.locale.provider.TimeZoneNameUtility; import sun.util.resources.LocaleData; /** @@ -227,7 +225,7 @@ * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. * All locales use the same these unlocalized pattern characters. */ - static final String patternChars = "GyMdkHmsSEDFwWahKzZYuX"; + static final String patternChars = "GyMdkHmsSEDFwWahKzZYuXL"; static final int PATTERN_ERA = 0; // G static final int PATTERN_YEAR = 1; // y @@ -251,6 +249,7 @@ static final int PATTERN_WEEK_YEAR = 19; // Y static final int PATTERN_ISO_DAY_OF_WEEK = 20; // u static final int PATTERN_ISO_ZONE = 21; // X + static final int PATTERN_MONTH_STANDALONE = 22; // L /** * Localized date-time pattern characters. For example, a locale may @@ -326,7 +325,7 @@ if (dfs != null) { return dfs; } - return (DateFormatSymbols) getCachedInstance(locale).clone(); + throw new RuntimeException("DateFormatSymbols instance creation failed."); } /** @@ -340,49 +339,16 @@ if (dfs != null) { return dfs; } - return getCachedInstance(locale); + throw new RuntimeException("DateFormatSymbols instance creation failed."); } private static DateFormatSymbols getProviderInstance(Locale locale) { - DateFormatSymbols providersInstance = null; - - // 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(DateFormatSymbolsProvider.class); - if (pool.hasProviders()) { - providersInstance = pool.getLocalizedObject( - DateFormatSymbolsGetter.INSTANCE, locale); - } - return providersInstance; + LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); + DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider(); + return provider.getInstance(locale); } /** - * Returns a cached DateFormatSymbols if it's found in the - * cache. Otherwise, this method returns a newly cached instance - * for the given locale. - */ - private static DateFormatSymbols getCachedInstance(Locale locale) { - SoftReference ref = cachedInstances.get(locale); - DateFormatSymbols dfs = null; - if (ref == null || (dfs = ref.get()) == null) { - dfs = new DateFormatSymbols(locale); - ref = new SoftReference(dfs); - SoftReference x = cachedInstances.putIfAbsent(locale, ref); - if (x != null) { - DateFormatSymbols y = x.get(); - if (y != null) { - dfs = y; - } else { - // Replace the empty SoftReference with ref. - cachedInstances.put(locale, ref); - } - } - } - return dfs; - } - - /** * Gets era strings. For example: "AD" and "BC". * @return the era strings. */ @@ -400,6 +366,17 @@ /** * Gets month strings. For example: "January", "February", etc. + * + *

If the language requires different forms for formatting and + * stand-alone usages, this method returns month names in the + * formatting form. For example, the preferred month name for + * January in the Czech language is ledna in the + * formatting form, while it is leden in the stand-alone + * form. This method returns {@code "ledna"} in this case. Refer + * to the + * Calendar Elements in the Unicode Locale Data Markup Language + * (LDML) specification for more details. + * * @return the month strings. */ public String[] getMonths() { @@ -416,6 +393,17 @@ /** * Gets short month strings. For example: "Jan", "Feb", etc. + * + *

If the language requires different forms for formatting and + * stand-alone usages, This method returns short month names in + * the formatting form. For example, the preferred abbreviation + * for January in the Catalan language is de gen. in the + * formatting form, while it is gen. in the stand-alone + * form. This method returns {@code "de gen."} in this case. Refer + * to the + * Calendar Elements in the Unicode Locale Data Markup Language + * (LDML) specification for more details. + * * @return the short month strings. */ public String[] getShortMonths() { @@ -645,7 +633,7 @@ * Cache to hold DateFormatSymbols instances per Locale. */ private static final ConcurrentMap> cachedInstances - = new ConcurrentHashMap>(3); + = new ConcurrentHashMap<>(3); private transient int lastZoneIndex = 0; @@ -661,7 +649,15 @@ } // Initialize the fields from the ResourceBundle for locale. - ResourceBundle resource = LocaleData.getDateFormatData(locale); + LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); + // Avaoid any potential recursions + switch (adapter.getAdapterType()) { + case HOST: + case SPI: + adapter = LocaleProviderAdapter.getResourceBundleBased(); + break; + } + ResourceBundle resource = adapter.getLocaleData().getDateFormatData(locale); eras = resource.getStringArray("Eras"); months = resource.getStringArray("MonthNames"); @@ -672,6 +668,17 @@ // Day of week names are stored in a 1-based array. weekdays = toOneBasedArray(resource.getStringArray("DayNames")); shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); + + // Put a clone in the cache + ref = new SoftReference<>((DateFormatSymbols)this.clone()); + SoftReference x = cachedInstances.putIfAbsent(locale, ref); + if (x != null) { + DateFormatSymbols y = x.get(); + if (y == null) { + // Replace the empty SoftReference with ref. + cachedInstances.put(locale, ref); + } + } } private static String[] toOneBasedArray(String[] src) { @@ -730,7 +737,7 @@ } } - private final String[][] getZoneStringsImpl(boolean needsCopy) { + private String[][] getZoneStringsImpl(boolean needsCopy) { if (zoneStrings == null) { zoneStrings = TimeZoneNameUtility.getZoneStrings(locale); } @@ -747,7 +754,7 @@ return aCopy; } - private final boolean isSubclassObject() { + private boolean isSubclassObject() { return !getClass().getName().equals("java.text.DateFormatSymbols"); } @@ -757,7 +764,7 @@ * @param src the source DateFormatSymbols. * @param dst the target DateFormatSymbols. */ - private final void copyMembers(DateFormatSymbols src, DateFormatSymbols dst) + private void copyMembers(DateFormatSymbols src, DateFormatSymbols dst) { dst.eras = Arrays.copyOf(src.eras, src.eras.length); dst.months = Arrays.copyOf(src.months, src.months.length); @@ -786,23 +793,4 @@ } stream.defaultWriteObject(); } - - /** - * Obtains a DateFormatSymbols instance from a DateFormatSymbolsProvider - * implementation. - */ - private static class DateFormatSymbolsGetter - implements LocaleServiceProviderPool.LocalizedObjectGetter { - private static final DateFormatSymbolsGetter INSTANCE = - new DateFormatSymbolsGetter(); - - public DateFormatSymbols getObject(DateFormatSymbolsProvider dateFormatSymbolsProvider, - Locale locale, - String key, - Object... params) { - assert params.length == 0; - return dateFormatSymbolsProvider.getInstance(locale); - } - } }