src/share/classes/sun/util/resources/LocaleData.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -40,13 +40,15 @@
 
 package sun.util.resources;
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 import sun.util.locale.provider.LocaleDataMetaInfo;
 import sun.util.locale.provider.LocaleProviderAdapter;
 import static sun.util.locale.provider.LocaleProviderAdapter.Type.JRE;
 

@@ -120,10 +122,36 @@
      */
     public ResourceBundle getDateFormatData(Locale locale) {
         return getBundle(type.getTextResourcesPackage() + ".FormatData", locale);
     }
 
+    public void setSupplementary(ParallelListResourceBundle formatData) {
+        assert type == LocaleProviderAdapter.Type.JRE
+                && formatData.getClass().getSimpleName().contains("FormatData");
+        if (!formatData.areParallelContentsComplete()) {
+            String suppName = type.getTextResourcesPackage() + ".JavaTimeSupplementary";
+            setSupplementary(suppName, formatData);
+        }
+    }
+
+    private boolean setSupplementary(String suppName, ParallelListResourceBundle formatData) {
+        ParallelListResourceBundle parent = (ParallelListResourceBundle) formatData.getParent();
+        boolean resetKeySet = false;
+        if (parent != null) {
+            resetKeySet = setSupplementary(suppName, parent);
+        }
+        OpenListResourceBundle supp = getSupplementary(suppName, formatData.getLocale());
+        formatData.setParallelContents(supp);
+        resetKeySet |= supp != null;
+        // If any parents or this bundle has parallel data, reset keyset to creat
+        // a new keyset with the data.
+        if (resetKeySet) {
+            formatData.resetKeySet();
+        }
+        return resetKeySet;
+    }
+
     /**
      * Gets a number format data resource bundle, using privileges
      * to allow accessing a sun.* package.
      */
     public ResourceBundle getNumberFormatData(Locale locale) {

@@ -132,24 +160,39 @@
 
     public static ResourceBundle getBundle(final String baseName, final Locale locale) {
         return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
                 @Override
                 public ResourceBundle run() {
-                    return ResourceBundle.
-                        getBundle(baseName, locale,
-                                  LocaleDataResourceBundleControl.getRBControlInstance());
+                return ResourceBundle
+                        .getBundle(baseName, locale, LocaleDataResourceBundleControl.INSTANCE);
+            }
+        });
+    }
+
+    private static OpenListResourceBundle getSupplementary(final String baseName, final Locale locale) {
+        return AccessController.doPrivileged(new PrivilegedAction<OpenListResourceBundle>() {
+           @Override
+           public OpenListResourceBundle run() {
+               OpenListResourceBundle rb = null;
+               try {
+                   rb = (OpenListResourceBundle) ResourceBundle.getBundle(baseName,
+                           locale, SupplementaryResourceBundleControl.INSTANCE);
+
+               } catch (MissingResourceException e) {
+                   // return null if no supplementary is available
+               }
+               return rb;
                 }
             });
     }
 
     private static class LocaleDataResourceBundleControl extends ResourceBundle.Control {
         /* Singlton instance of ResourceBundle.Control. */
-        private static LocaleDataResourceBundleControl rbControlInstance =
+        private static final LocaleDataResourceBundleControl INSTANCE =
             new LocaleDataResourceBundleControl();
 
-        public static LocaleDataResourceBundleControl getRBControlInstance() {
-            return rbControlInstance;
+        private LocaleDataResourceBundleControl() {
         }
 
         /*
          * This method overrides the default implementation to search
          * from a prebaked locale string list to determin the candidate

@@ -241,8 +284,27 @@
                                       + baseName.substring(index);
                 }
             }
             return super.toBundleName(newBaseName, locale);
         }
+    }
+
+    private static class SupplementaryResourceBundleControl extends LocaleDataResourceBundleControl {
+        private static final SupplementaryResourceBundleControl INSTANCE =
+                new SupplementaryResourceBundleControl();
+
+        private SupplementaryResourceBundleControl() {
+        }
 
+        @Override
+        public List<Locale> getCandidateLocales(String baseName, Locale locale) {
+            // Specifiy only the given locale
+            return Arrays.asList(locale);
+        }
+
+        @Override
+        public long getTimeToLive(String baseName, Locale locale) {
+            assert baseName.contains("JavaTimeSupplementary");
+            return TTL_DONT_CACHE;
+        }
     }
 }