sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1605797 - in /sis/branches/JDK7: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintena...
Date Thu, 26 Jun 2014 14:30:28 GMT
Author: desruisseaux
Date: Thu Jun 26 14:30:27 2014
New Revision: 1605797

URL: http://svn.apache.org/r1605797
Log:
Merge the DefaultCoverageDescription upgrade for ISO 19115:2014.

Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyProperties.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
    sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK8:r1605686-1605796

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyProperties.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyProperties.java?rev=1605797&r1=1605796&r2=1605797&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyProperties.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyProperties.java
[UTF-8] Thu Jun 26 14:30:27 2014
@@ -18,14 +18,18 @@ package org.apache.sis.internal.metadata
 
 import java.util.AbstractCollection;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
+import org.apache.sis.metadata.AbstractMetadata;
+import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.ArgumentChecks;
 
 
 /**
  * An adapter for collections of a legacy type replaced by an other collection.
- * This adapter is used for properties which have been deprecated after updating an ISO standard.
+ * This adapter is used for implementation of deprecated methods in the {@link org.apache.sis.metadata.iso}
+ * sub-packages, usually when the deprecation is the result of upgrading from an older to
a newer ISO standard.
  *
  * @param <L> The legacy type.
  * @param <N> The new type.
@@ -42,9 +46,14 @@ public abstract class LegacyProperties<L
     final Collection<N> elements;
 
     /**
+     * For logging warning only once per collection usage.
+     */
+    private transient boolean warningOccurred;
+
+    /**
      * Creates a new adapter.
      *
-     * @param elements The collection where to store the elements.
+     * @param elements The collection where to store the elements (may be {@code null}).
      */
     protected LegacyProperties(final Collection<N> elements) {
         this.elements = elements;
@@ -61,10 +70,122 @@ public abstract class LegacyProperties<L
     /**
      * Extracts a legacy value from the new type.
      *
-     * @param  value The new type.
+     * @param  container The new type.
      * @return The legacy value, or {@code null}.
      */
-    protected abstract L unwrap(final N value);
+    protected abstract L unwrap(final N container);
+
+    /**
+     * Update a new value with the given legacy value.
+     *
+     * @param  container The new value to be used as a container for the old value.
+     * @param  value     The value to update in the container.
+     * @return Whether this method has been able to perform the update.
+     */
+    protected abstract boolean update(final N container, final L value);
+
+
+
+    // ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐
+    // │                                  Convenience methods for subclasses          
                        │
+    // └───────────────────────────────────────────────────────────────────────────────────────────────────────┘
+
+
+
+    /**
+     * Returns {@code this} if the collection given at construction time was non-null, or
{@code null} otherwise.
+     * The later case may happen at marshalling time.
+     *
+     * @return {@code this} or {@code null}.
+     */
+    public final LegacyProperties<L,N> validOrNull() {
+        return (elements != null) ? this : null;
+    }
+
+    /**
+     * Sets the values from the given collection.
+     *
+     * @param newValues The values to set (may be {@code null}).
+     */
+    public final void setValues(Collection<? extends L> newValues) {
+        if (newValues == null) {
+            newValues = Collections.emptySet();
+        }
+        final Iterator<? extends L> it = newValues.iterator();
+        final Iterator<N> toUpdate = elements.iterator();
+        boolean hasNext = it.hasNext();
+        L next = hasNext ? it.next() : null;
+        while (toUpdate.hasNext()) {
+            final N container = toUpdate.next();
+            if (update(container, next)) {
+                hasNext = it.hasNext();
+                next = hasNext ? it.next() : null;
+                if (isEmpty(container)) {
+                    toUpdate.remove();
+                }
+            }
+        }
+        if (hasNext) {
+            elements.add(wrap(next));
+            while (it.hasNext()) {
+                elements.add(wrap(it.next()));
+            }
+        }
+    }
+
+    /**
+     * 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  values        The collection from which to get the value.
+     * @param  valueClass    The value class, used in case of warning only.
+     * @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)
+    {
+        if (values != null) {
+            final Iterator<? extends L> it = values.iterator();
+            if (it.hasNext()) {
+                final L value = it.next();
+                if (!warningOccurred && it.hasNext()) {
+                    warningOccurred = true;
+                    MetadataUtilities.warning(callerClass, callerMethod,
+                            Messages.Keys.IgnoredPropertiesAfterFirst_1, valueClass);
+                }
+                return value;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the given value as an empty or singleton collection.
+     *
+     * @param  <L>   The type of the old value.
+     * @param  value The value, or {@code null} if none.
+     * @return The given value as a collection.
+     */
+    public static <L> Collection<L> asCollection(final L value) {
+        return (value != null) ? Collections.singleton(value) : Collections.<L>emptySet();
+    }
+
+    /**
+     * Returns {@code true} if the given metadata is empty.
+     */
+    static boolean isEmpty(final Object container) {
+        return (container instanceof AbstractMetadata) && ((AbstractMetadata) container).isEmpty();
+    }
+
+
+
+    // ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐
+    // │                                 Methods from the Collection interface        
                        │
+    // └───────────────────────────────────────────────────────────────────────────────────────────────────────┘
+
+
 
     /**
      * Returns {@code true} if this collection is empty.
@@ -113,42 +234,66 @@ public abstract class LegacyProperties<L
     public final Iterator<L> iterator() {
         final Iterator<N> it = elements.iterator();
         return new Iterator<L>() {
-            /** The next value to return, or {@code null} if not yet verified. */
+            /**
+             * The container of the next value to return.
+             */
+            private N container;
+
+            /**
+             * The next value to return, or {@code null} if not yet verified.
+             */
             private L next;
 
-            /** Returns {@code true} if there is more elements to iterator. */
+            /**
+             * Returns {@code true} if there is more elements to iterate.
+             * This method prefetches and stores the next value.
+             */
             @Override
             public final boolean hasNext() {
                 if (next != null) {
                     return true;
                 }
                 while (it.hasNext()) {
-                    next = unwrap(it.next());
+                    container = it.next();
+                    next = unwrap(container);
                     if (next != null) {
                         return true;
                     }
                 }
+                container = null;
                 return false;
             }
 
-            /** Returns the next element. */
+            /**
+             * Returns the next element.
+             */
             @Override
             public final L next() {
-                L n = next;
-                if (n == null) {
+                L value = next;
+                if (value == null) {
                     if (!hasNext()) {
                         throw new NoSuchElementException();
                     }
-                    n = next;
+                    value = next;
                 }
                 next = null;
-                return n;
+                return value;
             }
 
-            /** Removes the last element returned by {@link #next()}. */
+            /**
+             * Removes the last element returned by {@link #next()}.
+             */
             @Override
             public final void remove() {
-                it.remove();
+                if (container == null) {
+                    throw new IllegalStateException();
+                }
+                if (!update(container, null)) {
+                    throw new UnsupportedOperationException();
+                }
+                if (isEmpty(container)) {
+                    it.remove();
+                }
             }
         };
     }

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java?rev=1605797&r1=1605796&r2=1605797&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
[UTF-8] Thu Jun 26 14:30:27 2014
@@ -21,6 +21,8 @@ import javax.xml.bind.annotation.XmlType
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import org.opengis.metadata.Identifier;
+import org.opengis.metadata.content.AttributeGroup;
 import org.opengis.metadata.content.CoverageContentType;
 import org.opengis.metadata.content.CoverageDescription;
 import org.opengis.metadata.content.ImageDescription;
@@ -28,6 +30,9 @@ import org.opengis.metadata.content.Rang
 import org.opengis.metadata.content.RangeElementDescription;
 import org.opengis.util.RecordType;
 import org.apache.sis.xml.Namespaces;
+import org.apache.sis.util.resources.Messages;
+import org.apache.sis.internal.metadata.LegacyProperties;
+import org.apache.sis.internal.metadata.MetadataUtilities;
 
 
 /**
@@ -37,7 +42,7 @@ import org.apache.sis.xml.Namespaces;
  * @author  Touraïvane (IRD)
  * @author  Cédric Briançon (Geomatys)
  * @since   0.3 (derived from geotk-2.1)
- * @version 0.3
+ * @version 0.5
  * @module
  */
 @XmlType(name = "MD_CoverageDescription_Type", propOrder = {
@@ -55,7 +60,7 @@ public class DefaultCoverageDescription 
     /**
      * Serial number for inter-operability with different versions.
      */
-    private static final long serialVersionUID = -3314118785767660332L;
+    private static final long serialVersionUID = 2161065580202989466L;
 
     /**
      * Description of the attribute described by the measurement value.
@@ -63,14 +68,14 @@ public class DefaultCoverageDescription 
     private RecordType attributeDescription;
 
     /**
-     * Type of information represented by the cell value.
+     * Identifier for the level of processing that has been applied to the resource.
      */
-    private CoverageContentType contentType;
+    private Identifier processingLevelCode;
 
     /**
-     * Information on the dimensions of the cell measurement value.
+     * Information on attribute groups of the resource.
      */
-    private Collection<RangeDimension> dimensions;
+    private Collection<AttributeGroup> attributeGroups;
 
     /**
      * Provides the description of the specific range elements of a coverage.
@@ -96,8 +101,8 @@ public class DefaultCoverageDescription 
         super(object);
         if (object != null) {
             attributeDescription     = object.getAttributeDescription();
-            contentType              = object.getContentType();
-            dimensions               = copyCollection(object.getDimensions(), RangeDimension.class);
+            processingLevelCode      = object.getProcessingLevelCode();
+            attributeGroups          = copyCollection(object.getAttributeGroups(), AttributeGroup.class);
             rangeElementDescriptions = copyCollection(object.getRangeElementDescriptions(),
RangeElementDescription.class);
         }
     }
@@ -136,7 +141,7 @@ public class DefaultCoverageDescription 
     /**
      * Returns the description of the attribute described by the measurement value.
      *
-     * @return Description of the attribute, or {@code null}.
+     * @return Description of the attribute.
      */
     @Override
     @XmlElement(name = "attributeDescription", required = true)
@@ -155,44 +160,155 @@ public class DefaultCoverageDescription 
     }
 
     /**
+     * Returns an identifier for the level of processing that has been applied to the resource,
or {@code null} if none.
+     *
+     * @return Identifier for the level of processing that has been applied to the resource,
or {@code null} if none.
+     *
+     * @since 0.5
+     */
+    @Override
+/// @XmlElement(name = "processingLevelCode")
+    public Identifier getProcessingLevelCode() {
+        return processingLevelCode;
+    }
+
+    /**
+     * Sets the identifier for the level of processing that has been applied to the resource.
+     *
+     * @param newValue The new identifier for the level of processing.
+     *
+     * @since 0.5
+     */
+    public void setProcessingLevelCode(final Identifier newValue) {
+        checkWritePermission();
+        processingLevelCode = newValue;
+    }
+
+    /**
+     * Returns information on attribute groups of the resource.
+     *
+     * @return Information on attribute groups of the resource.
+     *
+     * @since 0.5
+     */
+    @Override
+/// @XmlElement(name = "attributeGroup")
+    public Collection<AttributeGroup> getAttributeGroups() {
+        return attributeGroups = nonNullCollection(attributeGroups, AttributeGroup.class);
+    }
+
+    /**
+     * Sets information on attribute groups of the resource.
+     *
+     * @param newValues The new information on attribute groups of the resource.
+     *
+     * @since 0.5
+     */
+    public void setAttributeGroups(final Collection<? extends AttributeGroup> newValues)
{
+        attributeGroups = writeCollection(newValues, attributeGroups, AttributeGroup.class);
+    }
+
+    /**
      * Returns the type of information represented by the cell value.
      *
      * @return Type of information represented by the cell value, or {@code null}.
+     *
+     * @deprecated Moved to {@link DefaultAttributeGroup#getContentTypes()} as of ISO 19115:2014.
      */
     @Override
+    @Deprecated
     @XmlElement(name = "contentType", required = true)
     public CoverageContentType getContentType() {
-        return contentType;
+        CoverageContentType type = null;
+        if (attributeGroups != null) {
+            for (final AttributeGroup g : attributeGroups) {
+                final Collection<? extends CoverageContentType> contentTypes = g.getContentTypes();
+                if (contentTypes != null) { // May be null on marshalling.
+                    for (final CoverageContentType t : contentTypes) {
+                        if (type == null) {
+                            type = t;
+                        } else {
+                            MetadataUtilities.warning(DefaultCoverageDescription.class, "getContentType",
+                                    Messages.Keys.IgnoredPropertiesAfterFirst_1, CoverageContentType.class);
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        return type;
     }
 
     /**
      * Sets the type of information represented by the cell value.
      *
      * @param newValue The new content type.
+     *
+     * @deprecated Moved to {@link DefaultAttributeGroup#setContentTypes(Collection)}.
      */
+    @Deprecated
     public void setContentType(final CoverageContentType newValue) {
         checkWritePermission();
-        contentType = newValue;
+        final Collection<CoverageContentType> newValues = LegacyProperties.asCollection(newValue);
+        final Collection<AttributeGroup> groups = getAttributeGroups();
+        for (final AttributeGroup group : groups) {
+            if (group instanceof DefaultAttributeGroup) {
+                ((DefaultAttributeGroup) group).setContentTypes(newValues);
+                return;
+            }
+        }
+        final DefaultAttributeGroup group = new DefaultAttributeGroup();
+        group.setContentTypes(newValues);
+        groups.add(group);
     }
 
     /**
      * Returns the information on the dimensions of the cell measurement value.
      *
      * @return Dimensions of the cell measurement value.
+     *
+     * @deprecated Moved to {@link DefaultAttributeGroup#getGroupAttributes()} as of ISO
19115:2014.
      */
     @Override
+    @Deprecated
     @XmlElement(name = "dimension")
-    public Collection<RangeDimension> getDimensions() {
-        return dimensions = nonNullCollection(dimensions, RangeDimension.class);
+    public final Collection<RangeDimension> getDimensions() {
+        return new LegacyProperties<RangeDimension,AttributeGroup>(getAttributeGroups())
{
+            /** Stores a legacy value into the new kind of value. */
+            @Override protected AttributeGroup wrap(final RangeDimension value) {
+                final DefaultAttributeGroup container = new DefaultAttributeGroup();
+                container.setGroupAttributes(asCollection(value));
+                return container;
+            }
+
+            /** 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");
+            }
+
+            /** Updates the legacy value in an existing new kind of value. */
+            @Override protected boolean update(final AttributeGroup container, final RangeDimension
value) {
+                if (container instanceof DefaultAttributeGroup) {
+                    ((DefaultAttributeGroup) container).setGroupAttributes(asCollection(value));
+                    return true;
+                }
+                return false;
+            }
+        }.validOrNull();
     }
 
     /**
      * Sets the information on the dimensions of the cell measurement value.
      *
      * @param newValues The new dimensions.
+     *
+     * @deprecated Moved to {@link DefaultAttributeGroup#setGroupAttributes(Collection)}.
      */
+    @Deprecated
     public void setDimensions(final Collection<? extends RangeDimension> newValues)
{
-        dimensions = writeCollection(newValues, dimensions, RangeDimension.class);
+        checkWritePermission();
+        ((LegacyProperties<RangeDimension,?>) getDimensions()).setValues(newValues);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java?rev=1605797&r1=1605796&r2=1605797&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
[UTF-8] Thu Jun 26 14:30:27 2014
@@ -56,7 +56,7 @@ public class DefaultImageDescription ext
     /**
      * Serial number for inter-operability with different versions.
      */
-    private static final long serialVersionUID = 1756867502303578675L;
+    private static final long serialVersionUID = -239683653229623567L;
 
     /**
      * Illumination elevation measured in degrees clockwise from the target plane
@@ -87,12 +87,6 @@ public class DefaultImageDescription ext
     private Double cloudCoverPercentage;
 
     /**
-     * Image distributor's code that identifies the level of radiometric and geometric
-     * processing that has been applied.
-     */
-    private Identifier processingLevelCode;
-
-    /**
      * Count of the number of lossy compression cycles performed on the image.
      */
     private Integer compressionGenerationQuantity;
@@ -150,7 +144,6 @@ public class DefaultImageDescription ext
             imagingCondition                      = object.getImagingCondition();
             imageQualityCode                      = object.getImageQualityCode();
             cloudCoverPercentage                  = object.getCloudCoverPercentage();
-            processingLevelCode                   = object.getProcessingLevelCode();
             compressionGenerationQuantity         = object.getCompressionGenerationQuantity();
             triangulationIndicator                = object.getTriangulationIndicator();
             radiometricCalibrationDataAvailable   = object.isRadiometricCalibrationDataAvailable();
@@ -311,7 +304,7 @@ public class DefaultImageDescription ext
     @Override
     @XmlElement(name = "processingLevelCode")
     public Identifier getProcessingLevelCode() {
-        return processingLevelCode;
+        return super.getProcessingLevelCode();
     }
 
     /**
@@ -320,9 +313,9 @@ public class DefaultImageDescription ext
      *
      * @param newValue The new processing level code.
      */
+    @Override
     public void setProcessingLevelCode(final Identifier newValue) {
-        checkWritePermission();
-        processingLevelCode = newValue;
+        super.setProcessingLevelCode(newValue);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java?rev=1605797&r1=1605796&r2=1605797&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
[UTF-8] Thu Jun 26 14:30:27 2014
@@ -18,8 +18,6 @@ package org.apache.sis.metadata.iso.main
 
 import java.util.Date;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
@@ -37,8 +35,6 @@ import org.apache.sis.metadata.iso.ISOMe
 import org.apache.sis.metadata.iso.quality.DefaultScope;
 import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
 import org.apache.sis.internal.metadata.LegacyProperties;
-import org.apache.sis.internal.metadata.MetadataUtilities;
-import org.apache.sis.util.resources.Messages;
 
 
 /**
@@ -245,6 +241,7 @@ public class DefaultMaintenanceInformati
      */
     @Deprecated
     public void setDateOfNextUpdate(final Date newValue) {
+        checkWritePermission();
         if (newValue != null) {
             if (maintenanceDates != null) {
                 for (final CitationDate date : maintenanceDates) {
@@ -315,48 +312,40 @@ public class DefaultMaintenanceInformati
     @Override
     @Deprecated
     @XmlElement(name = "updateScope")
-    public Collection<ScopeCode> getUpdateScopes() {
-        final Collection<Scope> scopes = getMaintenanceScopes();
-        if (scopes == null) {
-            return null; // May happen at marshalling time.
-        }
-        return new LegacyProperties<ScopeCode,Scope>(scopes) {
-            @Override protected Scope wrap(final ScopeCode code) {
-                return new DefaultScope(code);
+    public final Collection<ScopeCode> getUpdateScopes() {
+        return new LegacyProperties<ScopeCode,Scope>(getMaintenanceScopes()) {
+            /** Stores a legacy value into the new kind of value. */
+            @Override protected Scope wrap(final ScopeCode value) {
+                return new DefaultScope(value);
+            }
+
+            /** Extracts the legacy value from the new kind of value. */
+            @Override protected ScopeCode unwrap(final Scope container) {
+                return container.getLevel();
             }
 
-            @Override protected ScopeCode unwrap(final Scope scope) {
-                return scope.getLevel();
+            /** Updates the legacy value in an existing new kind of value. */
+            @Override protected boolean update(final Scope container, final ScopeCode value)
{
+                if (container instanceof DefaultScope) {
+                    ((DefaultScope) container).setLevel(value);
+                    return true;
+                }
+                return false;
             }
-        };
+        }.validOrNull();
     }
 
     /**
      * Sets the scope of data to which maintenance is applied.
      *
      * @param newValues The new update scopes.
+     *
+     * @deprecated Replaced by {@link #setMaintenanceScopes(Collection)}.
      */
     @Deprecated
-    public void setUpdateScopes(Collection<? extends ScopeCode> newValues) {
-        if (newValues == null) {
-            newValues = Collections.emptySet();
-        }
-        final Iterator<? extends ScopeCode> it = newValues.iterator();
-        final Collection<Scope> scopes = getMaintenanceScopes();
-        final Iterator<Scope> im = scopes.iterator();
-        while (im.hasNext()) {
-            final Scope scope = im.next();
-            if (scope instanceof DefaultScope) {
-                final DefaultScope df = (DefaultScope) scope;
-                df.setLevel(it.hasNext() ? it.next() : null);
-                if (df.isEmpty()) {
-                    im.remove();
-                }
-            }
-        }
-        while (it.hasNext()) {
-            scopes.add(new DefaultScope(it.next()));
-        }
+    public void setUpdateScopes(final Collection<? extends ScopeCode> newValues) {
+        checkWritePermission();
+        ((LegacyProperties<ScopeCode,?>) getUpdateScopes()).setValues(newValues);
     }
 
     /**
@@ -371,64 +360,43 @@ public class DefaultMaintenanceInformati
     @Override
     @Deprecated
     @XmlElement(name = "updateScopeDescription")
-    public Collection<ScopeDescription> getUpdateScopeDescriptions() {
-        final Collection<Scope> scopes = getMaintenanceScopes();
-        if (scopes == null) {
-            return null; // May happen at marshalling time.
-        }
-        return new LegacyProperties<ScopeDescription,Scope>(scopes) {
-            private boolean warningOccurred;
+    public final Collection<ScopeDescription> getUpdateScopeDescriptions() {
+        return new LegacyProperties<ScopeDescription,Scope>(getMaintenanceScopes())
{
+            /** Stores a legacy value into the new kind of value. */
+            @Override protected Scope wrap(final ScopeDescription value) {
+                final DefaultScope container = new DefaultScope();
+                container.setLevelDescription(asCollection(value));
+                return container;
+            }
 
-            @Override protected Scope wrap(final ScopeDescription code) {
-                final DefaultScope scope = new DefaultScope();
-                scope.setLevelDescription(Collections.singleton(code));
-                return scope;
+            /** 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");
             }
 
-            @Override protected ScopeDescription unwrap(final Scope scope) {
-                final Iterator<? extends ScopeDescription> it = scope.getLevelDescription().iterator();
-                if (!it.hasNext()) {
-                    return null;
+            /** Updates the legacy value in an existing new kind of value. */
+            @Override protected boolean update(final Scope container, final ScopeDescription
value) {
+                if (container instanceof DefaultScope) {
+                    ((DefaultScope) container).setLevelDescription(asCollection(value));
+                    return true;
                 }
-                final ScopeDescription description = it.next();
-                if (!warningOccurred && it.hasNext()) {
-                    warningOccurred = true;
-                    MetadataUtilities.warning(DefaultMaintenanceInformation.class, "getUpdateScopeDescriptions",
-                            Messages.Keys.IgnoredPropertiesAfterFirst_1, ScopeDescription.class);
-                }
-                return description;
+                return false;
             }
-        };
+        }.validOrNull();
     }
 
     /**
      * Sets additional information about the range or extent of the resource.
      *
      * @param newValues The new update scope descriptions.
+     *
+     * @deprecated Replaced by {@link #setMaintenanceScopes(Collection)}.
      */
     @Deprecated
-    public void setUpdateScopeDescriptions(Collection<? extends ScopeDescription> newValues)
{
-        if (newValues == null) {
-            newValues = Collections.emptySet();
-        }
-        final Iterator<? extends ScopeDescription> it = newValues.iterator();
-        final Collection<Scope> scopes = getMaintenanceScopes();
-        final Iterator<Scope> im = scopes.iterator();
-        while (im.hasNext()) {
-            final Scope scope = im.next();
-            if (scope instanceof DefaultScope) {
-                final DefaultScope df = (DefaultScope) scope;
-                df.setLevelDescription(it.hasNext() ? Collections.singleton(it.next()) :
null);
-                if (df.isEmpty()) {
-                    im.remove();
-                }
-            }
-        }
-        while (it.hasNext()) {
-            final DefaultScope scope = new DefaultScope();
-            scope.setLevelDescription(Collections.singleton(it.next()));
-            scopes.add(scope);
-        }
+    public void setUpdateScopeDescriptions(final Collection<? extends ScopeDescription>
newValues) {
+        checkWritePermission();
+        ((LegacyProperties<ScopeDescription,?>) getUpdateScopeDescriptions()).setValues(newValues);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java?rev=1605797&r1=1605796&r2=1605797&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java
[UTF-8] Thu Jun 26 14:30:27 2014
@@ -40,7 +40,7 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.05)
- * @version 0.3
+ * @version 0.5
  * @module
  */
 @DependsOn({PropertyAccessorTest.class, PropertyInformationTest.class})
@@ -87,7 +87,7 @@ public final strictfp class InformationM
                 descriptions.get("cloudCoverPercentage").getDefinition().toString(Locale.ENGLISH));
 
         assertEquals("Testing a property inherited from the CoverageDescription parent.",
-                "Type of information represented by the cell value.",
-                descriptions.get("contentType").getDefinition().toString(Locale.ENGLISH));
+                "Description of the attribute described by the measurement value.",
+                descriptions.get("attributeDescription").getDefinition().toString(Locale.ENGLISH));
     }
 }

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java?rev=1605797&r1=1605796&r2=1605797&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
[UTF-8] Thu Jun 26 14:30:27 2014
@@ -162,14 +162,16 @@ public final strictfp class TreeTableFor
         final String text = format.format(image.asTreeTable());
         assertMultilinesEquals(
             "Image description\n" +
-            "  ├─Dimension (1 of 2)\n" +
-            "  │   ├─Max value…………… 0.26\n" +
-            "  │   ├─Min value…………… 0.25\n" +
-            "  │   └─Units……………………… cm\n" +
-            "  └─Dimension (2 of 2)\n" +
-            "      ├─Max value…………… 0.29\n" +
-            "      ├─Min value…………… 0.28\n" +
-            "      └─Units……………………… cm\n", text);
+            "  ├─Attribute group (1 of 2)\n" +
+            "  │   └─Group attribute\n" +
+            "  │       ├─Max value………………… 0.26\n" +
+            "  │       ├─Min value………………… 0.25\n" +
+            "  │       └─Units…………………………… cm\n" +
+            "  └─Attribute group (2 of 2)\n" +
+            "      └─Group attribute\n" +
+            "          ├─Max value………………… 0.29\n" +
+            "          ├─Min value………………… 0.28\n" +
+            "          └─Units…………………………… cm\n", text);
     }
 
     /**

Modified: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1605797&r1=1605796&r2=1605797&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
[UTF-8] Thu Jun 26 14:30:27 2014
@@ -81,6 +81,7 @@ public final strictfp class MetadataRead
      * The given metadata shall have been created from the {@link #NCEP} dataset.
      */
     static void compareToExpected(final Metadata actual) {
+        final String text = formatNameAndValue(DefaultMetadata.castOrCopy(actual).asTreeTable());
         assertMultilinesEquals(
             "Metadata\n" +
             "  ├─File identifier…………………………………………………………………………
edu.ucar.unidata:NCEP/SST/Global_5x2p5deg/SST_Global_5x2p5deg_20050922_0000.nc\n" +
@@ -139,13 +140,13 @@ public final strictfp class MetadataRead
             "  │           ├─Minimum value………………………………………………
0.0\n" +
             "  │           └─Maximum value………………………………………………
0.0\n" +
             "  ├─Content info\n" +
-            "  │   └─Dimension\n" +
-            "  │       ├─Sequence identifier…………………………………………
SST\n" +
-            "  │       └─Descriptor…………………………………………………………………
Sea temperature\n" +
+            "  │   └─Attribute group\n" +
+            "  │       └─Group attribute\n" +
+            "  │           ├─Sequence identifier………………………………
SST\n" +
+            "  │           └─Descriptor………………………………………………………
Sea temperature\n" +
             "  └─Data quality info\n" +
             "      └─Lineage\n" +
             "          └─Statement……………………………………………………………………
2003-04-07 12:12:50 - created by gribtocdl" +
-            "              2005-09-26T21:50:00 - edavis - add attributes for dataset discovery\n",
-        formatNameAndValue(DefaultMetadata.castOrCopy(actual).asTreeTable()));
+            "              2005-09-26T21:50:00 - edavis - add attributes for dataset discovery\n",
text);
     }
 }



Mime
View raw message