You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2019/09/12 14:53:41 UTC
[sis] branch geoapi-4.0 updated (b94b082 -> 1387466)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git.
from b94b082 First round of removal of classes/methods deprecated in SIS 1.0. This commit removes only the classes and methods having no dependencies in SIS.
new 25e21ce Remove the deprecated WarningListeners class and interface.
new 3f0bf11 Delete deprecated DistanceUtils class (replaced by GeodeticCalculator) and remove LatLonPointRadius from public API.
new 7762360 Bug fix: MetadataCopier.copy(type, metadata) should accept a type which is a super-type of the interface implemented by the given metadata instance.
new 1387466 Remove the deprecated ModifiableMetadata.unmodifiable() method.
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/org/apache/sis/internal/jaxb/Context.java | 14 +-
.../apache/sis/internal/metadata/Resources.java | 2 +-
.../sis/internal/metadata/Resources.properties | 2 +-
.../sis/internal/metadata/Resources_fr.properties | 2 +-
.../org/apache/sis/metadata/MetadataCopier.java | 2 +-
.../apache/sis/metadata/ModifiableMetadata.java | 120 +------
.../metadata/iso/citation/DefaultTelephone.java | 4 +-
.../apache/sis/metadata/sql/CachedStatement.java | 25 +-
.../apache/sis/metadata/sql/MetadataFallback.java | 15 -
.../apache/sis/metadata/sql/MetadataSource.java | 77 ++---
.../org/apache/sis/metadata/sql/package-info.java | 2 +-
.../src/main/java/org/apache/sis/xml/Pooled.java | 18 +-
.../src/main/java/org/apache/sis/xml/XML.java | 20 +-
.../apache/sis/metadata/MetadataCopierTest.java | 15 +
.../apache/sis/metadata/MetadataStandardTest.java | 4 +-
.../metadata/iso/citation/DefaultCitationTest.java | 17 -
.../referencing/gazetteer/FinalLocationType.java | 20 +-
.../sis/referencing/gazetteer/package-info.java | 2 +-
.../referencing/gazetteer/LocationTypeTest.java | 2 +-
.../org/apache/sis/distance/DistanceUtils.java | 102 ------
.../java/org/apache/sis/util/logging/Logging.java | 28 +-
.../apache/sis/util/logging/QuietLogRecord.java | 73 ----
.../apache/sis/util/logging/WarningListener.java | 92 ------
.../apache/sis/util/logging/WarningListeners.java | 366 ---------------------
.../org/apache/sis/util/logging/package-info.java | 2 +-
.../apache/sis/index/tree}/LatLonPointRadius.java | 61 +---
.../java/org/apache/sis/index/tree/QuadTree.java | 1 -
.../sis/internal/storage/io/ChannelFactory.java | 8 +-
.../apache/sis/storage/event/StoreListeners.java | 58 +---
.../org/apache/sis/storage/event/package-info.java | 2 +-
.../internal/storage/xml/stream/StaxDataStore.java | 2 +-
31 files changed, 147 insertions(+), 1011 deletions(-)
delete mode 100644 core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java
delete mode 100644 core/sis-utility/src/main/java/org/apache/sis/util/logging/QuietLogRecord.java
delete mode 100644 core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java
delete mode 100644 core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
rename {core/sis-referencing/src/main/java/org/apache/sis/distance => storage/sis-storage/src/main/java/org/apache/sis/index/tree}/LatLonPointRadius.java (69%)
[sis] 04/04: Remove the deprecated
ModifiableMetadata.unmodifiable() method.
Posted by de...@apache.org.
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 1387466ac20d88d5b3ab36209d6e1730e0ed7dde
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Sep 12 16:53:01 2019 +0200
Remove the deprecated ModifiableMetadata.unmodifiable() method.
---
.../apache/sis/metadata/ModifiableMetadata.java | 120 +--------------------
.../metadata/iso/citation/DefaultTelephone.java | 4 +-
.../metadata/iso/citation/DefaultCitationTest.java | 17 ---
.../referencing/gazetteer/FinalLocationType.java | 20 ++--
.../sis/referencing/gazetteer/package-info.java | 2 +-
.../referencing/gazetteer/LocationTypeTest.java | 2 +-
6 files changed, 20 insertions(+), 145 deletions(-)
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
index a6a196f..f9c3b78 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
@@ -133,16 +133,6 @@ public abstract class ModifiableMetadata extends AbstractMetadata {
private transient byte state;
/**
- * An unmodifiable copy of this metadata, created only when first needed.
- * If {@code null}, then no unmodifiable entity is available.
- * If {@code this}, then this entity is itself unmodifiable.
- *
- * @deprecated to be deleted after the removal of {@link #unmodifiable()}.
- */
- @Deprecated
- private transient ModifiableMetadata unmodifiable;
-
- /**
* Constructs an initially empty metadata.
* The initial state is {@link State#EDITABLE}.
*/
@@ -297,112 +287,6 @@ public abstract class ModifiableMetadata extends AbstractMetadata {
}
/**
- * Returns {@code true} if this metadata is modifiable. This method returns
- * {@code false} if {@link #freeze()} has been invoked on this object.
- *
- * @return {@code true} if this metadata is modifiable.
- *
- * @see #freeze()
- * @see #checkWritePermission()
- *
- * @deprecated Replaced by <code>{@linkplain #state()} != State.FINAL</code>.
- * See <a href="https://issues.apache.org/jira/browse/SIS-81">SIS-81</a>.
- */
- @Deprecated
- public final boolean isModifiable() {
- return state <= STAGED;
- }
-
- /**
- * Returns an unmodifiable copy of this metadata. Any attempt to modify a property of the
- * returned object will throw an {@link UnmodifiableMetadataException}. The state of this
- * object is not modified.
- *
- * <p>This method is useful for reusing the same metadata object as a template.
- * For example:</p>
- *
- * {@preformat java
- * DefaultCitation myCitation = new DefaultCitation();
- * myCitation.setTitle(new SimpleInternationalString("The title of my book"));
- * myCitation.setEdition(new SimpleInternationalString("First edition"));
- * final Citation firstEdition = (Citation) myCitation.unmodifiable();
- *
- * myCitation.setEdition(new SimpleInternationalString("Second edition"));
- * final Citation secondEdition = (Citation) myCitation.unmodifiable();
- * // The title of the second edition is unchanged compared to the first edition.
- * }
- *
- * The default implementation makes the following choice:
- *
- * <ul>
- * <li>If this metadata is itself unmodifiable, then this method returns {@code this} unchanged.</li>
- * <li>Otherwise this method {@linkplain #clone() clone} this metadata and
- * {@linkplain #freeze() freeze} the clone before to return it.</li>
- * </ul>
- *
- * @return an unmodifiable copy of this metadata.
- *
- * @see MetadataCopier
- *
- * @deprecated Replaced by {@code MetadataCopier.forModifiable(getStandard()).copy(this).transition(State.FINAL)}.
- */
- @Deprecated
- public AbstractMetadata unmodifiable() {
- if (!isModifiable()) {
- unmodifiable = this;
- }
- /*
- * The 'unmodifiable' field is reset to null by checkWritePermission().
- * However this is not sufficient since the setter method of some child
- * could have been invoked without invoking any setter method on 'this'.
- * So we also need to perform an equality check.
- */
- if (unmodifiable == null || !equals(unmodifiable)) {
- final ModifiableMetadata candidate = (ModifiableMetadata) MetadataCopier.forModifiable(getStandard()).copy(this);
- candidate.freeze();
- /*
- * Set the field only after success. The 'unmodifiable' field must
- * stay null if an exception occurred during clone() or freeze().
- */
- unmodifiable = candidate;
- }
- assert !unmodifiable.isModifiable();
- return unmodifiable;
- }
-
- /**
- * Declares this metadata and all its properties as unmodifiable. Any attempt to modify a
- * property after this method call will throw an {@link UnmodifiableMetadataException}.
- * If this metadata is already unmodifiable, then this method does nothing.
- *
- * <p>Subclasses usually do not need to override this method since the default implementation
- * performs its work using Java reflection.</p>
- *
- * @see #state()
- * @see #checkWritePermission()
- *
- * @deprecated Replaced by {@code transition(State.FINAL)}.
- */
- @Deprecated
- public void freeze() {
- transition(State.FINAL);
- }
-
- /**
- * @deprecated Replaced by {@link #checkWritePermission(Object)}.
- *
- * @throws UnmodifiableMetadataException if this metadata is unmodifiable.
- */
- @Deprecated
- protected void checkWritePermission() throws UnmodifiableMetadataException {
- if (state == FINAL) {
- throw new UnmodifiableMetadataException(Resources.format(Resources.Keys.UnmodifiableMetadata));
- } else {
- unmodifiable = null; // Discard since this metadata is going to change.
- }
- }
-
- /**
* Checks if changes in the metadata are allowed. All {@code setFoo(…)} methods in subclasses
* shall invoke this method (directly or indirectly) before to apply any change.
* The current property value should be specified in argument.
@@ -416,7 +300,9 @@ public abstract class ModifiableMetadata extends AbstractMetadata {
*/
protected void checkWritePermission(Object current) throws UnmodifiableMetadataException {
if (state != COMPLETABLE) {
- checkWritePermission();
+ if (state == FINAL) {
+ throw new UnmodifiableMetadataException(Resources.format(Resources.Keys.UnmodifiableMetadata));
+ }
} else if (current != null) {
final MetadataStandard standard;
if (current instanceof AbstractMetadata) {
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
index f1aef1f..f9d6f7c 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
@@ -216,8 +216,8 @@ public class DefaultTelephone extends ISOMetadata implements Telephone {
*
* <p>This field references the same collection than {@link DefaultContact#phones} when possible.
* Note that the link between this collection and {@code DefaultContact.phones} is broken when
- * {@link DefaultContact#freeze()} is invoked, since the {@code Cloner.clone(Object)} method
- * creates a new (unmodifiable) collection.</p>
+ * {@link DefaultContact} is copied by {@link org.apache.sis.metadata.MetadataCopier}, since the
+ * {@code Cloner.clone(Object)} method creates a new (unmodifiable) collection.</p>
*
* @deprecated This field will be removed after we removed the deprecated public methods.
*/
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java
index b4a11d8..ec877ca 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java
@@ -157,23 +157,6 @@ public final strictfp class DefaultCitationTest extends TestUsingFile {
}
/**
- * Tests {@link DefaultCitation#unmodifiable()}.
- *
- * @deprecated To be removed after we removed {@link DefaultCitation#unmodifiable()}.
- */
- @Test
- @Deprecated
- public void testUnmodifiable() {
- final DefaultCitation original = create();
- final DefaultCitation clone = (DefaultCitation) original.unmodifiable(); // This will invoke 'freeze()'.
- assertSame("original.unmodifiable", clone, original.unmodifiable());
- assertSame("clone.unmodifiable", clone, clone.unmodifiable());
- assertEquals("original.state", DefaultCitation.State.EDITABLE, original.state());
- assertEquals("clone.state", DefaultCitation.State.FINAL, clone.state());
- assertCopy(original, clone);
- }
-
- /**
* Verifies that {@code clone} is a copy of {@code original}, sharing same instance of values when possible.
*/
private static void assertCopy(final DefaultCitation original, final DefaultCitation clone) {
diff --git a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
index 255a2bf..5ca0cd2 100644
--- a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
+++ b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
@@ -26,6 +26,7 @@ import org.opengis.metadata.extent.Extent;
import org.opengis.metadata.extent.GeographicExtent;
import org.apache.sis.internal.util.UnmodifiableArrayList;
import org.apache.sis.metadata.ModifiableMetadata;
+import org.apache.sis.metadata.MetadataCopier;
import org.apache.sis.util.ArgumentChecks;
// Branch-dependent imports
@@ -40,7 +41,7 @@ import org.opengis.referencing.gazetteer.ReferenceSystemUsingIdentifiers;
* system than the original location type.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.1
* @since 0.8
* @module
*/
@@ -134,8 +135,8 @@ final class FinalLocationType extends AbstractLocationType implements Serializab
theme = source.getTheme();
identifications = snapshot(source.getIdentifications());
definition = source.getDefinition();
- territoryOfUse = (GeographicExtent) unmodifiable(source.getTerritoryOfUse());
- owner = (Party) unmodifiable(source.getOwner());
+ territoryOfUse = unmodifiable(GeographicExtent.class, source.getTerritoryOfUse());
+ owner = unmodifiable(Party.class, source.getOwner());
parents = snapshot(source.getParents(), rs, existing);
children = snapshot(source.getChildren(), rs, existing);
referenceSystem = rs;
@@ -196,13 +197,18 @@ final class FinalLocationType extends AbstractLocationType implements Serializab
/**
* Returns an unmodifiable copy of the given metadata, if necessary and possible.
+ *
+ * @param <T> compile-time value of the {@code type} argument.
+ * @param type the interface of the metadata object to eventually copy.
+ * @param metadata the metadata object to eventually copy, or {@code null}.
+ * @return an unmodifiable copy of the given metadata object, or {@code null} if the given argument is {@code null}.
*/
- private static Object unmodifiable(final Object metadata) {
+ private static <T> T unmodifiable(final Class<T> type, T metadata) {
if (metadata instanceof ModifiableMetadata) {
- return ((ModifiableMetadata) metadata).unmodifiable();
- } else {
- return metadata;
+ metadata = MetadataCopier.forModifiable(((ModifiableMetadata) metadata).getStandard()).copy(type, metadata);
+ ((ModifiableMetadata) metadata).transition(ModifiableMetadata.State.FINAL);
}
+ return metadata;
}
/**
diff --git a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
index 2a273b7..f74a09b 100644
--- a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
+++ b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
@@ -31,7 +31,7 @@
*
* @author Chris Mattmann (JPL)
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.1
* @since 0.8
* @module
*/
diff --git a/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java b/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
index 461ae41..34a3971 100644
--- a/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
+++ b/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
@@ -33,7 +33,7 @@ import org.opengis.referencing.gazetteer.LocationType;
* Tests {@link AbstractLocationType}, {@link FinalLocationType} and {@link ModifiableLocationType}.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.1
* @since 0.8
* @module
*/
[sis] 02/04: Delete deprecated DistanceUtils class (replaced by
GeodeticCalculator) and remove LatLonPointRadius from public API.
Posted by de...@apache.org.
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 3f0bf11e021a74d6df7db6f55711d599fab8374b
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Sep 12 14:29:44 2019 +0200
Delete deprecated DistanceUtils class (replaced by GeodeticCalculator) and remove LatLonPointRadius from public API.
---
.../org/apache/sis/distance/DistanceUtils.java | 102 ---------------------
.../apache/sis/index/tree}/LatLonPointRadius.java | 61 ++----------
.../java/org/apache/sis/index/tree/QuadTree.java | 1 -
3 files changed, 6 insertions(+), 158 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java b/core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java
deleted file mode 100644
index 4037eeb..0000000
--- a/core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.distance;
-
-import org.apache.sis.geometry.DirectPosition2D;
-
-/**
- * Class to calculate distances on earth surface. Actual calculation code very
- * similar to Apache SIS but refractor to allow use of custom classes.
- *
- * @deprecated Replaced by {@link org.apache.sis.referencing.GeodeticCalculator}.
- * See <a href="https://issues.apache.org/jira/browse/SIS-385">SIS-385</a>.
- */
-@Deprecated
-public final class DistanceUtils {
- private DistanceUtils() {
- }
-
- public static final int EARTH_RADIUS = 6371; // in km
- public static final double HALF_EARTH_CIRCUMFERENCE = 20037.58; // in km
-
- /**
- * Returns a coordinate on the great circle at the specified bearing.
- *
- * @param latitude
- * the latitude of center of circle
- * @param longitude
- * the longitude of center of circle
- * @param d
- * the distance from the center
- * @param bearing
- * the great circle bearing
- * @return a coordinate at the specified bearing
- *
- * @deprecated Replaced by {@link org.apache.sis.referencing.GeodeticCalculator#getEndPoint()}.
- */
- @Deprecated
- public static DirectPosition2D getPointOnGreatCircle(double latitude, double longitude,
- double d, double bearing) {
- double angularDistance = d / EARTH_RADIUS;
-
- double lon1 = Math.toRadians(longitude);
- double lat1 = Math.toRadians(latitude);
-
- double cosLat = Math.cos(lat1);
- double sinLat = Math.sin(lat1);
-
- double sinD = Math.sin(angularDistance);
- double cosD = Math.cos(angularDistance);
- double brng = Math.toRadians(bearing);
-
- double lat2 = Math.asin((sinLat * cosD) + (cosLat * sinD * Math.cos(brng)));
- double lon2 = lon1
- + Math.atan2(Math.sin(brng) * sinD * cosLat, cosD - sinLat
- * Math.sin(lat2));
-
- return new DirectPosition2D(Math.toDegrees(lat2), Math.toDegrees(lon2));
- }
-
- /**
- * Calculates haversine (great circle) distance between two lat/lon
- * coordinates.
- *
- * @param latitude1
- * latitude of first coordinate
- * @param longitude1
- * longitude of first coordinate
- * @param latitude2
- * latitude of second coordinate
- * @param longitude2
- * longitude of second coordinate
- * @return great circle distance between specified lat/lon coordinates
- *
- * @deprecated Replaced by {@link org.apache.sis.referencing.GeodeticCalculator#getGeodesicDistance()}.
- */
- @Deprecated
- public static double getHaversineDistance(double latitude1,
- double longitude1, double latitude2, double longitude2) {
- double longRadian1 = Math.toRadians(longitude1);
- double latRadian1 = Math.toRadians(latitude1);
- double longRadian2 = Math.toRadians(longitude2);
- double latRadian2 = Math.toRadians(latitude2);
- double angularDistance = Math.acos(Math.sin(latRadian1)
- * Math.sin(latRadian2) + Math.cos(latRadian1) * Math.cos(latRadian2)
- * Math.cos(longRadian1 - longRadian2));
- return EARTH_RADIUS * angularDistance;
- }
-}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/distance/LatLonPointRadius.java b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/LatLonPointRadius.java
similarity index 69%
rename from core/sis-referencing/src/main/java/org/apache/sis/distance/LatLonPointRadius.java
rename to storage/sis-storage/src/main/java/org/apache/sis/index/tree/LatLonPointRadius.java
index a58d767..82a0429 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/distance/LatLonPointRadius.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/LatLonPointRadius.java
@@ -15,18 +15,12 @@
* limitations under the License.
*/
-package org.apache.sis.distance;
+package org.apache.sis.index.tree;
-//JDK imports
import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
-
-// GeoAPI import
import org.opengis.geometry.DirectPosition;
-
-//SIS imports
-import org.apache.sis.geometry.DirectPosition2D;
import org.apache.sis.measure.Longitude;
import org.apache.sis.referencing.CommonCRS;
import org.apache.sis.referencing.GeodeticCalculator;
@@ -34,11 +28,9 @@ import org.apache.sis.referencing.GeodeticCalculator;
/**
* Represents a 2D point associated with a radius to enable great circle
* estimation on earth surface.
- *
- * @deprecated Replaced by {@link org.apache.sis.referencing.GeodeticCalculator#createGeodesicCircle2D(double)}.
*/
-@Deprecated
-public class LatLonPointRadius {
+final class LatLonPointRadius {
+ private static final double HALF_EARTH_CIRCUMFERENCE = 20037.58; // in km
private final DirectPosition center;
private final double radius;
@@ -51,61 +43,20 @@ public class LatLonPointRadius {
* @param radius
* the radius of the search region
*/
- public LatLonPointRadius(DirectPosition center, double radius) {
+ LatLonPointRadius(DirectPosition center, double radius) {
this.center = center;
this.radius = radius;
}
/**
- * Gets the circular region approximation on the earth surface using haversine
- * formula.
- *
- * @param numberOfPoints
- * the number of points used to estimate the circular region
- * @return an array of DirectPosition2D representing the points that estimate the
- * circular region
- */
- public DirectPosition2D[] getCircularRegionApproximation(int numberOfPoints) {
- if (radius >= DistanceUtils.HALF_EARTH_CIRCUMFERENCE) {
- DirectPosition2D[] points = new DirectPosition2D[5];
- points[0] = new DirectPosition2D(-180.0, -90.0);
- points[1] = new DirectPosition2D(-180.0, 90.0);
- points[2] = new DirectPosition2D(180.0, 90.0);
- points[3] = new DirectPosition2D(180.0, -90.0);
- points[4] = points[0];
- return points;
- }
- // plus one to add closing point
- DirectPosition2D[] points = new DirectPosition2D[numberOfPoints + 1];
-
- double bearingIncrement = 0;
- if (numberOfPoints > 0) { bearingIncrement = 360/numberOfPoints; }
-
- final GeodeticCalculator calculator = GeodeticCalculator.create(CommonCRS.SPHERE.geographic());
- calculator.setStartGeographicPoint(center.getOrdinate(1), center.getOrdinate(0));
- calculator.setGeodesicDistance(radius);
-
- for (int i = 0; i < numberOfPoints; i++)
- {
- calculator.setStartingAzimuth(i * bearingIncrement);
- DirectPosition p = calculator.getEndPoint();
- points[i] = new DirectPosition2D(p.getOrdinate(1), p.getOrdinate(0));
- }
-
- points[numberOfPoints] = points[0];
-
- return points;
- }
-
- /**
* Calculates the rectangular region enclosing the circular search region.
*
* @param numberOfPoints
* the number of points used to estimate the circular search region
* @return Java Rectangle2D object that bounds the circlar search region
*/
- public Rectangle2D getRectangularRegionApproximation(int numberOfPoints) {
- if (radius >= DistanceUtils.HALF_EARTH_CIRCUMFERENCE) {
+ Rectangle2D getRectangularRegionApproximation(int numberOfPoints) {
+ if (radius >= HALF_EARTH_CIRCUMFERENCE) {
return new Rectangle2D.Double(0.0, 0.0, 360.0, 180.0);
}
int numberOfCrossOvers = 0;
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTree.java b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTree.java
index cfb8e4d..bda627c 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTree.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTree.java
@@ -22,7 +22,6 @@ import java.util.List;
import org.apache.sis.geometry.DirectPosition2D;
import org.apache.sis.geometry.Envelope2D;
-import org.apache.sis.distance.LatLonPointRadius;
import org.apache.sis.referencing.CommonCRS;
import org.apache.sis.referencing.GeodeticCalculator;
[sis] 01/04: Remove the deprecated WarningListeners class and
interface.
Posted by de...@apache.org.
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 25e21ce4111c26c6245aee76758f9d7553d48121
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Sep 12 14:21:00 2019 +0200
Remove the deprecated WarningListeners class and interface.
---
.../java/org/apache/sis/internal/jaxb/Context.java | 14 +-
.../apache/sis/metadata/sql/CachedStatement.java | 25 +-
.../apache/sis/metadata/sql/MetadataFallback.java | 15 -
.../apache/sis/metadata/sql/MetadataSource.java | 77 ++---
.../org/apache/sis/metadata/sql/package-info.java | 2 +-
.../src/main/java/org/apache/sis/xml/Pooled.java | 18 +-
.../src/main/java/org/apache/sis/xml/XML.java | 20 +-
.../java/org/apache/sis/util/logging/Logging.java | 28 +-
.../apache/sis/util/logging/QuietLogRecord.java | 73 ----
.../apache/sis/util/logging/WarningListener.java | 92 ------
.../apache/sis/util/logging/WarningListeners.java | 366 ---------------------
.../org/apache/sis/util/logging/package-info.java | 2 +-
.../sis/internal/storage/io/ChannelFactory.java | 8 +-
.../apache/sis/storage/event/StoreListeners.java | 58 +---
.../org/apache/sis/storage/event/package-info.java | 2 +-
.../internal/storage/xml/stream/StaxDataStore.java | 2 +-
16 files changed, 99 insertions(+), 703 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 a4af9cf..4483329 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
@@ -181,7 +181,7 @@ public final class Context extends MarshalContext {
/**
* The object to inform about warnings, or {@code null} if none.
*/
- private final Filter warningListener;
+ private final Filter logFilter;
/**
* The {@code <gml:*PropertyType>} which is wrapping the {@code <gml:*Type>} object to (un)marshal, or
@@ -222,7 +222,7 @@ public final class Context extends MarshalContext {
* @param versionMetadata the metadata version, or {@code null}.
* @param resolver the resolver in use.
* @param converter the converter in use.
- * @param warningListener the object to inform about warnings.
+ * @param logFilter the object to inform about warnings.
*/
@SuppressWarnings("ThisEscapedInObjectConstruction")
public Context(int bitMasks,
@@ -233,7 +233,7 @@ public final class Context extends MarshalContext {
final Version versionMetadata,
final ReferenceResolver resolver,
final ValueConverter converter,
- final Filter warningListener)
+ final Filter logFilter)
{
if (versionMetadata != null && versionMetadata.compareTo(LegacyNamespaces.VERSION_2014) < 0) {
bitMasks |= LEGACY_METADATA;
@@ -244,7 +244,7 @@ public final class Context extends MarshalContext {
this.versionGML = versionGML;
this.resolver = resolver;
this.converter = converter;
- this.warningListener = warningListener;
+ this.logFilter = logFilter;
this.identifiers = new HashMap<>();
this.identifiedObjects = new IdentityHashMap<>();
if (locale != null) {
@@ -621,10 +621,10 @@ public final class Context extends MarshalContext {
record.setSourceMethodName(method);
record.setLoggerName(Loggers.XML);
if (context != null) {
- final Filter warningListener = context.warningListener;
- if (warningListener != null) {
+ final Filter logFilter = context.logFilter;
+ if (logFilter != null) {
record.setThrown(exception);
- if (!warningListener.isLoggable(record)) {
+ if (!logFilter.isLoggable(record)) {
return;
}
}
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/CachedStatement.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/CachedStatement.java
index 306dd04..6b35eb3 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/CachedStatement.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/CachedStatement.java
@@ -18,13 +18,15 @@ package org.apache.sis.metadata.sql;
import java.util.Locale;
import java.util.logging.Level;
+import java.util.logging.Filter;
+import java.util.logging.Logger;
import java.util.logging.LogRecord;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
+import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.logging.WarningListeners;
import org.apache.sis.internal.system.Loggers;
@@ -51,6 +53,11 @@ import org.apache.sis.internal.system.Loggers;
*/
final class CachedStatement implements AutoCloseable {
/**
+ * Where to log warnings.
+ */
+ static final Logger LOGGER = Logging.getLogger(Loggers.SQL);
+
+ /**
* The interface for which the prepared statement has been created.
*/
final Class<?> type;
@@ -81,23 +88,21 @@ final class CachedStatement implements AutoCloseable {
long expireTime;
/**
- * Where to report the warnings. This is not necessarily a logger, since users can register listeners.
+ * Where to report the warnings before to eventually log them.
*/
- private final WarningListeners<MetadataSource> listeners;
+ private final Filter logFilter;
/**
* Constructs a metadata result from the specified connection.
*
* @param type the GeoAPI interface to implement.
* @param statement the prepared statement.
- * @param listeners where to report the warnings.
+ * @param logFilter where to report the warnings.
*/
- CachedStatement(final Class<?> type, final PreparedStatement statement,
- final WarningListeners<MetadataSource> listeners)
- {
+ CachedStatement(final Class<?> type, final PreparedStatement statement, final Filter logFilter) {
this.type = type;
this.statement = statement;
- this.listeners = listeners;
+ this.logFilter = logFilter;
}
/**
@@ -183,6 +188,8 @@ final class CachedStatement implements AutoCloseable {
record.setSourceClassName(source.getCanonicalName());
record.setSourceMethodName(method);
record.setLoggerName(Loggers.SQL);
- listeners.warning(record);
+ if (logFilter == null || logFilter.isLoggable(record)) {
+ LOGGER.log(record);
+ }
}
}
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataFallback.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataFallback.java
index 87609ce..97f4de9 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataFallback.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataFallback.java
@@ -27,7 +27,6 @@ import org.apache.sis.metadata.iso.citation.DefaultResponsibility;
import org.apache.sis.internal.util.Constants;
import org.apache.sis.util.iso.Types;
import org.apache.sis.util.ArgumentChecks;
-import org.apache.sis.util.logging.WarningListener;
import org.apache.sis.xml.NilReason;
import static java.util.Collections.singleton;
@@ -222,20 +221,6 @@ final class MetadataFallback extends MetadataSource {
* Ignored.
*/
@Override
- public void addWarningListener(WarningListener<? super MetadataSource> listener) {
- }
-
- /**
- * Ignored.
- */
- @Override
- public void removeWarningListener(WarningListener<? super MetadataSource> listener) {
- }
-
- /**
- * Ignored.
- */
- @Override
public void close() {
}
}
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 5e4a6c2..75f15b8 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
@@ -28,8 +28,8 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Locale;
-import java.util.NoSuchElementException;
import java.util.logging.Level;
+import java.util.logging.Filter;
import java.util.logging.LogRecord;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
@@ -65,8 +65,6 @@ import org.apache.sis.internal.util.UnmodifiableArrayList;
import org.apache.sis.util.collection.Containers;
import org.apache.sis.util.collection.CodeListSet;
import org.apache.sis.util.collection.WeakValueHashMap;
-import org.apache.sis.util.logging.WarningListeners;
-import org.apache.sis.util.logging.WarningListener;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.ArgumentChecks;
@@ -110,7 +108,7 @@ import org.apache.sis.util.iso.Types;
*
* @author Touraïvane (IRD)
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 1.0
+ * @version 1.1
* @since 0.8
* @module
*/
@@ -262,11 +260,11 @@ public class MetadataSource implements AutoCloseable {
private final ThreadLocal<LookupInfo> lastUsed;
/**
- * Where to report the warnings. This is not necessarily a logger, since users can register listeners.
+ * Where to report the warnings before to eventually log them.
*
* @see #readColumn(LookupInfo, Method, Dispatcher)
*/
- private final WarningListeners<MetadataSource> listeners;
+ private volatile Filter logFilter;
/**
* Whether at least one {@link CloseTask} is scheduled for execution.
@@ -391,7 +389,6 @@ public class MetadataSource implements AutoCloseable {
this.statements = new CachedStatement[maxStatements - 1];
this.tableColumns = new HashMap<>();
this.pool = new WeakValueHashMap<>(CacheKey.class);
- this.listeners = new WarningListeners<>(this);
this.lastUsed = ThreadLocal.withInitial(LookupInfo::new);
}
@@ -401,9 +398,8 @@ public class MetadataSource implements AutoCloseable {
* but will use their own {@link Connection}.
* This constructor is useful when concurrency is desired.
*
- * <p>The new {@code MetadataSource} initially contains all {@linkplain #addWarningListener warning listeners}
- * declared in the given {@code source}. But listeners added or removed in a {@code MetadataSource} after the
- * construction will not impact the other {@code MetadataSource} instance.</p>
+ * <p>The new {@code MetadataSource} initially contains the {@linkplain #setWarningFilter warning filter}
+ * declared in the given {@code source}.</p>
*
* @param source the source from which to copy the configuration.
*/
@@ -419,7 +415,7 @@ public class MetadataSource implements AutoCloseable {
classloader = source.classloader;
pool = source.pool;
lastUsed = source.lastUsed;
- listeners = new WarningListeners<>(this, source.listeners);
+ logFilter = source.logFilter;
}
/**
@@ -434,7 +430,6 @@ public class MetadataSource implements AutoCloseable {
classloader = getClass().getClassLoader();
pool = null;
lastUsed = null;
- listeners = null;
}
/**
@@ -940,7 +935,7 @@ public class MetadataSource implements AutoCloseable {
final String query = helper.clear().append("SELECT * FROM ")
.appendIdentifier(schema, tableName).append(" WHERE ")
.appendIdentifier(ID_COLUMN).append("=?").toString();
- result = new CachedStatement(type, connection().prepareStatement(query), listeners);
+ result = new CachedStatement(type, connection().prepareStatement(query), logFilter);
}
value = result.getValue(toSearch.identifier, columnName);
isArray = (value instanceof java.sql.Array);
@@ -1073,56 +1068,44 @@ public class MetadataSource implements AutoCloseable {
record.setSourceClassName(source.getCanonicalName());
record.setSourceMethodName(method);
record.setLoggerName(Loggers.SQL);
- listeners.warning(record);
+ final Filter filter = logFilter;
+ if (filter == null || filter.isLoggable(record)) {
+ CachedStatement.LOGGER.log(record);
+ }
}
/**
- * Adds a listener to be notified when a warning occurred while reading from or writing metadata.
+ * Sets a filter to be notified when a warning occurred while reading from or writing metadata.
* When a warning occurs, there is a choice:
*
* <ul>
- * <li>If this metadata source has no warning listener, then the warning is logged at {@link Level#WARNING}.</li>
- * <li>If this metadata source has at least one warning listener, then all listeners are notified
- * and the warning is <strong>not</strong> logged by this metadata source instance.</li>
+ * <li>If this metadata source has no warning filter, or if the filter returns {@code true},
+ * then the warning is logged at {@link Level#WARNING}.</li>
+ * <li>Otherwise the warning is not logged by this metadata source instance.
+ * The filter implementation is free to keep a reference to the given record,
+ * for example in order to display it in a graphical user interface.</li>
* </ul>
*
- * Consider invoking this method in a {@code try} … {@code finally} block if the {@code MetadataSource}
- * lifetime is longer than the listener lifetime, as below:
- *
- * {@preformat java
- * source.addWarningListener(listener);
- * try {
- * // Do some work...
- * } finally {
- * source.removeWarningListener(listener);
- * }
- * }
- *
- * @param listener the listener to add.
- * @throws IllegalArgumentException if the given listener is already registered in this metadata source.
+ * @param filter the filter to set, or {@code null} for removing the filter.
+ * @return the previous filter, or {@code null} if none.
*
- * @deprecated {@code WarningListener} to be replaced by {@link java.util.logging.Filter}.
+ * @since 1.1
*/
- @Deprecated
- public void addWarningListener(final WarningListener<? super MetadataSource> listener)
- throws IllegalArgumentException
- {
- listeners.addWarningListener(listener);
+ public Filter setWarningFilter(final Filter filter) {
+ Filter p = logFilter;
+ logFilter = filter;
+ return p;
}
/**
- * Removes a previously registered listener.
+ * Returns the current warning filter.
*
- * @param listener the listener to remove.
- * @throws NoSuchElementException if the given listener is not registered in this metadata source.
+ * @return the current filter, or {@code null} if none.
*
- * @deprecated {@code WarningListener} to be replaced by {@link java.util.logging.Filter}.
+ * @since 1.1
*/
- @Deprecated
- public void removeWarningListener(final WarningListener<? super MetadataSource> listener)
- throws NoSuchElementException
- {
- listeners.removeWarningListener(listener);
+ public Filter getWarningFilter() {
+ return logFilter;
}
/**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/package-info.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/package-info.java
index 14c2a0f..14e4bc0 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/package-info.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/package-info.java
@@ -42,7 +42,7 @@
*
* @author Touraïvane (IRD)
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 1.0
+ * @version 1.1
*
* @see org.apache.sis.referencing.factory.sql
*
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 4d0bcef..c06fb65 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
@@ -36,7 +36,6 @@ import org.apache.sis.util.Version;
import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.logging.WarningListener;
import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.internal.util.Strings;
import org.apache.sis.internal.jaxb.Context;
@@ -53,7 +52,7 @@ import org.apache.sis.internal.jaxb.TypeRegistration;
*
* @author Martin Desruisseaux (Geomatys)
* @author Cullen Rombach (Image Matters)
- * @version 1.0
+ * @version 1.1
* @since 0.3
* @module
*/
@@ -154,7 +153,7 @@ abstract class Pooled {
/**
* The object to inform about warnings, or {@code null} if none.
*/
- private Filter warningListener;
+ private Filter logFilter;
/**
* The {@link System#nanoTime()} value of the last call to {@link #reset(Pooled)}.
@@ -223,7 +222,7 @@ abstract class Pooled {
resolver = template.resolver;
converter = template.converter;
rootAdapters = template.rootAdapters;
- warningListener = template.warningListener;
+ logFilter = template.logFilter;
resetTime = System.nanoTime();
if (this instanceof Marshaller) {
bitMasks |= Context.MARSHALLING;
@@ -380,11 +379,7 @@ abstract class Pooled {
return;
}
case XML.WARNING_FILTER: {
- warningListener = (Filter) value;
- return;
- }
- case XML.WARNING_LISTENER: {
- warningListener = ((WarningListener<?>) value).asFilter();
+ logFilter = (Filter) value;
return;
}
case TypeRegistration.ROOT_ADAPTERS: {
@@ -425,8 +420,7 @@ abstract class Pooled {
case XML.METADATA_VERSION: return versionMetadata;
case XML.RESOLVER: return resolver;
case XML.CONVERTER: return converter;
- case XML.WARNING_FILTER: return warningListener;
- case XML.WARNING_LISTENER: return null;
+ case XML.WARNING_FILTER: return logFilter;
case XML.LENIENT_UNMARSHAL: return (bitMasks & Context.LENIENT_UNMARSHAL) != 0;
case XML.STRING_SUBSTITUTES: {
int n = 0;
@@ -563,6 +557,6 @@ abstract class Pooled {
*/
final Context begin() {
return new Context(bitMasks | specificBitMasks(), locale, timezone,
- schemas, versionGML, versionMetadata, resolver, converter, warningListener);
+ schemas, versionGML, versionMetadata, resolver, converter, logFilter);
}
}
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 25d5411..1e684bf 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
@@ -46,7 +46,6 @@ import org.apache.sis.util.Static;
import org.apache.sis.util.Version;
import org.apache.sis.util.Workaround;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.logging.WarningListener;
import org.apache.sis.internal.system.Modules;
import org.apache.sis.internal.system.SystemListener;
import org.apache.sis.internal.jaxb.TypeRegistration;
@@ -82,13 +81,13 @@ import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
* <tr><td>{@link #RESOLVER}</td> <td>{@link ReferenceResolver}</td> <td>for replacing {@code xlink} or {@code uuidref} attributes by the actual object to use.</td></tr>
* <tr><td>{@link #CONVERTER}</td> <td>{@link ValueConverter}</td> <td>for controlling the conversion of URL, UUID, Units or similar objects.</td></tr>
* <tr><td>{@link #STRING_SUBSTITUTES}</td> <td>{@code String[]}</td> <td>for specifying which code lists to replace by simpler {@code <gco:CharacterString>} elements.</td></tr>
- * <tr><td>{@link #WARNING_LISTENER}</td> <td>{@link WarningListener}</td> <td>for being notified about non-fatal warnings.</td></tr>
+ * <tr><td>{@link #WARNING_FILTER}</td> <td>{@link Filter}</td> <td>for being notified about non-fatal warnings.</td></tr>
* </table>
*
* @author Cédric Briançon (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @author Cullen Rombach (Image Matters)
- * @version 1.0
+ * @version 1.1
* @since 0.3
* @module
*/
@@ -373,21 +372,6 @@ public final class XML extends Static {
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
- * property is set for this key, then the {@link WarningListener#warningOccured(Object, LogRecord)}
- * 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";
-
- /**
* The pool of marshallers and unmarshallers used by this class.
* The field name uses the uppercase convention because this field is almost constant:
* this field is initially null, then created by {@link #getPool()} when first needed.
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java b/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
index df73cb4..2fc3afd 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
@@ -48,7 +48,7 @@ import org.apache.sis.internal.system.Modules;
* </ul>
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
* @since 0.3
* @module
*/
@@ -261,7 +261,7 @@ public final class Logging extends Static {
if (!classname.equals(classe)) {
continue;
}
- } else if (!WarningListeners.isPublic(element)) {
+ } else if (!isPublic(element)) {
continue;
}
/*
@@ -304,6 +304,30 @@ public final class Logging extends Static {
}
/**
+ * Returns {@code true} if the given stack trace element describes a method considered part of public API.
+ * This method is invoked in order to infer the class and method names to declare in a {@link LogRecord}.
+ * We do not document this feature in public Javadoc because it is based on heuristic rules that may change.
+ *
+ * <p>The current implementation compares the class name against a hard-coded list of classes to hide.
+ * This implementation may change in any future SIS version.</p>
+ *
+ * @param e a stack trace element.
+ * @return {@code true} if the class and method specified by the given element can be considered public API.
+ */
+ private static boolean isPublic(final StackTraceElement e) {
+ final String classname = e.getClassName();
+ if (classname.startsWith("java") || classname.startsWith(Modules.INTERNAL_CLASSNAME_PREFIX) ||
+ classname.indexOf('$') >= 0 || e.getMethodName().indexOf('$') >= 0)
+ {
+ return false;
+ }
+ if (classname.startsWith(Modules.CLASSNAME_PREFIX + "util.logging.")) {
+ return classname.endsWith("Test"); // Consider JUnit tests as public.
+ }
+ return true; // TODO: with StackWalker on JDK9, check if the class is public.
+ }
+
+ /**
* Invoked when an unexpected error occurred. This method logs a message at {@link Level#WARNING}
* to the specified logger. The originating class name and method name can optionally be specified.
* If any of them is {@code null}, then it will be inferred from the error stack trace as described below.
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/QuietLogRecord.java b/core/sis-utility/src/main/java/org/apache/sis/util/logging/QuietLogRecord.java
deleted file mode 100644
index d10ff94..0000000
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/QuietLogRecord.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.util.logging;
-
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-
-/**
- * A log record to be logged without stack trace, unless the user specified it explicitly.
- *
- * @author Martin Desruisseaux (Geomatys)
- * @version 0.8
- * @since 0.3
- * @module
- *
- * @deprecated Moved to {@link org.apache.sis.storage.event.QuietLogRecord}.
- */
-@Deprecated
-final class QuietLogRecord extends LogRecord {
- /**
- * For cross-version compatibility.
- */
- private static final long serialVersionUID = -8225936118310305206L;
-
- /**
- * {@code true} if the user invoked {@link #setThrown(Throwable)}.
- * In such case, {@link #clearThrown()} will not reset the throwable to null.
- */
- private boolean explicitThrown;
-
- /**
- * Creates a new log record for the given message and exception.
- */
- QuietLogRecord(final Level level, final String message, final Exception exception) {
- super(level, message);
- super.setThrown(exception);
- }
-
- /**
- * Sets the throwable to the given value. The given throwable will not be cleared
- * when the record will be logged.
- */
- @Override
- public void setThrown(final Throwable thrown) {
- explicitThrown = true;
- super.setThrown(thrown);
- }
-
- /**
- * Clears the throwable if it has not been explicit set by the user.
- * Otherwise do nothing.
- */
- void clearThrown() {
- if (!explicitThrown) {
- super.setThrown(null);
- }
- }
-}
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
deleted file mode 100644
index 642e773..0000000
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-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;
-
-
-/**
- * Intercepts non-fatal error messages logged by {@link org.apache.sis.storage.DataStore} or other SIS objects.
- * Warnings are encapsulated in {@link LogRecord} objects and logged at {@link Level#WARNING} if the emitter does not
- * have registered any {@code WarningListener}. This listener allows applications to intercept warning records for
- * displaying them in a dialog (or any other action that the application may choose) instead than logging them.
- *
- * <div class="note"><b>Comparison with alternative approaches:</b>
- * it is also possible to listen to login events by registering a custom {@link java.util.logging.Handler} to the logger.
- * But {@code Handler} instances are registered on a per-logger basis and receive all messages sent to that logger
- * regardless their emitter. By contrast, {@code WarningListener} instances are registered on a per-{@code DataStore}
- * basis (or any other emitter) and receive all messages sent by that emitter regardless the destination logger.
- * The emitter is part of the information given to the {@link #warningOccured(Object, LogRecord)} method,
- * in addition to the log record.</div>
- *
- * @author Martin Desruisseaux (Geomatys)
- * @version 1.0
- *
- * @param <S> the base type of objects that emit warnings (the <cite>source</cite>).
- *
- * @see WarningListeners
- * @see org.apache.sis.storage.event.StoreListener
- *
- * @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.
- * This is typically, but not necessarily, the class having the name returned by
- * {@link LogRecord#getSourceClassName()}, or one of its parent classes.
- *
- * @return the base type of objects that emit warnings (the <cite>source</cite>).
- */
- Class<S> getSourceClass();
-
- /**
- * Reports the occurrence of a non-fatal error. The emitter process (often a
- * {@link org.apache.sis.storage.DataStore} in the midst of a reading process)
- * will continue following the call to this method.
- *
- * <p>The {@code LogRecord} provides the warning {@linkplain LogRecord#getMessage() message} together with
- * programmatic information like the {@linkplain LogRecord#getSourceClassName() source class name} and
- * {@linkplain LogRecord#getSourceMethodName() method name} where the warning occurred. The log record
- * may optionally contains the exception which has been {@linkplain LogRecord#getThrown() thrown}.</p>
- *
- * <p>Applications may choose to ignore the warning, display a dialog or take any other action they choose.
- * Applications do not need to log the warning, since logging will be done automatically if the emitter has
- * no registered warning listeners.</p>
- *
- * @param source the object that emitted a warning, or {@code null} if not available.
- * @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
deleted file mode 100644
index 1e4717e..0000000
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.util.logging;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import java.util.logging.Level;
-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.Exceptions;
-import org.apache.sis.util.ArgumentChecks;
-import org.apache.sis.util.resources.Errors;
-import org.apache.sis.internal.system.Modules;
-import org.apache.sis.internal.util.UnmodifiableArrayList;
-
-
-/**
- * Holds a list of {@link WarningListener} instances and provides convenience methods for emitting warnings.
- * This is a helper class for {@link org.apache.sis.storage.DataStore} implementations or for other services
- * susceptible to emit warnings.
- * Observers can {@linkplain #addWarningListener can add listeners} for being notified about warnings, and
- * processes can invoke one of the {@code warning(…)} methods for emitting warnings. All warnings are given
- * to the listeners as {@link LogRecord} instances (this allows localizable messages and additional information
- * like {@linkplain LogRecord#getMillis() timestamp} and {@linkplain LogRecord#getThrown() stack trace}).
- * This {@code WarningListeners} class provides convenience methods like {@link #warning(String, Exception)},
- * which builds {@code LogRecord} from an exception or from a string, but all those {@code warning(…)} methods
- * ultimately delegate to {@link #warning(LogRecord)}, thus providing a single point that subclasses can override.
- * When a warning is emitted, the default behavior is:
- *
- * <ul>
- * <li>If at least one {@link WarningListener} is registered,
- * then all listeners are notified and the warning is <strong>not</strong> logged.
- * <li>Otherwise if the value returned by {@link LogRecord#getLoggerName()} is non-null,
- * then the warning will be logged to that named logger.</li>
- * <li>Otherwise the warning is logged to the logger returned by {@link #getLogger()}.</li>
- * </ul>
- *
- * <div class="section">Thread safety</div>
- * The same {@code WarningListeners} instance can be safely used by many threads without synchronization
- * on the part of the caller. Subclasses should make sure that any overridden methods remain safe to call
- * from multiple threads.
- *
- * @author Martin Desruisseaux (Geomatys)
- * @version 1.0
- *
- * @param <S> the type of the source of warnings.
- *
- * @see WarningListener
- * @see org.apache.sis.storage.DataStore#listeners
- *
- * @since 0.3
- * @module
- *
- * @deprecated Replaced by {@link org.apache.sis.storage.event.StoreListeners}.
- */
-@Deprecated
-public class WarningListeners<S> implements Localized {
- /**
- * The declared source of warnings. This is not necessarily the real source,
- * but this is the source that the implementer wants to declare as public API.
- */
- private final S source;
-
- /**
- * The listeners, or {@code null} if none. This is a <cite>copy on write</cite> array:
- * no elements are modified once the array have been created.
- */
- private WarningListener<? super S>[] listeners;
-
- /**
- * 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}.
- *
- * @param source the declared source of warnings. This is not necessarily the real source,
- * but this is the source that the implementer wants to declare as public API.
- */
- public WarningListeners(final S source) {
- this.source = source;
- }
-
- /**
- * Creates a new instance initialized with the same listeners than the given instance.
- * This constructor is useful when a {@code DataStore} or other data producer needs to
- * be duplicated for concurrency reasons.
- *
- * @param source the declared source of warnings. This is not necessarily the real source,
- * but this is the source that the implementer wants to declare as public API.
- * @param other the existing instance from which to copy the listeners, or {@code null} if none.
- *
- * @since 0.8
- */
- public WarningListeners(final S source, final WarningListeners<? super S> other) {
- this(source);
- if (other != null) {
- listeners = other.listeners;
- }
- }
-
- /**
- * Returns the source declared source of warnings.
- * This value is specified at construction time.
- *
- * @return the declared source of warnings.
- *
- * @since 0.8
- */
- public S getSource() {
- return source;
- }
-
- /**
- * The locale to use for formatting warning messages, or {@code null} for the default locale.
- * If the {@code source} object given to the constructor implements the {@link Localized} interface,
- * then this method delegates to its {@code getLocale()} method. Otherwise this method returns {@code null}.
- */
- @Override
- public Locale getLocale() {
- return (source instanceof Localized) ? ((Localized) source).getLocale() : null;
- }
-
- /**
- * Returns the logger where to send the warnings when no other destination is specified.
- * This logger is used when:
- *
- * <ul>
- * <li>no listener has been {@linkplain #addWarningListener registered}, and</li>
- * <li>the {@code LogRecord} does not {@linkplain LogRecord#getLoggerName() specify a logger}.</li>
- * </ul>
- *
- * The default implementation infers a logger name from the package name of the {@code source} object.
- * Subclasses should override this method if they can provide a more determinist logger instance,
- * typically from a static final constant.
- *
- * @return the logger where to send the warnings when there is no other destination.
- */
- public Logger getLogger() {
- return Logging.getLogger(source.getClass());
- }
-
- /**
- * Reports a warning represented by the given log record. The default implementation forwards
- * the given record to <strong>one</strong> of the following destinations, in preference order:
- *
- * <ol>
- * <li><code>{@linkplain WarningListener#warningOccured WarningListener.warningOccured}(source, record)</code>
- * on all {@linkplain #addWarningListener registered listeners} it at least one such listener exists.</li>
- * <li><code>{@linkplain Logging#getLogger(String) Logging.getLogger}(record.{@linkplain LogRecord#getLoggerName
- * getLoggerName()}).{@linkplain Logger#log(LogRecord) log}(record)</code> if the logger name is non-null.</li>
- * <li><code>{@linkplain #getLogger()}.{@linkplain Logger#log(LogRecord) log}(record)</code> otherwise.</li>
- * </ol>
- *
- * @param record the warning as a log record.
- */
- public void warning(final LogRecord record) {
- final WarningListener<? super S>[] current;
- synchronized (this) {
- current = listeners;
- }
- if (current != null) {
- for (final WarningListener<? super S> listener : current) {
- listener.warningOccured(source, record);
- }
- } else {
- final String name = record.getLoggerName();
- final Logger logger;
- if (name != null) {
- logger = Logging.getLogger(name);
- } else {
- logger = getLogger();
- record.setLoggerName(logger.getName());
- }
- if (record instanceof QuietLogRecord) {
- ((QuietLogRecord) record).clearThrown();
- }
- logger.log(record);
- }
- }
-
- /**
- * Reports a warning represented by the given message and exception.
- * At least one of {@code message} and {@code exception} shall be non-null.
- * If both are non-null, then the exception message will be concatenated after the given message.
- * If the exception is non-null, its stack trace will be omitted at logging time for avoiding to
- * pollute console output (keeping in mind that this method should be invoked only for non-fatal
- * warnings). See {@linkplain #warning(Level, String, Exception) below} for more explanation.
- *
- * <p>This method is a shortcut for <code>{@linkplain #warning(Level, String, Exception)
- * warning}({@linkplain Level#WARNING}, message, exception)</code>.
- *
- * @param message the message to log, or {@code null} if none.
- * @param exception the exception to log, or {@code null} if none.
- */
- public void warning(String message, Exception exception) {
- warning(Level.WARNING, message, exception);
- }
-
- /**
- * Reports a warning at the given level represented by the given message and exception.
- * At least one of {@code message} and {@code exception} shall be non-null.
- * If both are non-null, then the exception message will be concatenated after the given message.
- *
- * <div class="section">Stack trace omission</div>
- * If there is no registered listener, then the {@link #warning(LogRecord)} method will send the record to the
- * {@linkplain #getLogger() logger}, but <em>without</em> the stack trace. This is done that way because stack
- * traces consume lot of space in the logging files, while being considered implementation details in the context
- * of {@code WarningListeners} (on the assumption that the logging message provides sufficient information).
- * If the stack trace is desired, then users can either:
- * <ul>
- * <li>invoke {@code warning(LogRecord)} directly, or</li>
- * <li>override {@code warning(LogRecord)} and invoke {@link LogRecord#setThrown(Throwable)} explicitly, or</li>
- * <li>register a listener which will log the record itself.</li>
- * </ul>
- *
- * @param level the warning level.
- * @param message the message to log, or {@code null} if none.
- * @param exception the exception to log, or {@code null} if none.
- */
- public void warning(final Level level, String message, final Exception exception) {
- ArgumentChecks.ensureNonNull("level", level);
- final LogRecord record;
- final StackTraceElement[] trace;
- if (exception != null) {
- trace = exception.getStackTrace();
- message = Exceptions.formatChainedMessages(getLocale(), message, exception);
- if (message == null) {
- message = exception.toString();
- }
- record = new QuietLogRecord(level, message, exception);
- } else {
- ArgumentChecks.ensureNonEmpty("message", message);
- trace = Thread.currentThread().getStackTrace();
- record = new LogRecord(level, message);
- }
- for (final StackTraceElement e : trace) {
- if (isPublic(e)) {
- record.setSourceClassName(e.getClassName());
- record.setSourceMethodName(e.getMethodName());
- break;
- }
- }
- warning(record);
- }
-
- /**
- * Returns {@code true} if the given stack trace element describes a method considered part of public API.
- * This method is invoked in order to infer the class and method names to declare in a {@link LogRecord}.
- * We do not document this feature in public Javadoc because it is based on heuristic rules that may change.
- *
- * <p>The current implementation compares the class name against a hard-coded list of classes to hide.
- * This implementation may change in any future SIS version.</p>
- *
- * @param e a stack trace element.
- * @return {@code true} if the class and method specified by the given element can be considered public API.
- */
- static boolean isPublic(final StackTraceElement e) {
- final String classname = e.getClassName();
- if (classname.startsWith("java") || classname.startsWith(Modules.INTERNAL_CLASSNAME_PREFIX) ||
- classname.indexOf('$') >= 0 || e.getMethodName().indexOf('$') >= 0)
- {
- return false;
- }
- if (classname.startsWith(Modules.CLASSNAME_PREFIX + "util.logging.")) {
- return classname.endsWith("Test"); // Consider JUnit tests as public.
- }
- return true; // TODO: with StackWalker on JDK9, check if the class is public.
- }
-
- /**
- * Adds a listener to be notified when a warning occurred.
- * When a warning occurs, there is a choice:
- *
- * <ul>
- * <li>If this object has no warning listener, then the warning is logged at
- * {@link java.util.logging.Level#WARNING}.</li>
- * <li>If this object has at least one warning listener, then all listeners are notified
- * and the warning is <strong>not</strong> logged by this object.</li>
- * </ul>
- *
- * @param listener the listener to add.
- * @throws IllegalArgumentException if the given listener is already registered.
- */
- public synchronized void addWarningListener(final WarningListener<? super S> listener)
- throws IllegalArgumentException
- {
- ArgumentChecks.ensureNonNull("listener", listener);
- final WarningListener<? super S>[] current = listeners;
- final int length = (current != null) ? current.length : 0;
-
- @SuppressWarnings({"unchecked", "rawtypes"}) // Generic array creation.
- final WarningListener<? super S>[] copy = new WarningListener[length + 1];
- for (int i=0; i<length; i++) {
- final WarningListener<? super S> c = current[i];
- if (c == listener) {
- throw new IllegalArgumentException(Errors.format(Errors.Keys.ElementAlreadyPresent_1, listener));
- }
- copy[i] = c;
- }
- copy[length] = listener;
- listeners = copy;
- }
-
- /**
- * Removes a previously registered listener.
- *
- * @param listener the listener to remove.
- * @throws NoSuchElementException if the given listener is not registered.
- */
- public synchronized void removeWarningListener(final WarningListener<? super S> listener)
- throws NoSuchElementException
- {
- ArgumentChecks.ensureNonNull("listener", listener);
- final WarningListener<? super S>[] current = listeners;
- if (current != null) {
- for (int i=0; i<current.length; i++) {
- if (current[i] == listener) {
- if (current.length == 1) {
- listeners = null;
- } else {
- @SuppressWarnings({"unchecked", "rawtypes"}) // Generic array creation.
- final WarningListener<? super S>[] copy = new WarningListener[current.length - 1];
- System.arraycopy(current, 0, copy, 0, i);
- System.arraycopy(current, i+1, copy, i, copy.length - i);
- listeners = copy;
- }
- return;
- }
- }
- }
- throw new NoSuchElementException(Errors.format(Errors.Keys.ElementNotFound_1, listener));
- }
-
- /**
- * Returns all registered warning listeners, or an empty list if none.
- * This method returns an unmodifiable snapshot of the listener list at the time this method is invoked.
- *
- * @return immutable list of all registered warning listeners.
- *
- * @since 0.8
- */
- public List<WarningListener<? super S>> getListeners() {
- final WarningListener<? super S>[] current;
- synchronized (this) {
- current = listeners;
- }
- return (current != null) ? UnmodifiableArrayList.wrap(current) : Collections.emptyList();
- }
-
-}
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/package-info.java b/core/sis-utility/src/main/java/org/apache/sis/util/logging/package-info.java
index c5d651e..31d6ac6 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/package-info.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/logging/package-info.java
@@ -50,7 +50,7 @@
* order to give SIS a chance to redirect log events to an other logging framework.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
*
* @see <a href="http://download.oracle.com/javase/6/docs/technotes/guides/logging/overview.html">Java Logging Overview</a>
*
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelFactory.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelFactory.java
index 0f4dc55..a7aedfb 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelFactory.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelFactory.java
@@ -291,7 +291,7 @@ public abstract class ChannelFactory {
* it is caller's responsibility to wrap the stream in a {@link java.io.BufferedInputStream} if desired.
*
* @param filename data store name to report in case of failure.
- * @param listeners set of registered {@code WarningListener}s for the data store, or {@code null} if none.
+ * @param listeners set of registered {@code StoreListener}s for the data store, or {@code null} if none.
* @return the input stream.
* @throws DataStoreException if the channel is read-once.
* @throws IOException if the input stream or its underlying byte channel can not be created.
@@ -307,7 +307,7 @@ public abstract class ChannelFactory {
* it is caller's responsibility to wrap the stream in a {@link java.io.BufferedOutputStream} if desired.
*
* @param filename data store name to report in case of failure.
- * @param listeners set of registered {@code WarningListener}s for the data store, or {@code null} if none.
+ * @param listeners set of registered {@code StoreListener}s for the data store, or {@code null} if none.
* @return the output stream.
* @throws DataStoreException if the channel is write-once.
* @throws IOException if the output stream or its underlying byte channel can not be created.
@@ -324,7 +324,7 @@ public abstract class ChannelFactory {
* this method throws an exception.
*
* @param filename data store name to report in case of failure.
- * @param listeners set of registered {@code WarningListener}s for the data store, or {@code null} if none.
+ * @param listeners set of registered {@code StoreListener}s for the data store, or {@code null} if none.
* @return the channel for the given input.
* @throws DataStoreException if the channel is read-once.
* @throws IOException if an error occurred while opening the channel.
@@ -338,7 +338,7 @@ public abstract class ChannelFactory {
* this method throws an exception.
*
* @param filename data store name to report in case of failure.
- * @param listeners set of registered {@code WarningListener}s for the data store, or {@code null} if none.
+ * @param listeners set of registered {@code StoreListener}s for the data store, or {@code null} if none.
* @return the channel for the given output.
* @throws DataStoreException if the channel is write-once.
* @throws IOException if an error occurred while opening the channel.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java
index 1b70be5..2e18ac1 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java
@@ -29,7 +29,6 @@ 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.internal.system.Modules;
import org.apache.sis.internal.storage.StoreResource;
import org.apache.sis.storage.DataStoreProvider;
@@ -72,11 +71,11 @@ import org.apache.sis.storage.Resource;
* from multiple threads.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
* @since 1.0
* @module
*/
-public class StoreListeners extends org.apache.sis.util.logging.WarningListeners implements Localized {
+public class StoreListeners implements Localized {
/**
* Parent manager to notify in addition to this manager.
*/
@@ -210,7 +209,6 @@ public class StoreListeners extends org.apache.sis.util.logging.WarningListeners
* @param source the source of events. Can not be null.
*/
public StoreListeners(final StoreListeners parent, Resource source) {
- super(source);
/*
* Undocumented feature for allowing subclass to specify `this` as the source resource.
* This is used as a convenience by AbstractResource internal class. We need this hack
@@ -230,7 +228,6 @@ public class StoreListeners extends org.apache.sis.util.logging.WarningListeners
*
* @return the source of events.
*/
- @Override
public Resource getSource() {
return source;
}
@@ -319,7 +316,7 @@ public class StoreListeners extends org.apache.sis.util.logging.WarningListeners
*
* @return the logger where to send the warnings when there is no other destination.
*/
- private Logger logger() {
+ private Logger getLogger() {
Resource src = source;
final DataStore ds = getDataStore(this);
if (ds != null) {
@@ -378,7 +375,6 @@ public class StoreListeners extends org.apache.sis.util.logging.WarningListeners
* @param message the warning message to report, or {@code null} if none.
* @param exception the exception to report, or {@code null} if none.
*/
- @Override
public void warning(String message, Exception exception) {
warning(Level.WARNING, message, exception);
}
@@ -404,7 +400,6 @@ public class StoreListeners extends org.apache.sis.util.logging.WarningListeners
* @param message the message to log, or {@code null} if none.
* @param exception the exception to log, or {@code null} if none.
*/
- @Override
public void warning(final Level level, String message, final Exception exception) {
ArgumentChecks.ensureNonNull("level", level);
final LogRecord record;
@@ -476,7 +471,6 @@ public class StoreListeners extends org.apache.sis.util.logging.WarningListeners
*
* @param description warning details provided as a log record.
*/
- @Override
@SuppressWarnings("unchecked")
public void warning(final LogRecord description) {
if (!fire(new WarningEvent(source, description), WarningEvent.class)) {
@@ -485,7 +479,7 @@ public class StoreListeners extends org.apache.sis.util.logging.WarningListeners
if (name != null) {
logger = Logging.getLogger(name);
} else {
- logger = logger();
+ logger = getLogger();
description.setLoggerName(logger.getName());
}
if (description instanceof QuietLogRecord) {
@@ -616,48 +610,4 @@ public class StoreListeners extends org.apache.sis.util.logging.WarningListeners
} while (m != null);
return false;
}
-
-
- /**
- * @deprecated Replaced by {@code addListener(listener, WarningEvent.class)}.
- */
- @Override
- @Deprecated
- public void addWarningListener(final WarningListener listener) {
- addListener(new Legacy(listener), WarningEvent.class);
- }
-
- /**
- * @deprecated Replaced by {@code removeListener(listener, WarningEvent.class)}.
- */
- @Override
- @Deprecated
- public void removeWarningListener(final WarningListener listener) {
- for (ForType<?> e = listeners; e != null; e = e.next) {
- if (e.type.equals(WarningEvent.class)) {
- StoreListener<?>[] list = e.listeners;
- if (list != null) {
- for (final StoreListener<?> c : list) {
- if (c instanceof Legacy && ((Legacy) c).delegate == listener) {
- removeListener((StoreListener<WarningEvent>) c, WarningEvent.class);
- break;
- }
- }
- }
- }
- }
- }
-
- @Deprecated
- private static final class Legacy implements StoreListener<WarningEvent> {
- final WarningListener<? super Resource> delegate;
-
- Legacy(final WarningListener<? super Resource> delegate) {
- this.delegate = delegate;
- }
-
- @Override public void eventOccured(WarningEvent event) {
- delegate.warningOccured(event.getSource(), event.getDescription());
- }
- }
}
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/event/package-info.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/event/package-info.java
index 5745fca..c9a46b7 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/event/package-info.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/event/package-info.java
@@ -34,7 +34,7 @@
* to a specific kind of event}.
*
* @author Johann Sorel (Geomatys)
- * @since 1.0
+ * @since 1.1
* @version 1.0
* @module
*/
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 9dc4462..8ba40a4 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
@@ -298,7 +298,7 @@ public abstract class StaxDataStore extends URIDataStore {
/**
* Returns configuration associated to the given key, or {@code null} if none.
*
- * @param key one of {@link XML#LOCALE}, {@link XML#TIMEZONE} or {@link XML#WARNING_LISTENER}.
+ * @param key one of {@link XML#LOCALE}, {@link XML#TIMEZONE} or {@link XML#WARNING_FILTER}.
* @return the configuration for the given key, or {@code null} if none or if the given key is invalid.
*/
@Override
[sis] 03/04: Bug fix: MetadataCopier.copy(type,
metadata) should accept a type which is a super-type of the
interface implemented by the given metadata instance.
Posted by de...@apache.org.
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 7762360e27918b97b329911f6c16588133c83a69
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Sep 12 16:48:43 2019 +0200
Bug fix: MetadataCopier.copy(type, metadata) should accept a type which is a super-type of the interface implemented by the given metadata instance.
---
.../java/org/apache/sis/internal/metadata/Resources.java | 2 +-
.../org/apache/sis/internal/metadata/Resources.properties | 2 +-
.../apache/sis/internal/metadata/Resources_fr.properties | 2 +-
.../main/java/org/apache/sis/metadata/MetadataCopier.java | 2 +-
.../java/org/apache/sis/metadata/MetadataCopierTest.java | 15 +++++++++++++++
.../org/apache/sis/metadata/MetadataStandardTest.java | 4 +++-
6 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.java
index f2badce..660a727 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.java
@@ -81,7 +81,7 @@ public final class Resources extends IndexedResourceBundle {
public static final short ElementsOmitted_1 = 4;
/**
- * `{1}` is an implementation class. Specify the `{0}` interface instead.
+ * Illegal class `{1}`. Specify the `{0}` interface instead.
*/
public static final short ExpectedInterface_2 = 5;
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.properties b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.properties
index 0e80c25..8ab6976 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.properties
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.properties
@@ -23,5 +23,5 @@ BoxCrossesAntiMeridian = Bounding box crosses the antimeridian.
ConnectionAlreadyInitialized_1 = Connection to \u201c{0}\u201d database is already initialized.
ElementAlreadyInitialized_1 = This metadata element is already initialized with value \u201c{0}\u201d.
ElementsOmitted_1 = \u2026 {0} elements omitted \u2026
-ExpectedInterface_2 = `{1}` is an implementation class. Specify the `{0}` interface instead.
+ExpectedInterface_2 = Illegal class `{1}`. Specify the `{0}` interface instead.
UnmodifiableMetadata = This metadata is not modifiable.
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources_fr.properties b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources_fr.properties
index c8eefe5..8359aaa 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources_fr.properties
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources_fr.properties
@@ -28,5 +28,5 @@ BoxCrossesAntiMeridian = La bo\u00eete englobante traverse l\u2019ant
ConnectionAlreadyInitialized_1 = La connexion \u00e0 la base de donn\u00e9es \u00ab\u202f{0}\u202f\u00bb est d\u00e9j\u00e0 initialis\u00e9e.
ElementAlreadyInitialized_1 = Cet \u00e9l\u00e9ment de m\u00e9ta-donn\u00e9e est d\u00e9j\u00e0 initialis\u00e9 avec la valeur \u00ab\u202f{0}\u202f\u00bb.
ElementsOmitted_1 = \u2026 {0} \u00e9l\u00e9ments omis \u2026
-ExpectedInterface_2 = `{1}` est une classe d\u2019impl\u00e9mentation. Sp\u00e9cifiez l\u2019interface `{0}` \u00e0 la place.
+ExpectedInterface_2 = La classe `{1}` est ill\u00e9gale. Sp\u00e9cifiez l\u2019interface `{0}` \u00e0 la place.
UnmodifiableMetadata = Cette m\u00e9ta-donn\u00e9e n\u2019est pas modifiable.
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataCopier.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataCopier.java
index a99df1a..1e34396 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataCopier.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataCopier.java
@@ -155,7 +155,7 @@ public class MetadataCopier extends MetadataVisitor<Object> {
ArgumentChecks.ensureNonNull("type", type);
if (metadata instanceof AbstractMetadata) {
final Class<?> interfaceType = ((AbstractMetadata) metadata).getInterface();
- if (type != interfaceType) {
+ if (!type.isAssignableFrom(interfaceType)) {
/*
* In case the user specified an implementation despite the documentation warning.
* We could replace `type` by `interfaceType` and it would work most of the time,
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataCopierTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataCopierTest.java
index 7765a19..5c2634c 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataCopierTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataCopierTest.java
@@ -17,8 +17,10 @@
package org.apache.sis.metadata;
import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.extent.GeographicExtent;
import org.apache.sis.metadata.iso.citation.DefaultCitation;
import org.apache.sis.metadata.iso.citation.HardCodedCitations;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicDescription;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
@@ -70,6 +72,19 @@ public final strictfp class MetadataCopierTest extends TestCase {
}
/**
+ * Tests {@link MetadataCopier#copy(Class, Object)} when the given type is a parent
+ * of the interface implemented by the given argument.
+ */
+ @Test
+ public void testCopyWithSuperType() {
+ final MetadataCopier copier = new MetadataCopier(MetadataStandard.ISO_19115);
+ final DefaultGeographicDescription original = new DefaultGeographicDescription("Some area.");
+ final GeographicExtent copy = copier.copy(GeographicExtent.class, original);
+ assertNotSame(original, copy);
+ assertEquals (original, copy);
+ }
+
+ /**
* Tests {@link MetadataCopier#copy(Class, Object)} with an implementation class specified instead of an interface.
*/
@Test
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
index fa046f4..3990f1b 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.HashSet;
import org.opengis.metadata.citation.Citation;
import org.opengis.metadata.quality.Completeness;
+import org.opengis.metadata.extent.GeographicExtent;
import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.crs.GeographicCRS;
import org.opengis.coverage.grid.RectifiedGrid;
@@ -58,7 +59,7 @@ import static org.apache.sis.test.TestUtilities.getSingleton;
* </ul>
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
* @since 0.3
* @module
*/
@@ -133,6 +134,7 @@ public final strictfp class MetadataStandardTest extends TestCase {
assertEquals("getInterface(Citation)", Citation.class, getInterface(Citation.class));
assertEquals("getInterface(DefaultCitation)", Citation.class, getInterface(DefaultCitation.class));
assertEquals("getInterface(AbstractCompleteness)", Completeness.class, getInterface(AbstractCompleteness.class));
+ assertEquals("getInterface(GeographicExtent)", GeographicExtent.class, getInterface(GeographicExtent.class));
standard = MetadataStandard.ISO_19111;
assertEquals("getInterface(Citation)", Citation.class, getInterface(Citation.class));