sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1631453 - in /sis/branches/JDK8/core/sis-metadata/src: main/java/org/apache/sis/metadata/iso/ main/java/org/apache/sis/metadata/iso/maintenance/ test/java/org/apache/sis/metadata/iso/
Date Mon, 13 Oct 2014 16:03:10 GMT
Author: desruisseaux
Date: Mon Oct 13 16:03:10 2014
New Revision: 1631453

URL: http://svn.apache.org/r1631453
Log:
Bug fix in ScopeAdapter: the value was lost if the MetadataScope was not an instance of DefaultMetadataScope.
This bug has been identified by the port to trunk (it has not been identified by the tests
on the JDK8 branch,
but the fact that the tests on trunk sometime follow a different code path has made this bug
visible).

Added:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.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/metadata/iso/DefaultMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java?rev=1631453&r1=1631452&r2=1631453&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] Mon Oct 13 16:03:10 2014
@@ -260,8 +260,7 @@ public class DefaultMetadata extends ISO
      *
      * @param contact   Party responsible for the metadata information.
      * @param dateStamp Date that the metadata was created.
-     * @param identificationInfo Basic information about the resource
-     *        to which the metadata applies.
+     * @param identificationInfo Basic information about the resource to which the metadata
applies.
      */
     public DefaultMetadata(final Responsibility contact,
                            final Date           dateStamp,
@@ -542,7 +541,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "characterSet")
-    public final Charset getCharacterSet()  {
+    public final Charset getCharacterSet() {
         return LegacyPropertyAdapter.getSingleton(characterSets, Charset.class, null, DefaultMetadata.class,
"getCharacterSet");
     }
 
@@ -646,40 +645,6 @@ public class DefaultMetadata extends ISO
     }
 
     /**
-     * A specialization of {@link LegacyPropertyAdapter} which will try to merge the
-     * {@code "hierarchyLevel"} and {@code "hierarchyLevelName"} properties in the same
-     * {@link DefaultMetadataScope} instance.
-     */
-    private static abstract class ScopeAdapter<L> extends LegacyPropertyAdapter<L,MetadataScope>
{
-        /**
-         * @param scopes Value of {@link DefaultMetadata#getMetadataScopes()}.
-         */
-        ScopeAdapter(final Collection<MetadataScope> scopes)  {
-            super(scopes);
-        }
-
-        /**
-         * Invoked (indirectly) by JAXB when adding a new scope code or scope name. This
implementation searches
-         * for an existing {@link MetadataScope} instance with a free slot for the new value
before to create a
-         * new {@link DefaultMetadataScope} instance.
-         */
-        @Override
-        public boolean add(final L newValue) {
-            final Iterator<MetadataScope> it = elements.iterator();
-            if (it.hasNext()) {
-                MetadataScope scope = it.next();
-                if (unwrap(scope) == null) {
-                    if (!(scope instanceof DefaultMetadataScope)) {
-                        scope = new DefaultMetadataScope(scope);
-                    }
-                    return update(scope, newValue);
-                }
-            }
-            return super.add(newValue);
-        }
-    }
-
-    /**
      * Returns the scope to which the metadata applies.
      *
      * @return Scope to which the metadata applies.
@@ -691,7 +656,7 @@ public class DefaultMetadata extends ISO
     @Deprecated
     @XmlElement(name = "hierarchyLevel")
     public final Collection<ScopeCode> getHierarchyLevels() {
-        return new ScopeAdapter<ScopeCode>(getMetadataScopes()) {
+        return new MetadataScopeAdapter<ScopeCode>(getMetadataScopes()) {
             /** Stores a legacy value into the new kind of value. */
             @Override protected MetadataScope wrap(final ScopeCode value) {
                 return new DefaultMetadataScope(value);
@@ -739,7 +704,7 @@ public class DefaultMetadata extends ISO
     @Deprecated
     @XmlElement(name = "hierarchyLevelName")
     public final Collection<String> getHierarchyLevelNames() {
-        return new ScopeAdapter<String>(getMetadataScopes()) {
+        return new MetadataScopeAdapter<String>(getMetadataScopes()) {
             /** Stores a legacy value into the new kind of value. */
             @Override protected MetadataScope wrap(final String value) {
                 final DefaultMetadataScope scope = new DefaultMetadataScope();
@@ -756,7 +721,7 @@ public class DefaultMetadata extends ISO
             /** Updates the legacy value in an existing instance of the new kind of value.
*/
             @Override protected boolean update(final MetadataScope container, final String
value) {
                 if (container instanceof DefaultMetadataScope) {
-                    ((DefaultMetadataScope) container).setName(new SimpleInternationalString(value));
+                    ((DefaultMetadataScope) container).setName(value != null ? new SimpleInternationalString(value)
: null);
                     return true;
                 }
                 return false;

Added: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java?rev=1631453&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java
(added)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java
[UTF-8] Mon Oct 13 16:03:10 2014
@@ -0,0 +1,94 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Iterator;
+import java.util.Collection;
+import java.util.ConcurrentModificationException;
+import org.opengis.metadata.MetadataScope;
+import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+
+
+/**
+ * A specialization of {@link LegacyPropertyAdapter} which will try to merge the
+ * {@code "hierarchyLevel"} and {@code "hierarchyLevelName"} properties in the same
+ * {@link DefaultMetadataScope} instance.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+abstract class MetadataScopeAdapter<L> extends LegacyPropertyAdapter<L,MetadataScope>
{
+    /**
+     * @param scopes Value of {@link DefaultMetadata#getMetadataScopes()}.
+     */
+    MetadataScopeAdapter(final Collection<MetadataScope> scopes) {
+        super(scopes);
+    }
+
+    /**
+     * Invoked (indirectly) by JAXB when adding a new scope code or scope name. This implementation
searches
+     * for an existing {@link MetadataScope} instance with a free slot for the new value
before to create a
+     * new {@link DefaultMetadataScope} instance.
+     */
+    @Override
+    public boolean add(final L newValue) {
+        int n = 0;
+        final Iterator<MetadataScope> it = elements.iterator();
+        while (it.hasNext()) {
+            MetadataScope scope = it.next();
+            if (unwrap(scope) != null) {
+                n++;
+                continue;
+            }
+            /*
+             * We found a free slot. If the slot is a metadata that we can modify (which
is the usual case),
+             * we will be allowed to update that instance directly - no change needed in
the backing collection.
+             * But if the metadata is not modifiable, then we will need to clone it and replaces
the element in
+             * the collection.
+             */
+            if (!(scope instanceof DefaultMetadataScope) || !((DefaultMetadataScope) scope).isModifiable())
{
+                scope = new DefaultMetadataScope(scope);
+                if (elements instanceof List<?>) {
+                    ((List<MetadataScope>) elements).set(n, scope);
+                } else {
+                    /*
+                     * Not a list. Delete all the remaining parts, substitute the value
+                     * and reinsert everything in the same order.
+                     */
+                    final MetadataScope[] remaining = new MetadataScope[elements.size() -
n];
+                    remaining[0] = scope;
+                    n = 1;
+                    it.remove();
+                    while (it.hasNext()) {
+                        remaining[n++] = it.next();
+                        it.remove();
+                    }
+                    if (n != remaining.length) { // Paranoiac check.
+                        throw new ConcurrentModificationException();
+                    }
+                    elements.addAll(Arrays.asList(remaining));
+                }
+            }
+            return update(scope, newValue);
+        }
+        return super.add(newValue);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java?rev=1631453&r1=1631452&r2=1631453&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
[UTF-8] Mon Oct 13 16:03:10 2014
@@ -298,11 +298,11 @@ public class DefaultScopeDescription ext
      * “<cite>Administrative area A — Road network</cite>” description.
      * </div>
      *
-     * @return Feature types to which the information applies.
-     *
      * {@section Conditions}
      * This method returns a modifiable collection only if no other property is set.
      * Otherwise, this method returns an unmodifiable empty collection.
+     *
+     * @return Feature types to which the information applies.
      */
     @Override
     public Set<CharSequence> getFeatures() {
@@ -331,11 +331,11 @@ public class DefaultScopeDescription ext
      * “<cite>Administrative area A — Overhead clearance</cite>” description.
      * </div>
      *
-     * @return Attribute types to which the information applies.
-     *
      * {@section Conditions}
      * This method returns a modifiable collection only if no other property is set.
      * Otherwise, this method returns an unmodifiable empty collection.
+     *
+     * @return Attribute types to which the information applies.
      */
     @Override
     public Set<CharSequence> getAttributes() {
@@ -364,11 +364,11 @@ public class DefaultScopeDescription ext
      * “<cite>Administrative area A — New bridge</cite>” description.
      * </div>
      *
-     * @return Feature instances to which the information applies.
-     *
      * {@section Conditions}
      * This method returns a modifiable collection only if no other property is set.
      * Otherwise, this method returns an unmodifiable empty collection.
+     *
+     * @return Feature instances to which the information applies.
      */
     @Override
     public Set<CharSequence> getFeatureInstances() {
@@ -397,11 +397,11 @@ public class DefaultScopeDescription ext
      * “<cite>Administrative area A — New bridge — Overhead clearance</cite>”
description.
      * </div>
      *
-     * @return Attribute instances to which the information applies.
-     *
      * {@section Conditions}
      * This method returns a modifiable collection only if no other property is set.
      * Otherwise, this method returns an unmodifiable empty collection.
+     *
+     * @return Attribute instances to which the information applies.
      */
     @Override
     public Set<CharSequence> getAttributeInstances() {

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=1631453&r1=1631452&r2=1631453&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 Oct 13 16:03:10 2014
@@ -239,7 +239,7 @@ public final strictfp class AllMetadataT
         } else if (name.equals("stepDateTime")) {
             name = "dateTime";
         } else if (name.equals("defaultLocale+otherLocale") ||
-                   type == FeatureCatalogueDescription.class && name.equals("locale"))
+                type == FeatureCatalogueDescription.class && name.equals("locale"))
         {
             name = "language";
         }



Mime
View raw message