0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#warn This file is preprocessed before being compiled
0N/A
0N/Apackage sun.util;
0N/A
0N/Aimport java.util.Arrays;
0N/Aimport java.util.Collection;
0N/Aimport java.util.Collections;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.List;
0N/Aimport java.util.Locale;
0N/Aimport java.util.ResourceBundle;
0N/Aimport java.util.ResourceBundle.Control;
0N/A
0N/A/**
0N/A * This is a convenient class for loading some of internal resources faster
0N/A * if they are built with Resources.gmk defined in J2SE workspace. Also,
0N/A * they have to be in class file format.
0N/A *
0N/A * "LOCALE_LIST" will be replaced at built time by a list of locales we
0N/A * defined in Defs.gmk. We want to exclude these locales from search to
0N/A * gain better performance. For example, since we know if the resource
0N/A * is built with Resources.gmk, they are not going to provide basename_en.class
0N/A * & basename_en_US.class resources, in that case, continuing searching them
0N/A * is expensive. By excluding them from the candidate locale list, these
0N/A * resources won't be searched.
0N/A *
0N/A * @since 1.6.
0N/A */
0N/Apublic class CoreResourceBundleControl extends ResourceBundle.Control {
0N/A /* the candidate locale list to search */
0N/A private final Collection<Locale> excludedJDKLocales;
0N/A /* singlton instance of the resource bundle control. */
0N/A private static CoreResourceBundleControl resourceBundleControlInstance =
0N/A new CoreResourceBundleControl();
0N/A
0N/A protected CoreResourceBundleControl() {
0N/A excludedJDKLocales = Arrays.asList(#LOCALE_LIST#);
0N/A }
0N/A
0N/A /**
0N/A * This method is to provide a customized ResourceBundle.Control to speed
0N/A * up the search of resources in JDK.
0N/A *
0N/A * @return the instance of resource bundle control.
0N/A */
0N/A public static CoreResourceBundleControl getRBControlInstance() {
0N/A return resourceBundleControlInstance;
0N/A }
0N/A
0N/A /**
0N/A * This method is to provide a customized ResourceBundle.Control to speed
0N/A * up the search of resources in JDK, with the bundle's package name check.
0N/A *
0N/A * @param bundleName bundle name to check
0N/A * @return the instance of resource bundle control if the bundle is JDK's,
0N/A * otherwise returns null.
0N/A */
0N/A public static CoreResourceBundleControl getRBControlInstance(String bundleName) {
0N/A if (bundleName.startsWith("com.sun.") ||
0N/A bundleName.startsWith("java.") ||
0N/A bundleName.startsWith("javax.") ||
0N/A bundleName.startsWith("sun.")) {
0N/A return resourceBundleControlInstance;
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @returns a list of candidate locales to search from.
0N/A * @exception NullPointerException if baseName or locale is null.
0N/A */
0N/A @Override
0N/A public List<Locale> getCandidateLocales(String baseName, Locale locale) {
0N/A List<Locale> candidates = super.getCandidateLocales(baseName, locale);
0N/A candidates.removeAll(excludedJDKLocales);
0N/A return candidates;
0N/A }
0N/A
0N/A /**
0N/A * @ returns TTL_DONT_CACHE so that ResourceBundle instance won't be cached.
0N/A * User of this CoreResourceBundleControl should probably maintain a hard reference
0N/A * to the ResourceBundle object themselves.
0N/A */
0N/A @Override
0N/A public long getTimeToLive(String baseName, Locale locale) {
0N/A return ResourceBundle.Control.TTL_DONT_CACHE;
0N/A }
0N/A}