resourcebundle.java
来自「gcc3.2.1源代码」· Java 代码 · 共 475 行 · 第 1/2 页
JAVA
475 行
/* java.util.ResourceBundle Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.util;import java.lang.ref.Reference;import java.lang.ref.SoftReference;import java.security.AccessController;import java.security.PrivilegedAction;import gnu.classpath.Configuration;/** * A resource bundle contains locale-specific data. If you need * localized data, you can load a resource bundle that matches the * locale with <code>getBundle</code>. Now you can get your object by * calling <code>getObject</code> or <code>getString</code> on that * bundle. * <br> * When a bundle is demanded for a specific locale, the ResourceBundle * is searched in following order (<i>def. language code<i> stands for * the two letter ISO language code of the default locale (see * <code>Locale.getDefault()</code>). * <pre> * baseName_<i>language code</i>_<i>country code</i>_<i>variant</i> * baseName_<i>language code</i>_<i>country code</i> * baseName_<i>language code</i> * baseName_<i>def. language code</i>_<i>def. country code</i>_<i>def. variant</i> * baseName_<i>def. language code</i>_<i>def. country code</i> * baseName_<i>def. language code</i> * baseName * </pre> * * A bundle is backed up, by less specific bundle (omiting variant, * country or language). But it is not backed up by the default * language locale. * <br> * If you provide a bundle for a given locale, say * <code>Bundle_en_UK_POSIX</code>, you must also provide a bundle for * all sub locales, ie. <code>Bundle_en_UK</code>, <code>Bundle_en</code>, and * <code>Bundle</code>. * <br> * When a bundle is searched, we look first for a class with * the given name and if that is not found for a file with * <code>.properties</code> extension in the classpath. The name * must be a fully qualified classname (with dots as path separators). * <br> * (Note: This implementation always backs up the class with a * properties file if that is existing, but you shouldn't rely on * this, if you want to be compatible to the standard JDK.) * * @see Locale * @see PropertyResourceBundle * @author Jochen Hoenicke */public abstract class ResourceBundle{ /** * The parent bundle. This is consulted when you call getObject * and there is no such resource in the current bundle. This * field may be null. */ protected ResourceBundle parent; /** * The locale of this resource bundle. You can read this with * <code>getLocale</code> and it is automatically set in * <code>getBundle</code>. */ private Locale locale; /** * We override SecurityManager in order to access getClassContext(). */ static class Security extends SecurityManager { /** Return the ClassLoader of the class which called into this ResourceBundle, or null if it cannot be determined. */ ClassLoader getCallingClassLoader() { Class[] stack = super.getClassContext(); for (int i = 0; i < stack.length; i++) if (stack[i] != Security.class && stack[i] != ResourceBundle.class) return stack[i].getClassLoader(); return null; } } // This will always work since java.util classes have (all) system // permissions. static Security security = (Security) AccessController.doPrivileged ( new PrivilegedAction() { public Object run() { return new Security(); } } ); /** * The constructor. It does nothing special. */ public ResourceBundle() { } /** * Get a String from this resource bundle. Since most localized * Objects are Strings, this method provides a convenient way to get * them without casting. * @param key the name of the resource. * @exception MissingResourceException * if that particular object could not be found in this bundle nor * the parent bundle. */ public final String getString(String key) throws MissingResourceException { return (String) getObject(key); } /** * Get an array of Strings from this resource bundle. This method * provides a convenient way to get it without casting. * @param key the name of the resource. * @exception MissingResourceException * if that particular object could not be found in this bundle nor * the parent bundle. */ public final String[] getStringArray(String key) throws MissingResourceException { return (String[]) getObject(key); } /** * Get an object from this resource bundle. * @param key the name of the resource. * @exception MissingResourceException * if that particular object could not be found in this bundle nor * the parent bundle. */ public final Object getObject(String key) throws MissingResourceException { for (ResourceBundle bundle = this; bundle != null; bundle = bundle.parent) { try { Object o = bundle.handleGetObject(key); if (o != null) return o; } catch (MissingResourceException ex) { } } throw new MissingResourceException ("Key not found", getClass().getName(), key); } /** * Get the appropriate ResourceBundle for the default locale. * @param baseName the name of the ResourceBundle. This should be * a name of a Class or a properties-File. See the class * description for details. * @return the desired resource bundle * @exception MissingResourceException * if the resource bundle couldn't be found. */ public static final ResourceBundle getBundle(String baseName) throws MissingResourceException { return getBundle(baseName, Locale.getDefault(), security.getCallingClassLoader()); } /** * Get the appropriate ResourceBundle for the given locale. * @param baseName the name of the ResourceBundle. This should be * a name of a Class or a properties-File. See the class * description for details. * @param locale A locale. * @return the desired resource bundle * @exception MissingResourceException * if the resource bundle couldn't be found. */ public static final ResourceBundle getBundle(String baseName, Locale locale) throws MissingResourceException { return getBundle(baseName, locale, security.getCallingClassLoader()); } /** * The resource bundle cache. This is a two-level hash map: The key * is the class loader, the value is a new HashMap. The key of this * second hash map is the localized name, the value is a soft * references to the resource bundle. */ private static Map resourceBundleCache = new HashMap(); /** * The `empty' locale is created once in order to optimize * tryBundle(). */ private static final Locale emptyLocale = new Locale ("", "");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?