sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Deprecate WarningListener, replaced by the more generic StoreListener. In module that do not depend on org.apache.sis.storage, use java.util.logging.Filter.
Date Sat, 07 Sep 2019 16:04:33 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit d756a195f427e468ac9770b925b090f543a02155
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sat Sep 7 16:46:30 2019 +0200

    Deprecate WarningListener, replaced by the more generic StoreListener.
    In module that do not depend on org.apache.sis.storage, use java.util.logging.Filter.
---
 .../java/org/apache/sis/internal/jaxb/Context.java | 13 +++----
 .../apache/sis/metadata/sql/MetadataSource.java    |  6 ++++
 .../src/main/java/org/apache/sis/xml/Pooled.java   | 12 +++++--
 .../src/main/java/org/apache/sis/xml/XML.java      | 16 +++++++++
 .../apache/sis/metadata/iso/MarshallingTest.java   | 24 ++++---------
 .../metadata/iso/citation/DefaultContactTest.java  | 20 +++--------
 .../identification/DefaultBrowseGraphicTest.java   | 17 +++------
 .../main/java/org/apache/sis/referencing/CRS.java  | 41 +++++++++++++++-------
 .../apache/sis/util/logging/WarningListener.java   | 17 ++++++++-
 .../apache/sis/util/logging/WarningListeners.java  |  8 -----
 .../org/apache/sis/internal/storage/xml/Store.java | 34 ++++++++++--------
 .../internal/storage/xml/stream/StaxDataStore.java | 25 +++++--------
 12 files changed, 126 insertions(+), 107 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/Context.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/Context.java
index 5262688..a090b8d 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/Context.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/Context.java
@@ -26,10 +26,10 @@ import java.util.LinkedList;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.logging.LogRecord;
+import java.util.logging.Filter;
 import org.apache.sis.util.Version;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.logging.Logging;
-import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.resources.IndexedResourceBundle;
@@ -181,7 +181,7 @@ public final class Context extends MarshalContext {
     /**
      * The object to inform about warnings, or {@code null} if none.
      */
-    private final WarningListener<?> warningListener;
+    private final Filter warningListener;
 
     /**
      * The {@code <gml:*PropertyType>} which is wrapping the {@code <gml:*Type>}
object to (un)marshal, or
@@ -233,7 +233,7 @@ public final class Context extends MarshalContext {
                    final Version            versionMetadata,
                    final ReferenceResolver  resolver,
                    final ValueConverter     converter,
-                   final WarningListener<?> warningListener)
+                   final Filter             warningListener)
     {
         if (versionMetadata != null && versionMetadata.compareTo(LegacyNamespaces.VERSION_2014)
< 0) {
             bitMasks |= LEGACY_METADATA;
@@ -621,11 +621,12 @@ public final class Context extends MarshalContext {
         record.setSourceMethodName(method);
         record.setLoggerName(Loggers.XML);
         if (context != null) {
-            final WarningListener<?> warningListener = context.warningListener;
+            final Filter warningListener = context.warningListener;
             if (warningListener != null) {
                 record.setThrown(exception);
-                warningListener.warningOccured(null, record);
-                return;
+                if (!warningListener.isLoggable(record)) {
+                    return;
+                }
             }
         }
         /*
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
index 16396c1..5e4a6c2 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
@@ -1100,7 +1100,10 @@ public class MetadataSource implements AutoCloseable {
      *
      * @param  listener  the listener to add.
      * @throws IllegalArgumentException if the given listener is already registered in this
metadata source.
+     *
+     * @deprecated {@code WarningListener} to be replaced by {@link java.util.logging.Filter}.
      */
+    @Deprecated
     public void addWarningListener(final WarningListener<? super MetadataSource> listener)
             throws IllegalArgumentException
     {
@@ -1112,7 +1115,10 @@ public class MetadataSource implements AutoCloseable {
      *
      * @param  listener  the listener to remove.
      * @throws NoSuchElementException if the given listener is not registered in this metadata
source.
+     *
+     * @deprecated {@code WarningListener} to be replaced by {@link java.util.logging.Filter}.
      */
+    @Deprecated
     public void removeWarningListener(final WarningListener<? super MetadataSource>
listener)
             throws NoSuchElementException
     {
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java
index 26c40c4..4d0bcef 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java
@@ -24,6 +24,7 @@ import java.util.IllformedLocaleException;
 import java.util.Locale;
 import java.util.TimeZone;
 import java.util.function.UnaryOperator;
+import java.util.logging.Filter;
 import javax.xml.validation.Schema;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.JAXBException;
@@ -153,7 +154,7 @@ abstract class Pooled {
     /**
      * The object to inform about warnings, or {@code null} if none.
      */
-    private WarningListener<?> warningListener;
+    private Filter warningListener;
 
     /**
      * The {@link System#nanoTime()} value of the last call to {@link #reset(Pooled)}.
@@ -378,8 +379,12 @@ abstract class Pooled {
                     }
                     return;
                 }
+                case XML.WARNING_FILTER: {
+                    warningListener = (Filter) value;
+                    return;
+                }
                 case XML.WARNING_LISTENER: {
-                    warningListener = (WarningListener<?>) value;
+                    warningListener = ((WarningListener<?>) value).asFilter();
                     return;
                 }
                 case TypeRegistration.ROOT_ADAPTERS: {
@@ -420,7 +425,8 @@ abstract class Pooled {
             case XML.METADATA_VERSION:  return versionMetadata;
             case XML.RESOLVER:          return resolver;
             case XML.CONVERTER:         return converter;
-            case XML.WARNING_LISTENER:  return warningListener;
+            case XML.WARNING_FILTER:    return warningListener;
+            case XML.WARNING_LISTENER:  return null;
             case XML.LENIENT_UNMARSHAL: return (bitMasks & Context.LENIENT_UNMARSHAL)
!= 0;
             case XML.STRING_SUBSTITUTES: {
                 int n = 0;
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/XML.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/XML.java
index 1f0255c..25d5411 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/XML.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/XML.java
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.Locale;
 import java.util.TimeZone;
 import java.util.Collections;
+import java.util.logging.Filter;
 import java.util.logging.LogRecord;             // For javadoc
 import java.net.URL;
 import java.io.File;
@@ -361,6 +362,18 @@ public final class XML extends Static {
 
     /**
      * Specifies a listener to be notified when a non-fatal error occurred during the (un)marshalling.
+     * The value for this property shall be an instance of {@link Filter}.
+     *
+     * <p>By default, warnings that occur during the (un)marshalling process are logged.
However if a
+     * property is set for this key, then the {@link Filter#isLoggable(LogRecord)} method
will be invoked.
+     * If that method returns {@code false}, then the warning will not be logged by the (un)marshaller.</p>
+     *
+     * @since 1.0
+     */
+    public static final String WARNING_FILTER = "org.apache.sis.xml.warningFilter";
+
+    /**
+     * Specifies a listener to be notified when a non-fatal error occurred during the (un)marshalling.
      * The value for this property shall be an instance of {@code WarningListener<Object>}.
      *
      * <p>By default, warnings that occur during the (un)marshalling process are logged.
However if a
@@ -368,7 +381,10 @@ public final class XML extends Static {
      * method will be invoked and the warning will <em>not</em> be logged by
the (un)marshaller.</p>
      *
      * @see WarningListener
+     *
+     * @deprecated Replaced by {@link #WARNING_FILTER}.
      */
+    @Deprecated
     public static final String WARNING_LISTENER = "org.apache.sis.xml.warningListener";
 
     /**
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java
index 7492eb4..8eda873 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashMap;
+import java.util.logging.Filter;
 import java.util.logging.LogRecord;
 import java.util.MissingResourceException;
 import java.net.URI;
@@ -54,7 +55,6 @@ import org.apache.sis.metadata.iso.spatial.*;
 import org.apache.sis.util.iso.DefaultRecordSchema;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.util.iso.DefaultInternationalString;
-import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.measure.Units;
 import org.apache.sis.xml.XML;
 import org.apache.sis.xml.NilReason;
@@ -82,7 +82,7 @@ import static org.junit.Assert.*;
  * @since 1.0
  * @module
  */
-public final class MarshallingTest extends TestUsingFile implements WarningListener<Object>
{
+public final class MarshallingTest extends TestUsingFile implements Filter {
     /**
      * The marshaller used to handle marshalling the created DefaultMetadata object.
      */
@@ -113,7 +113,7 @@ public final class MarshallingTest extends TestUsingFile implements WarningListe
         output     = new StringWriter();
         pool       = getMarshallerPool();
         marshaller = pool.acquireMarshaller();
-        marshaller.setProperty(XML.WARNING_LISTENER, this);
+        marshaller.setProperty(XML.WARNING_FILTER, this);
     }
 
     /**
@@ -643,28 +643,17 @@ public final class MarshallingTest extends TestUsingFile implements
WarningListe
     }
 
     /**
-     * For internal {@code DefaultMetadata} usage.
-     *
-     * @return {@code Object.class}.
-     */
-    @Override
-    public Class<Object> getSourceClass() {
-        return Object.class;
-    }
-
-    /**
      * Invoked when a warning occurred while marshalling a test XML fragment. Expected warnings
are
      * "Can't find resource for bundle {@code java.util.PropertyResourceBundle}, key <cite>Foo</cite>".
      * When marshalling legacy XML only, additional warnings may occur.
      *
-     * @param source  ignored.
-     * @param warning the warning.
+     * @param  warning  the warning.
      */
     @Override
-    public void warningOccured(final Object source, final LogRecord warning) {
+    public boolean isLoggable(final LogRecord warning) {
         if (warning.getThrown() instanceof MissingResourceException) {
             assertNull("Expected a warning message without parameters.", warning.getParameters());
-            return;
+            return false;
         }
         final String message = warning.getMessage();
         if (legacyXML) {
@@ -673,5 +662,6 @@ public final class MarshallingTest extends TestUsingFile implements WarningListe
         } else {
             fail("Unexpected logging message: " + message);
         }
+        return false;
     }
 }
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
index ac3af11..e4c0dbe 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
@@ -18,11 +18,11 @@ package org.apache.sis.metadata.iso.citation;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.logging.Filter;
 import java.util.logging.LogRecord;
 import org.opengis.metadata.citation.Telephone;
 import org.opengis.metadata.citation.TelephoneType;
 import org.apache.sis.internal.jaxb.Context;
-import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.xml.TestCase;
 import org.junit.Test;
@@ -40,7 +40,7 @@ import static org.junit.Assert.*;
  * @since   0.5
  * @module
  */
-public final strictfp class DefaultContactTest extends TestCase implements WarningListener<Object>
{
+public final strictfp class DefaultContactTest extends TestCase implements Filter {
     /**
      * The resource key for the message of the warning that occurred, or {@code null} if
none.
      */
@@ -52,29 +52,19 @@ public final strictfp class DefaultContactTest extends TestCase implements
Warni
     private Object[] parameters;
 
     /**
-     * For internal {@code DefaultContact} usage.
-     *
-     * @return {@code Object.class}.
-     */
-    @Override
-    public Class<Object> getSourceClass() {
-        return Object.class;
-    }
-
-    /**
      * Invoked when a warning occurred while unmarshalling a test XML fragment. This method
ensures that no other
      * warning occurred before this method call (i.e. each test is allowed to cause at most
one warning), then
      * remember the warning parameters for verification by the test method.
      *
-     * @param source   ignored.
-     * @param warning  the warning.
+     * @param  warning  the warning.
      */
     @Override
-    public void warningOccured(final Object source, final LogRecord warning) {
+    public boolean isLoggable(final LogRecord warning) {
         assertNull(resourceKey);
         assertNull(parameters);
         assertNotNull(resourceKey = warning.getMessage());
         assertNotNull(parameters  = warning.getParameters());
+        return false;
     }
 
     /**
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultBrowseGraphicTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultBrowseGraphicTest.java
index 3bc89df..d353dd4 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultBrowseGraphicTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultBrowseGraphicTest.java
@@ -18,12 +18,12 @@ package org.apache.sis.metadata.iso.identification;
 
 import java.net.URI;
 import java.io.StringReader;
+import java.util.logging.Filter;
 import java.util.logging.LogRecord;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.JAXBException;
 import javax.xml.transform.stream.StreamSource;
 import org.opengis.metadata.identification.BrowseGraphic;
-import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.Version;
 import org.apache.sis.xml.MarshallerPool;
@@ -287,26 +287,18 @@ public final strictfp class DefaultBrowseGraphicTest extends TestCase
{
     /**
      * A warning listener to be registered by {@link #testWarnings()}.
      */
-    private static final class Warning implements WarningListener<Object> {
+    private static final class Warning implements Filter {
         /**
          * {@code true} if a warning has been sent by the XML unmarshaller.
          */
         boolean receivedWarning;
 
         /**
-         * Fixed to {@code Object.class} as required by {@link XML#WARNING_LISTENER} contract.
-         */
-        @Override
-        public Class<Object> getSourceClass() {
-            return Object.class;
-        }
-
-        /**
          * Invoked when a warning occurred. Ensures that no warning were previously sent,
          * then ensure that the warning content the expected message.
          */
         @Override
-        public void warningOccured(final Object source, final LogRecord warning) {
+        public boolean isLoggable(final LogRecord warning) {
             assertFalse("No other warning were expected.", receivedWarning);
             if (VERBOSE) {
                 /*
@@ -318,6 +310,7 @@ public final strictfp class DefaultBrowseGraphicTest extends TestCase
{
             assertArrayEquals("FileName shall have precedence over CharacterString.",
                     new Object[] {"CharacterString", "FileName"}, warning.getParameters());
             receivedWarning = true;
+            return false;
         }
 
         /**
@@ -325,7 +318,7 @@ public final strictfp class DefaultBrowseGraphicTest extends TestCase
{
          */
         public DefaultBrowseGraphic unmarshal(final String xml) throws JAXBException {
             return (DefaultBrowseGraphic) XML.unmarshal(new StreamSource(new StringReader(xml)),
-                    singletonMap(XML.WARNING_LISTENER, this));
+                    singletonMap(XML.WARNING_FILTER, this));
         }
     }
 }
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
index 1b9b49d..7a7b564 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.logging.Filter;
 import java.util.logging.LogRecord;
 import org.opengis.util.FactoryException;
 import org.opengis.geometry.Envelope;
@@ -392,34 +393,38 @@ public final class CRS extends Static {
      *   <li>Otherwise this method silently returns the given CRS as-is.</li>
      * </ul>
      *
-     * <b>Note:</b> the warnings emitted by this method are redundant with the
warnings emitted by
-     * {@link #fromWKT(String)} and {@link #fromXML(String)}, so the {@code warnings} argument
should be {@code null}
-     * when {@code fromAuthority(…)} is invoked for the CRS parsed by one of above-mentioned
methods.
-     * A non-null {@code warnings} argument is more useful for CRS parsed by {@link org.apache.sis.io.wkt.WKTFormat}
-     * or {@link org.apache.sis.xml.XML#unmarshal(String)} for instance.
-     *
-     * @param  crs       the CRS to replace by an authoritative CRS, or {@code null}.
-     * @param  factory   the factory where to search for authoritative definitions, or {@code
null} for the default.
-     * @param  listener  where to send warnings, or {@code null} for ignoring warnings.
+     * <div class="section">Avoiding warning redundancies</div>
+     * The warnings logged by this method are redundant with warnings logged by other methods
in this class,
+     * in particular {@link #fromWKT(String)} and {@link #fromXML(String)} methods. For avoiding
this annoyance,
+     * a {@code null} value for the {@code warningFilter} argument means to shut off those
redundant loggings.
+     * A non-null {@code warningFilter} argument is more useful for CRS parsed by methods
outside this class,
+     * for example {@link org.apache.sis.io.wkt.WKTFormat} or {@link org.apache.sis.xml.XML#unmarshal(String)}.
+     *
+     * @param  crs            the CRS to replace by an authoritative CRS, or {@code null}.
+     * @param  factory        the factory where to search for authoritative definitions,
or {@code null} for the default.
+     * @param  warningFilter  whether to log warnings, or {@code null} for the default behavior
(which is to filter out
+     *                        the warnings that are redundant with warnings emitted by other
methods in this class).
      * @return the suggested CRS to use (may be the {@code crs} argument itself), or {@code
null} if the given CRS was null.
      * @throws FactoryException if an error occurred while querying the authority factory.
      *
-     * @since 0.8
+     * @since 1.0
      */
     public static CoordinateReferenceSystem fromAuthority(CoordinateReferenceSystem crs,
-            final CRSAuthorityFactory factory, final WarningListener<?> listener) throws
FactoryException
+            final CRSAuthorityFactory factory, final Filter warningFilter) throws FactoryException
     {
         if (crs != null) {
             final DefinitionVerifier verification = DefinitionVerifier.withAuthority(crs,
factory, true);
             if (verification != null) {
                 crs = verification.authoritative;
-                if (listener != null) {
+                if (warningFilter != null) {
                     final LogRecord record = verification.warning(false);
                     if (record != null) {
                         record.setLoggerName(Modules.REFERENCING);
                         record.setSourceClassName(CRS.class.getName());
                         record.setSourceMethodName("fromAuthority");
-                        listener.warningOccured(null, record);
+                        if (warningFilter.isLoggable(record)) {
+                            Logging.getLogger(Modules.REFERENCING).log(record);
+                        }
                     }
                 }
             }
@@ -428,6 +433,16 @@ public final class CRS extends Static {
     }
 
     /**
+     * @deprecated {@code WarningListener} argument replaced by {@code java.util.logging.Filter}.
+     */
+    @Deprecated
+    public static CoordinateReferenceSystem fromAuthority(CoordinateReferenceSystem crs,
+            final CRSAuthorityFactory factory, final WarningListener<?> listener) throws
FactoryException
+    {
+        return fromAuthority(crs, factory, (listener != null) ? listener.asFilter() : null);
+    }
+
+    /**
      * Suggests a coordinate reference system which could be a common target for coordinate
operations having the
      * given sources. This method compares the {@linkplain #getGeographicBoundingBox(CoordinateReferenceSystem)
      * domain of validity} of all given CRSs. If a CRS has a domain of validity that contains
the domain of all other
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java
b/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java
index 17c9562..a97777a 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java
@@ -19,6 +19,7 @@ package org.apache.sis.util.logging;
 import java.util.EventListener;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
+import java.util.logging.Filter;
 
 
 /**
@@ -36,7 +37,7 @@ import java.util.logging.LogRecord;
  * in addition to the log record.</div>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.3
+ * @version 1.0
  *
  * @param <S>  the base type of objects that emit warnings (the <cite>source</cite>).
  *
@@ -46,7 +47,10 @@ import java.util.logging.LogRecord;
  *
  * @since 0.3
  * @module
+ *
+ * @deprecated Replaced by {@link java.util.logging.Filter}.
  */
+@Deprecated
 public interface WarningListener<S> extends EventListener {
     /**
      * Returns the type of objects that emit warnings of interest for this listener.
@@ -75,4 +79,15 @@ public interface WarningListener<S> extends EventListener {
      * @param warning  the warning message together with programmatic information.
      */
     void warningOccured(S source, LogRecord warning);
+
+    /**
+     * Wraps this listener in a {@code java.util.logging.Filter} for transitioning
+     * to the replacement of this interface.
+     */
+    default Filter asFilter() {
+        return (LogRecord warning) -> {
+            warningOccured(null, warning);
+            return false;
+        };
+    }
 }
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
b/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
index 3f22af8..cf51192 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
@@ -85,14 +85,6 @@ public class WarningListeners<S> implements Localized {
     private WarningListener<? super S>[] listeners;
 
     /**
-     * Creates a new instance without source. This constructor is for {@code EmptyWarningListeners}
-     * usage only, because it requires some method to be overloaded.
-     */
-    WarningListeners() {
-        source = null;
-    }
-
-    /**
      * Creates a new instance with initially no listener.
      * Warnings will be logger to the destination given by {@link #getLogger()},
      * unless at least one listener is {@linkplain #addWarningListener registered}.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
index 2cb658d..94504d7 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
@@ -18,6 +18,7 @@ package org.apache.sis.internal.storage.xml;
 
 import java.util.Map;
 import java.util.Collections;
+import java.util.logging.Filter;
 import java.util.logging.LogRecord;
 import java.io.Closeable;
 import java.io.Reader;
@@ -35,7 +36,6 @@ import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.UnsupportedStorageException;
 import org.apache.sis.storage.event.WarningEvent;
 import org.apache.sis.metadata.iso.DefaultMetadata;
-import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.storage.URIDataStore;
@@ -57,11 +57,11 @@ import org.apache.sis.setup.OptionKey;
  * The above list may be extended in any future SIS version.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.4
  * @module
  */
-final class Store extends URIDataStore {
+final class Store extends URIDataStore implements Filter {
     /**
      * The input stream or reader, set by the constructor and cleared when no longer needed.
      */
@@ -123,23 +123,27 @@ final class Store extends URIDataStore {
      */
     private Map<String,?> properties() {
         if (listeners.hasListeners(WarningEvent.class)) {
-            return Collections.singletonMap(XML.WARNING_LISTENER, new WarningListener<Object>()
{
-                /** Returns the type of objects that emit warnings of interest for this listener.
*/
-                @Override public Class<Object> getSourceClass() {
-                    return Object.class;
-                }
-
-                /** Reports the occurrence of a non-fatal error during XML unmarshalling.
*/
-                @Override public void warningOccured(final Object source, final LogRecord
warning) {
-                    warning.setLoggerName(Loggers.XML);
-                    listeners.warning(warning);
-                }
-            });
+            return Collections.singletonMap(XML.WARNING_FILTER, this);
         }
         return null;
     }
 
     /**
+     * Intercepts warnings produced during the (un)marshalling process and redirect them
to the listeners.
+     * This method is public as an implementation convenience for {@link #properties()} method;
+     * it should not be invoked directly.
+     *
+     * @param  warning  the warning that occurred during (un)marshalling.
+     * @return always {@code false} since logging will be handled by {@code listeners}.
+     */
+    @Override
+    public boolean isLoggable(final LogRecord warning) {
+        warning.setLoggerName(Loggers.XML);
+        listeners.warning(warning);
+        return false;
+    }
+
+    /**
      * Unmarshal the object, if not already done. Note that {@link #object} may still be
null
      * if an exception has been thrown at this invocation time or in previous invocation.
      *
diff --git a/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java
b/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java
index 299e6b4..9dc4462 100644
--- a/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java
+++ b/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java
@@ -20,6 +20,7 @@ import java.util.Locale;
 import java.util.TimeZone;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
+import java.util.logging.Filter;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
@@ -52,7 +53,6 @@ import org.apache.sis.storage.ConcurrentWriteException;
 import org.apache.sis.storage.DataStoreClosedException;
 import org.apache.sis.storage.ForwardOnlyStorageException;
 import org.apache.sis.storage.UnsupportedStorageException;
-import org.apache.sis.util.logging.WarningListener;
 
 
 /**
@@ -288,7 +288,7 @@ public abstract class StaxDataStore extends URIDataStore {
      * Holds information that can be used for (un)marshallers configuration, and opportunistically
      * implement various listeners used by JAXB (actually the SIS wrappers) or StAX.
      */
-    private final class Config extends AbstractMap<String,Object> implements XMLReporter,
WarningListener<Object> {
+    private final class Config extends AbstractMap<String,Object> implements XMLReporter,
Filter {
         /**
          * Fetches configuration information from the given object.
          */
@@ -306,9 +306,9 @@ public abstract class StaxDataStore extends URIDataStore {
         public Object get(final Object key) {
             if (key instanceof String) {
                 switch ((String) key) {
-                    case XML.LOCALE:           return locale;
-                    case XML.TIMEZONE:         return timezone;
-                    case XML.WARNING_LISTENER: return this;
+                    case XML.LOCALE:         return locale;
+                    case XML.TIMEZONE:       return timezone;
+                    case XML.WARNING_FILTER: return this;
                 }
             }
             return null;
@@ -319,7 +319,7 @@ public abstract class StaxDataStore extends URIDataStore {
          */
         @Override
         protected EntryIterator<String, Object> entryIterator() {
-            return new KeyIterator(XML.LOCALE, XML.TIMEZONE, XML.WARNING_LISTENER);
+            return new KeyIterator(XML.LOCALE, XML.TIMEZONE, XML.WARNING_FILTER);
         }
 
         /**
@@ -342,22 +342,13 @@ public abstract class StaxDataStore extends URIDataStore {
         /**
          * Reports a warning represented by the given log record.
          *
-         * @param source   ignored (typically a JAXB object being unmarshalled). Can be {@code
null}.
          * @param warning  the warning as a log record.
          */
         @Override
-        public void warningOccured(final Object source, final LogRecord warning) {
+        public boolean isLoggable(final LogRecord warning) {
             warning.setLoggerName(null);        // For allowing 'listeners' to select a logger
name.
             listeners.warning(warning);
-        }
-
-        /**
-         * Returns the type of objects that emit warnings of interest for this listener.
-         * Fixed to {@code Object.class} as required by {@link org.apache.sis.xml.XML#WARNING_LISTENER}
documentation.
-         */
-        @Override
-        public final Class<Object> getSourceClass() {
-            return Object.class;
+            return false;
         }
 
         /**


Mime
View raw message