commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r349012 - /jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/CollectionResourcesBase.java
Date Fri, 25 Nov 2005 20:15:08 GMT
Author: niallp
Date: Fri Nov 25 12:14:56 2005
New Revision: 349012

URL: http://svn.apache.org/viewcvs?rev=349012&view=rev
Log:
Add setDefaultLocale() for instance variable made private and additional debug logging.

Modified:
    jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/CollectionResourcesBase.java

Modified: jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/CollectionResourcesBase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/CollectionResourcesBase.java?rev=349012&r1=349011&r2=349012&view=diff
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/CollectionResourcesBase.java
(original)
+++ jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/CollectionResourcesBase.java
Fri Nov 25 12:14:56 2005
@@ -33,6 +33,8 @@
 import java.util.Set;
 import java.util.TimeZone;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.resources.ResourcesException;
 import org.apache.commons.resources.ResourcesKeyException;
 
@@ -50,6 +52,12 @@
 public abstract class CollectionResourcesBase extends ResourcesBase {
 
     /**
+     * <p>The logging instance for this class.</p>
+     */
+    private transient Log log =
+        LogFactory.getLog(CollectionResourcesBase.class);
+
+    /**
      * <p>Create a new {@link org.apache.commons.resources.Resources} instance with
the specified
      * logical name and base URL.</p>
      *
@@ -99,6 +107,14 @@
 
 
     /**
+     * Set the default locale.
+     * @param defaultLocale The default Locale.
+     */
+    public void setDefaultLocale(Locale defaultLocale) {
+        this.defaultLocale = defaultLocale;
+    }
+
+    /**
      * @see org.apache.commons.resources.impl.ResourcesBase#getKeys()
      */
     public Iterator getKeys() {
@@ -147,6 +163,11 @@
      */
     public Object getObject(String key, Locale locale, TimeZone timeZone) {
 
+        if (getLog().isTraceEnabled()) {
+            getLog().trace("Retrieving message for key '" + key + "' and locale '"
+                      + locale + "'");
+        }
+
         if (locale == null) {
             locale = defaultLocale;
         }
@@ -159,10 +180,21 @@
         for (int i = 0; i < n; i++) {
             Map map = getLocaleMap((Locale) list.get(i));
             if (map.containsKey(key)) {
-                return (map.get(key));
+                Object object  = map.get(key);
+                if (getLog().isTraceEnabled()) {
+                    getLog().trace("Retrieved object for key '" + key + 
+                                   "' and locale '" + locale +
+                                   "' is '" + object + "'");
+                }
+                return object;
             }
         }
 
+        if (getLog().isTraceEnabled()) {
+            getLog().trace("No message found for key '" + key + 
+                           "' and locale '" + locale + "'");
+        }
+
         // No value for this key was located in the entire hierarchy
         if (isReturnNull()) {
             return (null);
@@ -360,5 +392,21 @@
 
     }
 
+    /**
+     * Accessor method for Log instance.
+     *
+     * The Log instance variable is transient and
+     * accessing it through this method ensures it
+     * is re-initialized when this instance is
+     * de-serialized.
+     *
+     * @return The Log instance.
+     */
+    private Log getLog() {
+        if (log == null) {
+            log =  LogFactory.getLog(CollectionResourcesBase.class);
+        }
+        return log;
+    }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message