sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1586807 - in /sis/branches/JDK8: core/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerAdapter.java pom.xml
Date Sat, 12 Apr 2014 02:35:15 GMT
Author: desruisseaux
Date: Sat Apr 12 02:35:15 2014
New Revision: 1586807

URL: http://svn.apache.org/r1586807
Log:
Update for JDK8 changes: Logger.logrb(..., String bundleName, ...) deprecated in favor of
logrb(..., ResourceBundle bundle, ...).

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerAdapter.java
    sis/branches/JDK8/pom.xml

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerAdapter.java?rev=1586807&r1=1586806&r2=1586807&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerAdapter.java
[UTF-8] Sat Apr 12 02:35:15 2014
@@ -71,7 +71,7 @@ import org.apache.sis.util.Debug;
  * behavior since their configuration is entirely contained in the external logging framework.
  *
  * {@section Localization}
- * This logger is always created without resource bundles. Localizations must be performed
through
+ * This logger is always created without resource bundles. Localizations shall be done through
  * explicit calls to {@code logrb} or {@link #log(LogRecord)} methods. This is sufficient
for
  * SIS needs, which performs all localizations through the later. Note that those methods
  * will be slower in this {@code LoggerAdapter} than the default {@link Logger} because this
@@ -87,7 +87,7 @@ import org.apache.sis.util.Debug;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3 (derived from geotk-2.4)
- * @version 0.3
+ * @version 0.5
  * @module
  *
  * @see Logging
@@ -352,8 +352,9 @@ public abstract class LoggerAdapter exte
     }
 
     /**
-     * Logs a record. The default implementation delegates to
-     * {@link #logrb(Level,String,String,String,String,Object[]) logrb}.
+     * Logs a record. The default implementation delegates to one of the
+     * {@link #logrb(Level,String,String,ResourceBundle,String,Object[]) logrb} or
+     * {@link #logp(Level,String,String,String)} methods.
      *
      * @param record The log record to be published.
      */
@@ -369,37 +370,34 @@ public abstract class LoggerAdapter exte
         if (filter != null && !filter.isLoggable(record)) {
             return;
         }
-        Level     level        = record.getLevel();
-        String    sourceClass  = record.getSourceClassName();
-        String    sourceMethod = record.getSourceMethodName();
-        String    bundleName   = record.getResourceBundleName();
-        String    message      = record.getMessage();
-        Object[]  params       = record.getParameters();
-        Throwable thrown       = record.getThrown();
-        ResourceBundle bundle  = record.getResourceBundle();
-        boolean   localized    = false;
-        if (bundle != null) try {
-            message   = bundle.getString(message);
-            localized = true; // Sets only if the above succeed.
-        } catch (MissingResourceException e) {
-            // The default Formatter.messageFormat implementation ignores this exception
-            // and uses the bundle key as the message, so we mimic its behavior here.
-        }
+        final Level     level        = record.getLevel();
+        final String    sourceClass  = record.getSourceClassName();
+        final String    sourceMethod = record.getSourceMethodName();
+        final String    message      = record.getMessage();
+        final Object[]  params       = record.getParameters();
+        final Throwable thrown       = record.getThrown();
+        final ResourceBundle bundle  = record.getResourceBundle();
         final boolean useThrown = (thrown != null) && (params == null || params.length
== 0);
-        if (localized) {
-            // The message is already localized.
+        if (bundle != null) {
             if (useThrown) {
-                logp(level, sourceClass, sourceMethod, message, thrown);
+                logrb(level, sourceClass, sourceMethod, bundle, message, thrown);
             } else {
-                logp(level, sourceClass, sourceMethod, message, params);
+                logrb(level, sourceClass, sourceMethod, bundle, message, params);
             }
         } else {
-            // The message needs to be localized. The bundle was null but maybe bundleName
is not.
-            // Futhermore subclass may have overridden the 'logrb' methods.
-            if (useThrown) {
-                logrb(level, sourceClass, sourceMethod, bundleName, message, thrown);
+            final String bundleName = record.getResourceBundleName();
+            if (bundleName != null) {
+                if (useThrown) {
+                    logrb(level, sourceClass, sourceMethod, bundleName, message, thrown);
+                } else {
+                    logrb(level, sourceClass, sourceMethod, bundleName, message, params);
+                }
             } else {
-                logrb(level, sourceClass, sourceMethod, bundleName, message, params);
+                if (useThrown) {
+                    logp(level, sourceClass, sourceMethod, message, thrown);
+                } else {
+                    logp(level, sourceClass, sourceMethod, message, params);
+                }
             }
         }
     }
@@ -558,6 +556,48 @@ public abstract class LoggerAdapter exte
 
     /**
      * Logs a localizable record at the specified level. The default implementation localizes
the
+     * message immediately, then delegates to <code>{@linkplain #logp(Level,String,String,String,
+     * Object[]) logp}(level, sourceClass, sourceMethod, message, params)</code>.
+     *
+     * @param level        One of the message level identifiers.
+     * @param sourceClass  Name of class that issued the logging request.
+     * @param sourceMethod Name of the method.
+     * @param bundle       The resource bundle for localizing the message, or {@code null}.
+     * @param message      The message to log.
+     * @param params       Array of parameters to the method being entered.
+     *
+     * @since 0.5
+     */
+    @Override
+    public void logrb(final Level level, final String sourceClass, final String sourceMethod,
+                      final ResourceBundle bundle, final String message, final Object...
params)
+    {
+        logp(level, sourceClass, sourceMethod, localize(bundle, message), params);
+    }
+
+    /**
+     * Logs a localizable record at the specified level. The default implementation localizes
the
+     * message immediately, then delegates to <code>{@linkplain #logp(Level,String,String,String,
+     * Throwable) logp}(level, sourceClass, sourceMethod, message, thrown)</code>.
+     *
+     * @param level        One of the message level identifiers.
+     * @param sourceClass  Name of class that issued the logging request.
+     * @param sourceMethod Name of the method.
+     * @param bundle       The resource bundle for localizing the message, or {@code null}.
+     * @param message      The message to log.
+     * @param thrown       Throwable associated with log message.
+     *
+     * @since 0.5
+     */
+    @Override
+    public void logrb(final Level level, final String sourceClass, final String sourceMethod,
+                      final ResourceBundle bundle, final String message, final Throwable
thrown)
+    {
+        logp(level, sourceClass, sourceMethod, localize(bundle, message), thrown);
+    }
+
+    /**
+     * Logs a localizable record at the specified level. The default implementation localizes
the
      * message immediately, then delegates to <code>{@linkplain #logp(Level,String,String,String)
      * logp}(level, sourceClass, sourceMethod, message)</code>.
      *
@@ -566,8 +606,11 @@ public abstract class LoggerAdapter exte
      * @param sourceMethod Name of the method.
      * @param bundleName   Name of resource bundle to localize message, or {@code null}.
      * @param message      The message to log.
+     *
+     * @deprecated JDK 8 has deprecated this method.
      */
     @Override
+    @Deprecated
     public void logrb(final Level level, final String sourceClass, final String sourceMethod,
                       final String bundleName, final String message)
     {
@@ -585,8 +628,11 @@ public abstract class LoggerAdapter exte
      * @param bundleName   Name of resource bundle to localize message, or {@code null}.
      * @param message      The message to log.
      * @param thrown       Throwable associated with log message.
+     *
+     * @deprecated JDK 8 has deprecated this method.
      */
     @Override
+    @Deprecated
     public void logrb(final Level level, final String sourceClass, final String sourceMethod,
                       final String bundleName, final String message, final Throwable thrown)
     {
@@ -604,8 +650,11 @@ public abstract class LoggerAdapter exte
      * @param bundleName   Name of resource bundle to localize message, or {@code null}.
      * @param message      The message to log.
      * @param param        Parameter to the method being entered.
+     *
+     * @deprecated JDK 8 has deprecated this method.
      */
     @Override
+    @Deprecated
     public void logrb(final Level level, final String sourceClass, final String sourceMethod,
                       final String bundleName, final String message, final Object param)
     {
@@ -623,10 +672,13 @@ public abstract class LoggerAdapter exte
      * @param bundleName   Name of resource bundle to localize message, or {@code null}.
      * @param message      The message to log.
      * @param params       Array of parameters to the method being entered.
+     *
+     * @deprecated JDK 8 has deprecated this method.
      */
     @Override
+    @Deprecated
     public void logrb(final Level level, final String sourceClass, final String sourceMethod,
-                      final String bundleName, String message, final Object[] params)
+                      final String bundleName, final String message, final Object[] params)
     {
         logp(level, sourceClass, sourceMethod, localize(bundleName, message), params);
     }
@@ -724,4 +776,18 @@ public abstract class LoggerAdapter exte
         }
         return message;
     }
+
+    /**
+     * Localizes the specified message. This is a helper method for
+     * {@code logrb(...)} methods that delegate their work to {@code logp(...)}
+     */
+    private static String localize(final ResourceBundle bundle, String message) {
+        if (bundle != null) try {
+            message = bundle.getString(message);
+        } catch (MissingResourceException e) {
+            // The default Formatter.messageFormat implementation ignores this exception
+            // and uses the bundle key as the message, so we mimic its behavior here.
+        }
+        return message;
+    }
 }

Modified: sis/branches/JDK8/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/pom.xml?rev=1586807&r1=1586806&r2=1586807&view=diff
==============================================================================
--- sis/branches/JDK8/pom.xml (original)
+++ sis/branches/JDK8/pom.xml Sat Apr 12 02:35:15 2014
@@ -405,7 +405,7 @@ Apache SIS is a free software, Java lang
     <!-- Following properties are branch-specific -->
     <maven.compile.source>1.8</maven.compile.source>
     <maven.compile.target>1.8</maven.compile.target>
-    <sis.plugin.version>0.4</sis.plugin.version>
+    <sis.plugin.version>${project.version}</sis.plugin.version>
     <geoapi.version>3.1-SNAPSHOT</geoapi.version>
   </properties>
 
@@ -435,6 +435,9 @@ Apache SIS is a free software, Java lang
           <source>${maven.compile.source}</source>
           <target>${maven.compile.target}</target>
           <encoding>${project.build.sourceEncoding}</encoding>
+          <compilerArgs>
+            <arg>-Xlint:all</arg>
+          </compilerArgs>
         </configuration>
       </plugin>
 



Mime
View raw message