openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mprud...@apache.org
Subject svn commit: r477436 - /incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
Date Tue, 21 Nov 2006 00:29:53 GMT
Author: mprudhom
Date: Mon Nov 20 16:29:53 2006
New Revision: 477436

URL: http://svn.apache.org/viewvc?view=rev&rev=477436
Log:
Removed dependency on Class.getPackage() for finding localizer.properties files, since that
method can sometimes return null.

Modified:
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java?view=diff&rev=477436&r1=477435&r2=477436
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
Mon Nov 20 16:29:53 2006
@@ -77,12 +77,12 @@
         if (locale == null)
             locale = Locale.getDefault();
 
-        Package pkg = cls == null ? null : cls.getPackage();
+        int dot = (cls == null) ? -1 : cls.getName().lastIndexOf('.');
         String file;
-        if (pkg == null)
+        if (dot == -1)
             file = "localizer";
         else
-            file = pkg.getName() + ".localizer";
+            file = cls.getName().substring(0, dot + 1) + "localizer";
         String key = file + locale.toString();
 
         // no locking; ok if bundle created multiple times
@@ -91,7 +91,7 @@
         if (loc != null)
             return loc;
         else {
-            loc = new Localizer(pkg, file, locale, 
+            loc = new Localizer(cls, file, locale, 
                 cls == null ? null : cls.getClassLoader());
             _localizers.put(key, loc);
             return loc;
@@ -114,12 +114,12 @@
 
     private String _file;
     private ResourceBundle _bundle = null;
-    private Package _package;
+    private Class _cls;
     private Locale _locale;
     private ClassLoader _loader;
 
-    private Localizer(Package p, String f, Locale locale, ClassLoader loader) {
-        _package = p;
+    private Localizer(Class c, String f, Locale locale, ClassLoader loader) {
+        _cls = c;
         _file = f;
         _locale = locale;
         _loader = loader;
@@ -212,7 +212,7 @@
      * @see #get(String)
      */
     public Message get(String key, Object[] subs) {
-        return new Message(_package, getBundle(), key, subs, false);
+        return new Message(_cls, getBundle(), key, subs, false);
     }
 
     /**
@@ -224,7 +224,7 @@
      * @see #getFatal(String)
      */
     public Message getFatal(String key, Object[] subs) {
-        return new Message(_package, getBundle(), key, subs, true);
+        return new Message(_cls, getBundle(), key, subs, true);
     }
 
     /**
@@ -234,17 +234,17 @@
      */
     public static class Message {
 
-        private final Package _package;
+        private final Class _cls;
         private final String _key;
         private final Object[] _subs;
         private final String _localizedMessage;
 
-        private Message(Package pkg, ResourceBundle bundle, String key, 
+        private Message(Class cls, ResourceBundle bundle, String key, 
             Object[] subs, boolean fatal) {
             if (bundle == null && fatal)
                 throw new MissingResourceException(key, key, key);
 
-            _package = pkg;
+            _cls = cls;
             _key = key;
             _subs = subs;
             if (bundle == null) {
@@ -282,13 +282,6 @@
             return _subs;
         }
 
-        /**
-         * Package containing localized resource for this message.
-         */
-        public Package getPackage() {
-            return _package;
-        }
-        
         public String toString() {
             return getMessage();
         }



Mime
View raw message