sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1606676 - in /sis/branches/JDK8/core/sis-metadata/src: main/java/org/apache/sis/internal/metadata/ main/java/org/apache/sis/metadata/iso/content/ main/java/org/apache/sis/metadata/iso/lineage/ main/java/org/apache/sis/metadata/iso/maintena...
Date Mon, 30 Jun 2014 10:48:37 GMT
Author: desruisseaux
Date: Mon Jun 30 10:48:36 2014
New Revision: 1606676

URL: http://svn.apache.org/r1606676
Log:
Better implementation of DefaultSource.getSourceExtents() in order to avoid an UnsupportedOperationException
at unmarshalling time.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java?rev=1606676&r1=1606675&r2=1606676&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
[UTF-8] Mon Jun 30 10:48:36 2014
@@ -137,21 +137,28 @@ public abstract class LegacyPropertyAdap
      * Returns the singleton value of the given collection, or {@code null} if the given
collection is null or empty.
      * If the given collection contains more than one element, then a warning is emitted.
      *
+     * @param  <L>           The kind of legacy values to be returned.
      * @param  values        The collection from which to get the value.
      * @param  valueClass    The value class, used in case of warning only.
+     * @param  caller        Either {@code this} or {@code null}.
      * @param  callerClass   The caller class, used in case of warning only.
      * @param  callerMethod  The caller method, used in case of warning only.
      * @return The first value, or {@code null} if none.
      */
-    protected final L singleton(final Collection<? extends L> values, final Class<L>
valueClass,
-            final Class<?> callerClass, final String callerMethod)
+    public static <L> L getSingleton(final Collection<? extends L> values, final
Class<L> valueClass,
+            final LegacyPropertyAdapter<L,?> caller, final Class<?> callerClass,
final String callerMethod)
     {
         if (values != null) {
             final Iterator<? extends L> it = values.iterator();
             if (it.hasNext()) {
                 final L value = it.next();
-                if (!warningOccurred && it.hasNext()) {
-                    warningOccurred = true;
+                if (it.hasNext()) {
+                    if (caller != null) {
+                        if (caller.warningOccurred) {
+                            return value; // Skip the warning.
+                        }
+                        caller.warningOccurred = true;
+                    }
                     MetadataUtilities.warning(callerClass, callerMethod,
                             Messages.Keys.IgnoredPropertiesAfterFirst_1, valueClass);
                 }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java?rev=1606676&r1=1606675&r2=1606676&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
[UTF-8] Mon Jun 30 10:48:36 2014
@@ -286,8 +286,8 @@ public class DefaultCoverageDescription 
 
             /** Extracts the legacy value from the new kind of value. */
             @Override protected RangeDimension unwrap(final AttributeGroup container) {
-                return singleton(container.getGroupAttributes(), RangeDimension.class,
-                        DefaultCoverageDescription.class, "getDimensions");
+                return getSingleton(container.getGroupAttributes(), RangeDimension.class,
+                        this, DefaultCoverageDescription.class, "getDimensions");
             }
 
             /** Updates the legacy value in an existing new kind of value. */

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java?rev=1606676&r1=1606675&r2=1606676&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java
[UTF-8] Mon Jun 30 10:48:36 2014
@@ -35,7 +35,6 @@ import org.opengis.referencing.Reference
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.metadata.iso.quality.DefaultScope;
 import org.apache.sis.metadata.iso.identification.DefaultResolution;
-import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.xml.Namespaces;
 
@@ -371,8 +370,12 @@ public class DefaultSource extends ISOMe
     @Deprecated
     @XmlElement(name = "sourceExtent")
     public final Collection<Extent> getSourceExtents() {
-        final Scope scope = getScope();
-        return LegacyPropertyAdapter.asCollection(scope != null ? scope.getExtent() : null);
+        Scope scope = getScope();
+        if (!(scope instanceof DefaultScope)) {
+            scope = new DefaultScope(scope);
+            setScope(scope);
+        }
+        return ((DefaultScope) scope).getExtents();
     }
 
     /**
@@ -385,15 +388,12 @@ public class DefaultSource extends ISOMe
      */
     @Deprecated
     public final void setSourceExtents(final Collection<? extends Extent> newValues)
{
-        final Extent newValue = (newValues != null && !newValues.isEmpty()) ? newValues.iterator().next()
: null;
-        final Scope scope = getScope();
-        if (scope instanceof DefaultScope) {
-            ((DefaultScope) scope).setExtent(newValue);
-        } else {
-            final DefaultScope s = new DefaultScope();
-            s.setExtent(newValue);
-            setScope(s);
+        Scope scope = getScope();
+        if (!(scope instanceof DefaultScope)) {
+            scope = new DefaultScope(scope);
+            setScope(scope);
         }
+        ((DefaultScope) scope).setExtents(newValues);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java?rev=1606676&r1=1606675&r2=1606676&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
[UTF-8] Mon Jun 30 10:48:36 2014
@@ -371,8 +371,8 @@ public class DefaultMaintenanceInformati
 
             /** Extracts the legacy value from the new kind of value. */
             @Override protected ScopeDescription unwrap(final Scope container) {
-                return singleton(container.getLevelDescription(), ScopeDescription.class,
-                        DefaultMaintenanceInformation.class, "getUpdateScopeDescriptions");
+                return getSingleton(container.getLevelDescription(), ScopeDescription.class,
+                        this, DefaultMaintenanceInformation.class, "getUpdateScopeDescriptions");
             }
 
             /** Updates the legacy value in an existing new kind of value. */

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java?rev=1606676&r1=1606675&r2=1606676&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
[UTF-8] Mon Jun 30 10:48:36 2014
@@ -24,6 +24,7 @@ import org.opengis.metadata.extent.Exten
 import org.opengis.metadata.quality.Scope;
 import org.opengis.metadata.maintenance.ScopeCode;
 import org.opengis.metadata.maintenance.ScopeDescription;
+import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 import org.apache.sis.metadata.iso.ISOMetadata;
 
 
@@ -33,7 +34,7 @@ import org.apache.sis.metadata.iso.ISOMe
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Touraïvane (IRD)
  * @since   0.3 (derived from geotk-2.1)
- * @version 0.3
+ * @version 0.5
  * @module
  */
 @XmlType(name = "DQ_Scope_Type", propOrder = {
@@ -46,7 +47,7 @@ public class DefaultScope extends ISOMet
     /**
      * Serial number for inter-operability with different versions.
      */
-    private static final long serialVersionUID = -1152756005841712646L;
+    private static final long serialVersionUID = 8357871602883209505L;
 
     /**
      * Hierarchical level of the data specified by the scope.
@@ -54,9 +55,9 @@ public class DefaultScope extends ISOMet
     private ScopeCode level;
 
     /**
-     * Information about the spatial, vertical and temporal extent of the data specified
by the scope.
+     * Information about the spatial, vertical and temporal extent of the resource specified
by the scope.
      */
-    private Extent extent;
+    private Collection<Extent> extents;
 
     /**
      * Detailed description about the level of the data specified by the scope.
@@ -91,7 +92,7 @@ public class DefaultScope extends ISOMet
         super(object);
         if (object != null) {
             level            = object.getLevel();
-            extent           = object.getExtent();
+            extents          = copyCollection(object.getExtents(), Extent.class);
             levelDescription = copyCollection(object.getLevelDescription(), ScopeDescription.class);
         }
     }
@@ -143,6 +144,29 @@ public class DefaultScope extends ISOMet
     }
 
     /**
+     * Returns information about the spatial, vertical and temporal extents of the resource
specified by the scope.
+     *
+     * @return Information about the extent of the resource.
+     *
+     * @since 0.5
+     */
+    @Override
+    public Collection<Extent> getExtents() {
+        return extents = nonNullCollection(extents, Extent.class);
+    }
+
+    /**
+     * Sets information about the spatial, vertical and temporal extents of the resource
specified by the scope.
+     *
+     * @param newValues New information about the extent of the resource.
+     *
+     * @since 0.5
+     */
+    public void setExtents(final Collection<? extends Extent> newValues) {
+        extents = writeCollection(newValues, extents, Extent.class);
+    }
+
+    /**
      * Returns detailed descriptions about the level of the data specified by the scope.
      *
      * @return Detailed description about the level of the data.
@@ -164,23 +188,29 @@ public class DefaultScope extends ISOMet
 
     /**
      * Information about the spatial, vertical and temporal extent of the data specified
by the scope.
+     * This method fetches the value from the {@linkplain #getExtents() extents} collection.
      *
      * @return Information about the extent of the data, or {@code null}.
+     *
+     * @deprecated Replaced by {@link #getExtents()} as of ISO 19115:2014.
      */
     @Override
+    @Deprecated
     @XmlElement(name = "extent")
-    public Extent getExtent() {
-        return extent;
+    public final Extent getExtent() {
+        return LegacyPropertyAdapter.getSingleton(extents, Extent.class, null, DefaultScope.class,
"getExtent");
     }
 
     /**
-     * Sets information about the spatial, vertical and temporal extent of the data specified
-     * by the scope.
+     * Sets information about the spatial, vertical and temporal extent of the data specified
by the scope.
+     * This method stores the value in the {@linkplain #setExtents(Collection) extents} collection.
      *
      * @param newValue The new extent.
+     *
+     * @deprecated Replaced by {@link #setExtents(Collection)} as of ISO 19115:2014.
      */
-    public void setExtent(final Extent newValue) {
-        checkWritePermission();
-        extent = newValue;
+    @Deprecated
+    public final void setExtent(final Extent newValue) {
+        setExtents(LegacyPropertyAdapter.asCollection(newValue));
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java?rev=1606676&r1=1606675&r2=1606676&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
[UTF-8] Mon Jun 30 10:48:36 2014
@@ -153,7 +153,7 @@ public final strictfp class AllMetadataT
             org.opengis.metadata.lineage.Processing.class,
             org.opengis.metadata.lineage.ProcessStep.class,
             org.opengis.metadata.lineage.ProcessStepReport.class,
-// TODO     org.opengis.metadata.lineage.Source.class,
+            org.opengis.metadata.lineage.Source.class,
             org.opengis.metadata.maintenance.MaintenanceFrequency.class,
             org.opengis.metadata.maintenance.MaintenanceInformation.class,
             org.opengis.metadata.maintenance.MetadataScope.class,



Mime
View raw message