< prev index next >

src/com/sun/javatest/util/I18NResourceBundle.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


  32 import java.security.PrivilegedAction;
  33 import java.text.MessageFormat;
  34 import java.util.Enumeration;
  35 import java.util.Locale;
  36 import java.util.ResourceBundle;
  37 import java.util.MissingResourceException;
  38 
  39 /**
  40  * A class that lazily opens a package-specific resource bundle
  41  * containing localization data for a class.
  42  */
  43 public class I18NResourceBundle extends ResourceBundle
  44 {
  45     /**
  46      * Get a package-specific resource bundle for a class containing localization data.
  47      * The bundle is named i18n.properties in the same
  48      * package as the given class.
  49      * @param c the class for which to obtain the resource bundle
  50      * @return the appropriate resource bundle for the class
  51      */
  52     public static I18NResourceBundle getBundleForClass(Class c) {
  53         String cn = c.getName();
  54         int dot = cn.lastIndexOf('.');
  55         String rn = (dot == -1 ? "i18n" : cn.substring(0, dot) + ".i18n");
  56         boolean logging = (logClassPrefix == null ? false : cn.startsWith(logClassPrefix));
  57         return new I18NResourceBundle(rn, logging, c.getClassLoader());
  58     }
  59 
  60     /**
  61      * Get an entry from the resource bundle.
  62      * If the resource cannot be found, a message is printed to the console
  63      * and the result will be a string containing the method parameters.
  64      * @param key the name of the entry to be returned
  65      * @param arg an argument to be formatted into the result using
  66      * {@link java.text.MessageFormat#format}
  67      * @return the formatted string
  68      */
  69     public String getString(String key, Object arg) {
  70         return getString(key, new Object[] {arg});
  71     }
  72 




  32 import java.security.PrivilegedAction;
  33 import java.text.MessageFormat;
  34 import java.util.Enumeration;
  35 import java.util.Locale;
  36 import java.util.ResourceBundle;
  37 import java.util.MissingResourceException;
  38 
  39 /**
  40  * A class that lazily opens a package-specific resource bundle
  41  * containing localization data for a class.
  42  */
  43 public class I18NResourceBundle extends ResourceBundle
  44 {
  45     /**
  46      * Get a package-specific resource bundle for a class containing localization data.
  47      * The bundle is named i18n.properties in the same
  48      * package as the given class.
  49      * @param c the class for which to obtain the resource bundle
  50      * @return the appropriate resource bundle for the class
  51      */
  52     public static I18NResourceBundle getBundleForClass(Class<?> c) {
  53         String cn = c.getName();
  54         int dot = cn.lastIndexOf('.');
  55         String rn = (dot == -1 ? "i18n" : cn.substring(0, dot) + ".i18n");
  56         boolean logging = (logClassPrefix == null ? false : cn.startsWith(logClassPrefix));
  57         return new I18NResourceBundle(rn, logging, c.getClassLoader());
  58     }
  59 
  60     /**
  61      * Get an entry from the resource bundle.
  62      * If the resource cannot be found, a message is printed to the console
  63      * and the result will be a string containing the method parameters.
  64      * @param key the name of the entry to be returned
  65      * @param arg an argument to be formatted into the result using
  66      * {@link java.text.MessageFormat#format}
  67      * @return the formatted string
  68      */
  69     public String getString(String key, Object arg) {
  70         return getString(key, new Object[] {arg});
  71     }
  72 


< prev index next >