sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1479947 - in /sis/branches/JDK7: sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/ sis...
Date Tue, 07 May 2013 15:44:18 GMT
Author: desruisseaux
Date: Tue May  7 15:44:15 2013
New Revision: 1479947

URL: http://svn.apache.org/r1479947
Log:
Added warning messages when a property is discarded, and test cases.

Added:
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
  (with props)
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java
  (with props)
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java
  (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/WarningListeners.java
  (with props)
Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestCase.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java?rev=1479947&r1=1479946&r2=1479947&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -25,6 +25,8 @@ import org.opengis.metadata.identificati
 // import org.apache.sis.internal.jaxb.gco.GO_Distance; // TODO
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.measure.ValueRange;
+import org.apache.sis.util.resources.Messages;
+import org.apache.sis.internal.util.WarningListeners;
 
 
 /**
@@ -122,6 +124,14 @@ public class DefaultResolution extends I
     }
 
     /**
+     * Invoked when setting a property discards the other one.
+     */
+    private static void warning(final String method, final String oldName, final String newName)
{
+        WarningListeners.message(null, null, DefaultResolution.class, method,
+                Messages.Keys.DiscardedExclusiveProperty_2, oldName, newName);
+    }
+
+    /**
      * Returns the level of detail expressed as the scale of a comparable hardcopy map or
chart.
      * Only one of {@linkplain #getEquivalentScale() equivalent scale} and
      * {@linkplain #getDistance() ground sample distance} may be provided.
@@ -143,9 +153,13 @@ public class DefaultResolution extends I
      */
     public void setEquivalentScale(final RepresentativeFraction newValue) {
         checkWritePermission();
-        if (newValue != null || !isDistance()) {
-            scaleOrDistance = newValue;
+        if (isDistance()) {
+            if (newValue == null) {
+                return; // Do not erase the other property.
+            }
+            warning("setEquivalentScale", "distance", "equivalentScale");
         }
+        scaleOrDistance = newValue;
     }
 
     /**
@@ -168,8 +182,12 @@ public class DefaultResolution extends I
      */
     public void setDistance(final Double newValue) {
         checkWritePermission();
-        if (newValue != null || isDistance()) {
-            scaleOrDistance = newValue;
+        if (scaleOrDistance != null && !isDistance()) {
+            if (newValue == null) {
+                return; // Do not erase the other property.
+            }
+            warning("setDistance", "equivalentScale", "distance");
         }
+        scaleOrDistance = newValue;
     }
 }

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java?rev=1479947&r1=1479946&r2=1479947&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -25,7 +25,9 @@ import org.opengis.feature.type.FeatureT
 import org.opengis.metadata.maintenance.ScopeDescription;
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.internal.metadata.ExcludedSet;
+import org.apache.sis.internal.util.WarningListeners;
 import org.apache.sis.util.collection.CheckedContainer;
+import org.apache.sis.util.resources.Messages;
 
 import static org.apache.sis.internal.jaxb.Context.isMarshalling;
 import static org.apache.sis.util.collection.Containers.isNullOrEmpty;
@@ -38,8 +40,6 @@ import static org.apache.sis.util.collec
  * ISO 19115 defines {@code ScopeDescription} as an <cite>union</cite> (in the
C/C++ sense):
  * only one of the properties in this class can be set to a non-empty value.
  * Setting any property to a non-empty value discard all the other ones.
- * See the {@linkplain #DefaultScopeDescription(ScopeDescription) constructor javadoc}
- * for information about which property has precedence on copy operations.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Touraïvane (IRD)
@@ -78,6 +78,18 @@ public class DefaultScopeDescription ext
     };
 
     /**
+     * The names of the setter methods, for logging purpose only.
+     */
+    private static final String[] SETTERS = {
+        "setAttributes",
+        "setFeatures",
+        "setFeatureInstances",
+        "setAttributeInstances",
+        "setDataset",
+        "setOther"
+    };
+
+    /**
      * Specifies which property is set, or 0 if none.
      */
     private byte property;
@@ -211,6 +223,9 @@ public class DefaultScopeDescription ext
     /**
      * Sets the properties identified by the {@code code} argument, if non-null and non-empty.
      * This discards any other properties.
+     *
+     * @param caller The caller method, for logging purpose.
+     * @param code   The property which is going to be set.
      */
     private <E> void setProperty(final Set<? extends E> newValue, final Class<E>
type, final byte code) {
         Set<E> c = null;
@@ -219,12 +234,25 @@ public class DefaultScopeDescription ext
         } else if (isNullOrEmpty(newValue)) {
             return;
         } else {
+            warningOnOverwrite(code);
             property = code;
         }
         value = writeSet(newValue, c, type);
     }
 
     /**
+     * Sends a warning if setting the value for the given property would overwrite an existing
property.
+     *
+     * @param code The property which is going to be set.
+     */
+    private void warningOnOverwrite(final byte code) {
+        if (value != null && property != code) {
+                WarningListeners.message(null, null, DefaultScopeDescription.class, SETTERS[code-1],
+                        Messages.Keys.DiscardedExclusiveProperty_2, NAMES[property-1], NAMES[code-1]);
+        }
+    }
+
+    /**
      * Returns the attributes to which the information applies.
      *
      * {@section Conditions}
@@ -345,6 +373,7 @@ public class DefaultScopeDescription ext
     public void setDataset(final String newValue) {
         checkWritePermission();
         if (newValue != null || property == DATASET) {
+            warningOnOverwrite(DATASET);
             property = DATASET;
             value = newValue;
         }
@@ -373,6 +402,7 @@ public class DefaultScopeDescription ext
     public void setOther(final String newValue) {
         checkWritePermission();
         if (newValue != null || property == OTHER) {
+            warningOnOverwrite(OTHER);
             property = OTHER;
             value = newValue;
         }

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java?rev=1479947&r1=1479946&r2=1479947&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -27,6 +27,8 @@ import org.opengis.metadata.spatial.Geor
 import org.opengis.metadata.spatial.PixelOrientation;
 import org.opengis.geometry.primitive.Point;
 import org.opengis.util.InternationalString;
+import org.apache.sis.internal.util.WarningListeners;
+import org.apache.sis.util.resources.Messages;
 import org.apache.sis.xml.Namespaces;
 
 
@@ -185,8 +187,9 @@ public class DefaultGeorectified extends
      * accuracy of the georeferenced grid data.
      *
      * {@section Effect on other properties}
-     * If and only if the given {@code newValue} is {@code false}, then this method automatically
sets
-     * the {@linkplain #setCheckPointDescription check point description} property to {@code
null}.
+     * If and only if the given {@code newValue} is {@code false}, then this method automatically
hides
+     * the {@linkplain #setCheckPointDescription check point description} property. The description
can
+     * be shown again by reverting {@code checkPointAvailability} to {@code true}.
      *
      * @param newValue {@code true} if check points are available.
      */
@@ -195,8 +198,11 @@ public class DefaultGeorectified extends
         if (newValue) {
             booleans |= CHECK_POINT_MASK;
         } else {
+            if (checkPointDescription != null && (booleans & CHECK_POINT_MASK)
!= 0) {
+                WarningListeners.message(null, null, DefaultGeorectified.class, "setCheckPointAvailable",
+                        Messages.Keys.PropertyHiddenBy_2, "checkPointDescription", "checkPointAvailability");
+            }
             booleans &= ~CHECK_POINT_MASK;
-            checkPointDescription = null;
         }
     }
 
@@ -208,7 +214,7 @@ public class DefaultGeorectified extends
     @Override
     @XmlElement(name = "checkPointDescription")
     public InternationalString getCheckPointDescription() {
-        return checkPointDescription;
+        return (booleans & CHECK_POINT_MASK) != 0 ? checkPointDescription : null;
     }
 
     /**

Added: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java?rev=1479947&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -0,0 +1,113 @@
+/*
+ * 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.metadata.iso.identification;
+
+import java.util.logging.Filter;
+import java.util.logging.Logger;
+import java.util.logging.LogRecord;
+import org.apache.sis.util.logging.Logging;
+import org.apache.sis.test.TestCase;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link DefaultResolution}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class DefaultResolutionTest extends TestCase implements Filter {
+    /**
+     * The logger where to warnings are expected to be sent.
+     */
+    private static final Logger LOGGER = Logging.getLogger(DefaultResolution.class);
+
+    /**
+     * {@code false} when no logging message is expected, and {@code true} when expected.
+     */
+    private boolean isLogExpected;
+
+    /**
+     * Installs this {@link Filter} for the log messages before the tests are run.
+     * This installation will cause the {@link #isLoggable(LogRecord)} method to be
+     * invoked when a message is logged.
+     *
+     * @see #isLoggable(LogRecord)
+     */
+    @Before
+    public void installLogFilter() {
+        assertNull(LOGGER.getFilter());
+        LOGGER.setFilter(this);
+    }
+
+    /**
+     * Removes the filter which has been set for testing purpose.
+     */
+    @After
+    public void removeLogFilter() {
+        LOGGER.setFilter(null);
+    }
+
+    /**
+     * Tests the various setter methods. Since they are exclusive properties,
+     * we expect any new property to replace the old one.
+     */
+    @Test
+    public void testSetExclusiveProperties() {
+        final DefaultResolution metadata = new DefaultResolution();
+        final DefaultRepresentativeFraction scale = new DefaultRepresentativeFraction();
+        scale.setDenominator(100);
+
+        metadata.setDistance(2.0);
+        assertEquals("distance", Double.valueOf(2.0), metadata.getDistance());
+        assertNull("equivalentScale", metadata.getEquivalentScale());
+
+        isLogExpected = true;
+        metadata.setEquivalentScale(scale);
+        assertSame("equivalentScale", scale, metadata.getEquivalentScale());
+        assertNull("distance", metadata.getDistance());
+
+        metadata.setDistance(null); // Expected to be a no-op.
+        assertSame("equivalentScale", scale, metadata.getEquivalentScale());
+        assertNull("distance", metadata.getDistance());
+
+        metadata.setEquivalentScale(null);
+        assertNull("equivalentScale", metadata.getEquivalentScale());
+        assertNull("distance", metadata.getDistance());
+    }
+
+    /**
+     * Invoked (indirectly) when a setter method has emitted a warning. This method verifies
if we
+     * were expecting a log message, then resets the {@link #isLogExpected} flag to {@code
false}
+     * (i.e. we expect at most one logging message).
+     */
+    @Override
+    public boolean isLoggable(final LogRecord record) {
+        final String message = record.getMessage();
+        if (!isLogExpected) {
+            fail("Unexpected logging: " + message);
+        }
+        isLogExpected = false;
+        return verbose;
+    }
+}

Propchange: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java?rev=1479947&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -0,0 +1,109 @@
+/*
+ * 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.metadata.iso.maintenance;
+
+import java.util.logging.Filter;
+import java.util.logging.Logger;
+import java.util.logging.LogRecord;
+import org.apache.sis.util.logging.Logging;
+import org.apache.sis.test.TestCase;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link DefaultScopeDescription}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class DefaultScopeDescriptionTest extends TestCase implements Filter
{
+    /**
+     * The logger where to warnings are expected to be sent.
+     */
+    private static final Logger LOGGER = Logging.getLogger(DefaultScopeDescription.class);
+
+    /**
+     * {@code false} when no logging message is expected, and {@code true} when expected.
+     */
+    private boolean isLogExpected;
+
+    /**
+     * Installs this {@link Filter} for the log messages before the tests are run.
+     * This installation will cause the {@link #isLoggable(LogRecord)} method to be
+     * invoked when a message is logged.
+     *
+     * @see #isLoggable(LogRecord)
+     */
+    @Before
+    public void installLogFilter() {
+        assertNull(LOGGER.getFilter());
+        LOGGER.setFilter(this);
+    }
+
+    /**
+     * Removes the filter which has been set for testing purpose.
+     */
+    @After
+    public void removeLogFilter() {
+        LOGGER.setFilter(null);
+    }
+
+    /**
+     * Tests the various setter methods. Since they are exclusive properties,
+     * we expect any new property to replace the old one.
+     */
+    @Test
+    public void testSetExclusiveProperties() {
+        final DefaultScopeDescription metadata = new DefaultScopeDescription();
+        metadata.setDataset("A dataset");
+        assertEquals("dataset", "A dataset", metadata.getDataset());
+
+        isLogExpected = true;
+        metadata.setOther("Other value");
+        assertEquals("other", "Other value", metadata.getOther());
+        assertNull("dataset", metadata.getDataset());
+
+        metadata.setDataset(null); // Expected to be a no-op.
+        assertEquals("other", "Other value", metadata.getOther());
+        assertNull("dataset", metadata.getDataset());
+
+        metadata.setOther(null);
+        assertNull("other",   metadata.getOther());
+        assertNull("dataset", metadata.getDataset());
+    }
+
+    /**
+     * Invoked (indirectly) when a setter method has emitted a warning. This method verifies
if we
+     * were expecting a log message, then resets the {@link #isLogExpected} flag to {@code
false}
+     * (i.e. we expect at most one logging message).
+     */
+    @Override
+    public boolean isLoggable(final LogRecord record) {
+        final String message = record.getMessage();
+        if (!isLogExpected) {
+            fail("Unexpected logging: " + message);
+        }
+        isLogExpected = false;
+        return verbose;
+    }
+}

Propchange: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java?rev=1479947&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -0,0 +1,111 @@
+/*
+ * 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.metadata.iso.spatial;
+
+import java.util.logging.Filter;
+import java.util.logging.Logger;
+import java.util.logging.LogRecord;
+import org.opengis.util.InternationalString;
+import org.apache.sis.util.logging.Logging;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.test.TestCase;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link DefaultGeorectified}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class DefaultGeorectifiedTest extends TestCase implements Filter {
+    /**
+     * The logger where to warnings are expected to be sent.
+     */
+    private static final Logger LOGGER = Logging.getLogger(DefaultGeorectified.class);
+
+    /**
+     * {@code false} when no logging message is expected, and {@code true} when expected.
+     */
+    private boolean isLogExpected;
+
+    /**
+     * Installs this {@link Filter} for the log messages before the tests are run.
+     * This installation will cause the {@link #isLoggable(LogRecord)} method to be
+     * invoked when a message is logged.
+     *
+     * @see #isLoggable(LogRecord)
+     */
+    @Before
+    public void installLogFilter() {
+        assertNull(LOGGER.getFilter());
+        LOGGER.setFilter(this);
+    }
+
+    /**
+     * Removes the filter which has been set for testing purpose.
+     */
+    @After
+    public void removeLogFilter() {
+        LOGGER.setFilter(null);
+    }
+
+    /**
+     * Tests {@link DefaultGeorectified#isCheckPointAvailable()} and
+     * {@link DefaultGeorectified#setCheckPointAvailable(boolean)}.
+     */
+    @Test
+    public void testCheckPointAvailable() {
+        final DefaultGeorectified metadata = new DefaultGeorectified();
+        final InternationalString description = new SimpleInternationalString("A check point
description.");
+        assertFalse("checkPointAvailability", metadata.isCheckPointAvailable());
+
+        // Setting the description shall set automatically the availability.
+        metadata.setCheckPointDescription(description);
+        assertTrue("checkPointAvailability", metadata.isCheckPointAvailable());
+
+        // Setting the availability flag shall hide the description and logs a message.
+        isLogExpected = true;
+        metadata.setCheckPointAvailable(false);
+        assertNull("checkPointDescription", metadata.getCheckPointDescription());
+
+        // Setting the availability flag shall bring back the description.
+        metadata.setCheckPointAvailable(true);
+        assertSame("checkPointDescription", description, metadata.getCheckPointDescription());
+    }
+
+    /**
+     * Invoked (indirectly) when the {@link DefaultGeorectified#setCheckPointAvailable(boolean)}
method
+     * has emitted a warning. This method verifies if we were expecting a log message, then
resets the
+     * {@link #isLogExpected} flag to {@code false} (i.e. we expect at most one logging message).
+     */
+    @Override
+    public boolean isLoggable(final LogRecord record) {
+        final String message = record.getMessage();
+        if (!isLogExpected) {
+            fail("Unexpected logging: " + message);
+        }
+        isLogExpected = false;
+        return verbose;
+    }
+}

Propchange: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1479947&r1=1479946&r2=1479947&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -33,6 +33,9 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.metadata.MetadataUtilitiesTest.class,
     org.apache.sis.metadata.iso.citation.DefaultCitationDateTest.class,
     org.apache.sis.metadata.iso.citation.DefaultCitationTest.class,
+    org.apache.sis.metadata.iso.identification.DefaultResolutionTest.class,
+    org.apache.sis.metadata.iso.spatial.DefaultGeorectifiedTest.class,
+    org.apache.sis.metadata.iso.maintenance.DefaultScopeDescriptionTest.class,
     org.apache.sis.metadata.iso.quality.AbstractElementTest.class,
 
     // Classes using Java reflection.

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/WarningListeners.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/WarningListeners.java?rev=1479947&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/WarningListeners.java
(added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/WarningListeners.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -0,0 +1,131 @@
+/*
+ * 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.internal.util;
+
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import org.apache.sis.util.Classes;
+import org.apache.sis.util.Localized;
+import org.apache.sis.util.logging.Logging;
+import org.apache.sis.util.resources.Messages;
+
+
+/**
+ * Utilities methods for emitting warnings that may be of interest to the users.
+ * The current implementation does not have any mechanism for registering listeners,
+ * because we don't know yet what would be the most appropriate API. One possibility
+ * would be as below, based on the observation that the final destination of a warning
+ * is often the logger and that {@link LogRecord} provides many useful information like
+ * the source class and the stack trace:
+ *
+ * {@preformat java
+ *     public interface WarningListener extends EventListener {
+ *         boolean warningOccurred(LogRecord record);
+ *     }
+ * }
+ *
+ * In the main time, this class is used as a central place where we can trace the code
+ * that emit warnings of potential interest to the user.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.08)
+ * @version 0.3
+ * @module
+ */
+public final class WarningListeners {
+    /**
+     * A temporary variable for identifying places in the code that may need to be revisited
if we
+     * provide warning listeners. For example we do not log stack traces at this time for
avoiding
+     * to flood the logs, but we would want to provide the stack trace as information to
listeners.
+     */
+    private static final boolean HAS_LISTENERS = false;
+
+    /**
+     * Do not allow instantiation of this class (for now - may change in a future version).
+     */
+    private WarningListeners() {
+    }
+
+    /**
+     * Convenience method for reporting a warning for the given exception. If the given exception
+     * has no message of a message containing only one word (e.g. {@link IndexOutOfBoundsException}
+     * with only the index number), then this method tries to make the message more informative
by
+     * prepending the exception class name.
+     *
+     * @param  level     The logging level, or {@code null} for the default one.
+     * @param  caller    The public class which is invoking this method.
+     * @param  method    The public method which is invoking this method.
+     * @param  exception The exception to log.
+     */
+    public static void warningOccurred(Level level, final Class<?> caller, final String
method, final Exception exception) {
+        if (level == null) {
+            level = Level.WARNING;
+        }
+        String message = exception.getLocalizedMessage();
+        if (message == null || message.indexOf(' ') < 0) {
+            final String word = message;
+            message = Classes.getShortClassName(exception);
+            if (word != null) {
+                message = message + ": " + word;
+            }
+        }
+        final LogRecord record = new LogRecord(level, message);
+        if (HAS_LISTENERS) {
+            record.setThrown(exception);
+        }
+        Logging.log(caller, method, record);
+    }
+
+    /**
+     * Convenience method for logging a warning with the given message.
+     *
+     * @param  level     The logging level, or {@code null} for the default one.
+     * @param  caller    The public class which is invoking this method.
+     * @param  method    The public method which is invoking this method.
+     * @param  message   The message to log.
+     */
+    public static void warningOccurred(Level level, final Class<?> caller, final String
method, final String message) {
+        if (level == null) {
+            level = Level.WARNING;
+        }
+        final LogRecord record = new LogRecord(level, message);
+        Logging.log(caller, method, record);
+    }
+
+    /**
+     * Convenience method for logging a warning with the given localized message.
+     * The message will be produced using the {@link Messages} resources bundle.
+     *
+     * @param  level     The logging level, or {@code null} for the default one.
+     * @param  instance  The instance invoking this method, or {@code null}.
+     * @param  caller    The public class which is invoking this method.
+     * @param  method    The public method which is invoking this method.
+     * @param  key       The key from the message resource bundle to use for creating a message.
+     * @param  arguments The arguments to be used together with the key for building the
message.
+     */
+    public static void message(Level level, final Localized instance, final Class<?>
caller, final String method,
+            final int key, final Object... arguments)
+    {
+        if (level == null) {
+            level = Level.WARNING;
+        }
+        final Locale locale = (instance != null) ? instance.getLocale() : null;
+        final LogRecord record = Messages.getResources(locale).getLogRecord(level, key, arguments);
+        Logging.log(caller, method, record);
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/WarningListeners.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/WarningListeners.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java?rev=1479947&r1=1479946&r2=1479947&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
[UTF-8] Tue May  7 15:44:15 2013
@@ -60,11 +60,22 @@ public final class Messages extends Inde
         public static final int ChangedContainerCapacity_2 = 0;
 
         /**
+         * Property “{0}” has been discarded in favor of “{1}”, because those two
properties are
+         * mutually exclusive.
+         */
+        public static final int DiscardedExclusiveProperty_2 = 4;
+
+        /**
          * Text were discarded for some locales.
          */
         public static final int LocalesDiscarded = 2;
 
         /**
+         * Property “{0}” is hidden by “{1}”.
+         */
+        public static final int PropertyHiddenBy_2 = 3;
+
+        /**
          * Unavailable content.
          */
         public static final int UnavailableContent = 1;

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties?rev=1479947&r1=1479946&r2=1479947&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
[ISO-8859-1] Tue May  7 15:44:15 2013
@@ -15,5 +15,7 @@
 # limitations under the License.
 #
 ChangedContainerCapacity_2      = Changed the container capacity from {0} to {1} elements.
+DiscardedExclusiveProperty_2    = Property \u201c{0}\u201d has been discarded in favor of
\u201c{1}\u201d, because those two properties are mutually exclusive.
+PropertyHiddenBy_2              = Property \u201c{0}\u201d is hidden by \u201c{1}\u201d.
 LocalesDiscarded                = Text were discarded for some locales.
 UnavailableContent              = Unavailable content.

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties?rev=1479947&r1=1479946&r2=1479947&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
[ISO-8859-1] Tue May  7 15:44:15 2013
@@ -15,5 +15,7 @@
 # limitations under the License.
 #
 ChangedContainerCapacity_2      = Changement de la capacit\u00e9 du conteneur de {0} vers
{1} \u00e9l\u00e9ments.
+DiscardedExclusiveProperty_2    = La propri\u00e9t\u00e9 \u201c{0}\u201d a \u00e9t\u00e9
\u00e9cart\u00e9e en faveur de \u201c{1}\u201d, parce que ces deux propri\u00e9t\u00e9s sont
mutuellement exclusives.
+PropertyHiddenBy_2              = La propri\u00e9t\u00e9 \u201c{0}\u201d est masqu\u00e9e
par \u201c{1}\u201d.
 LocalesDiscarded                = Des textes ont \u00e9t\u00e9 ignor\u00e9s pour certaines
langues.
 UnavailableContent              = Contenu non-disponible.

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestCase.java?rev=1479947&r1=1479946&r2=1479947&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
Tue May  7 15:44:15 2013
@@ -92,7 +92,7 @@ public abstract strictfp class TestCase 
      * {@code true} if the {@value org.apache.sis.test.TestConfiguration#VERBOSE_OUTPUT_KEY}
      * system property is set to {@code true}.
      */
-    static final boolean verbose;
+    protected static final boolean verbose;
 
     /**
      * Sets the {@link #out} writer and its underlying {@link #buffer}.



Mime
View raw message