sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1487925 - in /sis/branches/JDK7/storage: sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/ sis-netcdf/src/ma...
Date Thu, 30 May 2013 16:45:11 GMT
Author: desruisseaux
Date: Thu May 30 16:45:11 2013
New Revision: 1487925

URL: http://svn.apache.org/r1487925
Log:
Take locale in account.

Modified:
    sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
    sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
    sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
    sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningConsumer.java
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningProducer.java

Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java?rev=1487925&r1=1487924&r2=1487925&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
[UTF-8] Thu May 30 16:45:11 2013
@@ -103,7 +103,7 @@ public abstract class Decoder extends Wa
         try {
             return Double.valueOf(value);
         } catch (NumberFormatException e) {
-            warning("numericValue", e);
+            warning("numericValue", null, e);
         }
         return null;
     }
@@ -133,7 +133,7 @@ public abstract class Decoder extends Wa
         if (unit != null) try {
             return Units.valueOf(unit);
         } catch (IllegalArgumentException e) {
-            warning("unitValue", e);
+            warning("unitValue", null, e);
         }
         return null;
     }

Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java?rev=1487925&r1=1487924&r2=1487925&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
[UTF-8] Thu May 30 16:45:11 2013
@@ -192,7 +192,7 @@ public final class ChannelDecoder extend
          */
         int version = input.readInt();
         if ((version & 0xFFFFFF00) != (('C' << 24) | ('D' << 16) | ('F' <<
 8))) {
-            throw new DataStoreException(Errors.format(Errors.Keys.UnexpectedFileFormat_2,
"NetCDF", filename));
+            throw new DataStoreException(errors().getString(Errors.Keys.UnexpectedFileFormat_2,
"NetCDF", filename));
         }
         /*
          * Check the version number.
@@ -201,7 +201,7 @@ public final class ChannelDecoder extend
         switch (version) {
             case 1:  is64bits = false; break;
             case 2:  is64bits = true;  break;
-            default: throw new DataStoreException(Errors.format(Errors.Keys.UnsupportedVersion_1,
version));
+            default: throw new DataStoreException(errors().getString(Errors.Keys.UnsupportedVersion_1,
version));
         }
         numrecs = input.readInt();
         /*
@@ -252,7 +252,7 @@ public final class ChannelDecoder extend
      * that the file should be a NetCDF one, but we found some inconsistency or unknown tags.
      */
     private DataStoreException malformedHeader() {
-        return new DataStoreException(Errors.format(Errors.Keys.CanNotParseFile_2, "NetCDF",
input.filename));
+        return new DataStoreException(errors().getString(Errors.Keys.CanNotParseFile_2, "NetCDF",
input.filename));
     }
 
     /**
@@ -260,7 +260,7 @@ public final class ChannelDecoder extend
      */
     private void ensureNonNegative(final int nelems, final int tag) throws DataStoreException
{
         if (nelems < 0) {
-            throw new DataStoreException(Errors.format(Errors.Keys.NegativeArrayLength_1,
+            throw new DataStoreException(errors().getString(Errors.Keys.NegativeArrayLength_1,
                     input.filename + DefaultNameSpace.DEFAULT_SEPARATOR + tagName(tag)));
         }
     }
@@ -284,9 +284,10 @@ public final class ChannelDecoder extend
         final long size = ((n & 0xFFFFFFFFL) * dataSize + 3) & ~3;
         if (size > input.buffer.capacity()) {
             name = input.filename + DefaultNameSpace.DEFAULT_SEPARATOR + name;
+            final Errors errors = errors();
             throw new DataStoreException(n < 0 ?
-                    Errors.format(Errors.Keys.NegativeArrayLength_1, name) :
-                    Errors.format(Errors.Keys.ExcessiveListSize_2, name, n));
+                    errors.getString(Errors.Keys.NegativeArrayLength_1, name) :
+                    errors.getString(Errors.Keys.ExcessiveListSize_2, name, n));
         }
         input.ensureBufferContains((int) size);
         return (int) size;
@@ -394,7 +395,7 @@ public final class ChannelDecoder extend
             if (length == 0) {
                 length = numrecs;
                 if (length == STREAMING) {
-                    throw new DataStoreException(Errors.format(Errors.Keys.MissingValueForProperty_1,
"numrecs"));
+                    throw new DataStoreException(errors().getString(Errors.Keys.MissingValueForProperty_1,
"numrecs"));
                 }
             }
             dimensions[i] = new Dimension(name, length);
@@ -603,7 +604,7 @@ public final class ChannelDecoder extend
             if (attribute.value instanceof String) try {
                 return JDK8.parseDateTime((String) attribute.value, DEFAULT_TIMEZONE_IS_UTC);
             } catch (IllegalArgumentException e) {
-                warning("dateValue", e);
+                warning("dateValue", null, e);
             }
         }
         return null;
@@ -630,7 +631,7 @@ public final class ChannelDecoder extend
                 }
             }
         } catch (ConversionException | IllegalArgumentException e) {
-            warning("numberToDate", e);
+            warning("numberToDate", null, e);
         }
         return dates;
     }

Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java?rev=1487925&r1=1487924&r2=1487925&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
[UTF-8] Thu May 30 16:45:11 2013
@@ -229,7 +229,7 @@ public final class DecoderWrapper extend
                         try {
                             date = CalendarDateFormatter.isoStringToCalendarDate(Calendar.proleptic_gregorian,
value);
                         } catch (IllegalArgumentException e) {
-                            warning("dateValue", e);
+                            warning("dateValue", null, e);
                             continue;
                         }
                         return new Date(date.getMillis());
@@ -254,7 +254,7 @@ public final class DecoderWrapper extend
         try {
             unit = new DateUnit(symbol);
         } catch (Exception e) { // Declared by the DateUnit constructor.
-            warning("numberToDate", e);
+            warning("numberToDate", null, e);
             return dates;
         }
         for (int i=0; i<values.length; i++) {
@@ -341,7 +341,7 @@ public final class DecoderWrapper extend
      */
     @Override
     public void setError(final String message) {
-        warning(null, message);
+        warning(null, message, null);
     }
 
     /**

Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java?rev=1487925&r1=1487924&r2=1487925&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
[UTF-8] Thu May 30 16:45:11 2013
@@ -272,7 +272,7 @@ final class MetadataReader extends Warni
             resource.setFunction(OnLineFunction.INFORMATION);
             return resource;
         } catch (URISyntaxException e) {
-            warning("createOnlineResource", e);
+            warning("createOnlineResource", null, e);
         }
         return null;
     }
@@ -677,7 +677,7 @@ final class MetadataReader extends Warni
             }
             extent.getTemporalElements().add(t);
         } catch (UnsupportedOperationException e) {
-            warning("createExtent", e);
+            warning("createExtent", null, e);
         }
         /*
          * Add the geographic identifier, if present.
@@ -700,7 +700,7 @@ final class MetadataReader extends Warni
         if (source != null) try {
             return source.getConverterToAny(target);
         } catch (ConversionException e) {
-            warning("getConverterTo", e);
+            warning("getConverterTo", null, e);
         }
         return null;
     }

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningConsumer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningConsumer.java?rev=1487925&r1=1487924&r2=1487925&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningConsumer.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningConsumer.java
[UTF-8] Thu May 30 16:45:11 2013
@@ -16,9 +16,11 @@
  */
 package org.apache.sis.internal.storage;
 
+import java.util.Locale;
 import java.util.logging.Logger;
 import java.util.logging.LogRecord;
 import java.util.NoSuchElementException;
+import org.apache.sis.util.Localized;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.logging.WarningListener;
@@ -67,6 +69,16 @@ public final class WarningConsumer<T> ex
     }
 
     /**
+     * The locale to use for formatting warning messages, or {@code null} for the default
locale.
+     * This method returns the {@link #source} locale if it implements the {@link Localized}
interface,
+     * or {@code null} otherwise.
+     */
+    @Override
+    public Locale getLocale() {
+        return (source instanceof Localized) ? ((Localized) source).getLocale() : null;
+    }
+
+    /**
      * Invoked when a new warning has been emitted. This method notifies the listeners if
any,
      * or log the warning otherwise.
      */

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningProducer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningProducer.java?rev=1487925&r1=1487924&r2=1487925&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningProducer.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/WarningProducer.java
[UTF-8] Thu May 30 16:45:11 2013
@@ -16,11 +16,15 @@
  */
 package org.apache.sis.internal.storage;
 
+import java.util.Locale;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
+import org.apache.sis.util.Localized;
 import org.apache.sis.util.Exceptions;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.logging.WarningListener;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -45,7 +49,7 @@ import org.apache.sis.util.logging.Warni
  * @version 0.3
  * @module
  */
-public class WarningProducer {
+public class WarningProducer implements Localized {
     /**
      * Where to send the warnings, or {@code null} if none. This field is always {@code null}
for
      * {@link WarningConsumer}, since the later will redirect warnings to the listeners (if
any).
@@ -62,6 +66,19 @@ public class WarningProducer {
     }
 
     /**
+     * The locale to use for formatting warning messages, or {@code null} for the default
locale.
+     * The default implementation returns the {@link #sink} locale if any, or {@code null}
otherwise.
+     * Subclasses can override this method if they are configured for formatting the error
messages
+     * is some specific locale.
+     *
+     * @return The locale for formatting warning messages, or {@code null} for the default.
+     */
+    @Override
+    public Locale getLocale() {
+        return (sink != null) ? sink.getLocale() : null;
+    }
+
+    /**
      * Reports a warning represented by the given log record. The default implementation
delegates to the
      * {@link #sink} if any, or logs the message to a default logger otherwise. The {@link
WarningConsumer}
      * subclass overrides this method in order to notify listeners or use a different logger.
@@ -78,12 +95,21 @@ public class WarningProducer {
     }
 
     /**
-     * Reports a warning represented by the given message.
+     * Reports a warning represented by the given message and exception.
+     * At least one of {@code message} and {@code exception} shall be non-null.
      *
      * @param methodName The name of the method in which the warning occurred.
-     * @param message    The message to log.
+     * @param message    The message to log, or {@code null} if none.
+     * @param exception  The exception to log, or {@code null} if none.
      */
-    protected final void warning(final String methodName, final String message) {
+    protected final void warning(final String methodName, String message, final Exception
exception) {
+        if (exception != null) {
+            message = Exceptions.formatChainedMessages(getLocale(), message, exception);
+            if (message == null) {
+                message = exception.toString();
+            }
+        }
+        ArgumentChecks.ensureNonEmpty("message", message);
         final LogRecord record = new LogRecord(Level.WARNING, message);
         record.setSourceClassName(getClass().getCanonicalName());
         record.setSourceMethodName(methodName);
@@ -91,12 +117,11 @@ public class WarningProducer {
     }
 
     /**
-     * Reports a warning represented by the given exception.
+     * Returns the localized error resource bundle for the locale given by {@link #getLocale()}.
      *
-     * @param methodName The name of the method in which the warning occurred.
-     * @param exception  The exception to log.
+     * @return The localized error resource bundle.
      */
-    protected final void warning(final String methodName, final Exception exception) {
-        warning(methodName, Exceptions.formatChainedMessages(null, null, exception));
+    protected final Errors errors() {
+        return Errors.getResources(getLocale());
     }
 }



Mime
View raw message