sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Fix a NullPointerException in call to setIdentifier(Identifier) by MetadataVisitor.
Date Mon, 02 Jul 2018 18:10:25 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 8aa6eee  Fix a NullPointerException in call to setIdentifier(Identifier) by MetadataVisitor.
8aa6eee is described below

commit 8aa6eeefc2b7358d1341438ac1b21325d486304b
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Jul 2 20:00:02 2018 +0200

    Fix a NullPointerException in call to setIdentifier(Identifier) by MetadataVisitor.
---
 .../sis/internal/jaxb/NonMarshalledAuthority.java     | 16 +++++++++++-----
 .../org/apache/sis/metadata/iso/DefaultMetadata.java  |  4 +---
 .../java/org/apache/sis/metadata/iso/ISOMetadata.java | 19 +++++++++++++++++++
 .../sis/metadata/iso/acquisition/DefaultEvent.java    |  5 ++---
 .../metadata/iso/acquisition/DefaultInstrument.java   |  5 ++---
 .../metadata/iso/acquisition/DefaultOperation.java    |  5 ++---
 .../sis/metadata/iso/acquisition/DefaultPlatform.java |  5 ++---
 .../metadata/iso/acquisition/DefaultPlatformPass.java |  5 ++---
 .../metadata/iso/acquisition/DefaultRequirement.java  |  5 ++---
 .../sis/metadata/iso/distribution/DefaultMedium.java  |  5 ++---
 .../iso/identification/DefaultCoupledResource.java    | 10 ++++++++--
 .../sis/metadata/iso/lineage/DefaultProcessing.java   |  5 ++---
 12 files changed, 55 insertions(+), 34 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
index d0eb1fb..24f1af4 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
@@ -61,7 +61,7 @@ import org.apache.sis.xml.IdentifierSpace;
  * }
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 1.0
  *
  * @param <T>  the type of object used as identifier values.
  *
@@ -138,13 +138,18 @@ public final class NonMarshalledAuthority<T> extends CitationConstant.Authority<
      * <p>This method is used for implementation of {@code setIdentifier(Identifier)}
methods
      * in public metadata objects.</p>
      *
-     * @param <T>          the type of object used as identifier values.
-     * @param identifiers  the collection in which to add the identifier.
-     * @param newValue     the identifier to add, or {@code null}.
+     * @param  <T>          the type of object used as identifier values.
+     * @param  identifiers  the collection in which to add the identifier.
+     * @param  newValue     the identifier to add, or {@code null}.
+     * @return the given collection, or a new collection if the given collection was {@code
null}.
      *
      * @see #setMarshallables(Collection, Collection)
      */
-    public static <T extends Identifier> void setMarshallable(final Collection<T>
identifiers, final T newValue) {
+    public static <T extends Identifier> Collection<T> setMarshallable(final
Collection<T> identifiers, final T newValue) {
+        if (identifiers == null) {
+            // This may happen during MetadataVisitor execution.
+            return CollectionsExt.singletonOrEmpty(newValue);
+        }
         final Iterator<T> it = identifiers.iterator();
         while (it.hasNext()) {
             final T old = it.next();
@@ -156,6 +161,7 @@ public final class NonMarshalledAuthority<T> extends CitationConstant.Authority<
         if (newValue != null) {
             identifiers.add(newValue);
         }
+        return identifiers;
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
index c631e85..75a18f7 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
@@ -429,9 +429,7 @@ public class DefaultMetadata extends ISOMetadata implements Metadata {
      * @since 0.5
      */
     public void setMetadataIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
index 57fb03a..da47139 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
@@ -32,6 +32,7 @@ import org.apache.sis.metadata.MetadataStandard;
 import org.apache.sis.metadata.ModifiableMetadata;
 import org.apache.sis.internal.jaxb.IdentifierMapAdapter;
 import org.apache.sis.internal.jaxb.ModifiableIdentifierMap;
+import org.apache.sis.internal.jaxb.NonMarshalledAuthority;
 import org.apache.sis.internal.metadata.MetadataUtilities;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.internal.system.Modules;
@@ -164,6 +165,24 @@ public class ISOMetadata extends ModifiableMetadata implements IdentifiedObject,
                                               : new IdentifierMapAdapter(identifiers);
     }
 
+    /**
+     * Sets the identifier for metadata objects that are expected to contain at most one
ISO 19115-1 identifier.
+     * This convenience method is used for implementation of public {@link setIdentifier(Identifier)}
methods in
+     * subclasses having a [0 … 1] cardinality for the {@code identifier} property.
+     *
+     * <p>The default implementation removes all identifiers that are not ISO 19115-3
identifiers before to add
+     * the given one in the {@link #identifiers} collection.</p>
+     *
+     * @param  newValue  the new identifier value, or {@code null} for removing the ISO
19115-1 identifier.
+     *
+     * @since 1.0
+     */
+    protected void setIdentifier(final Identifier newValue) {
+        checkWritePermission();
+        identifiers = nonNullCollection(identifiers, Identifier.class);
+        identifiers = writeCollection(NonMarshalledAuthority.setMarshallable(identifiers,
newValue), identifiers, Identifier.class);
+    }
+
     // --------------------------------------------------------------------------------------
     // End of identifier methods.
     // --------------------------------------------------------------------------------------
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEvent.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEvent.java
index 0da2a65..39f3e27 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEvent.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEvent.java
@@ -185,10 +185,9 @@ public class DefaultEvent extends ISOMetadata implements Event {
      *
      * @param  newValue  the event identifier value.
      */
+    @Override
     public void setIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultInstrument.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultInstrument.java
index 4268f81..c254041 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultInstrument.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultInstrument.java
@@ -174,10 +174,9 @@ public class DefaultInstrument extends ISOMetadata implements Instrument
{
      *
      * @param  newValue  the new identifier value.
      */
+    @Override
     public void setIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultOperation.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultOperation.java
index 4436a06..78f790a 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultOperation.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultOperation.java
@@ -246,10 +246,9 @@ public class DefaultOperation extends ISOMetadata implements Operation
{
      *
      * @param  newValue  the new identifier value.
      */
+    @Override
     public void setIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultPlatform.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultPlatform.java
index 82c7cc1..fe4451a 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultPlatform.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultPlatform.java
@@ -179,10 +179,9 @@ public class DefaultPlatform extends ISOMetadata implements Platform
{
      *
      * @param  newValue  the new identifier value.
      */
+    @Override
     public void setIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultPlatformPass.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultPlatformPass.java
index 7b4ad7c..e26f716 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultPlatformPass.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultPlatformPass.java
@@ -138,10 +138,9 @@ public class DefaultPlatformPass extends ISOMetadata implements PlatformPass
{
      *
      * @param  newValue  the new identifier value.
      */
+    @Override
     public void setIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultRequirement.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultRequirement.java
index 2acc982..a3886d6 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultRequirement.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultRequirement.java
@@ -214,10 +214,9 @@ public class DefaultRequirement extends ISOMetadata implements Requirement
{
      *
      * @param  newValue  the new identifier value.
      */
+    @Override
     public void setIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
index 2979b9c..31c0691 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
@@ -386,9 +386,8 @@ public class DefaultMedium extends ISOMetadata implements Medium {
      *
      * @since 0.5
      */
+    @Override
     public void setIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 }
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java
index 2de0499..c892b85 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java
@@ -287,8 +287,7 @@ public class DefaultCoupledResource extends ISOMetadata implements CoupledResour
 
     /**
      * Returns the resource identifier, which is assumed to be the name as a string.
-     * Used in legacy ISO 19139:2007 documents. There is no setter method; we expect
-     * the XML to declare {@code <srv:operationName>} instead.
+     * Used in legacy ISO 19139:2007 documents.
      */
     @XmlElement(name = "identifier", namespace = LegacyNamespaces.SRV)
     private String getIdentifier() {
@@ -302,6 +301,13 @@ public class DefaultCoupledResource extends ISOMetadata implements CoupledResour
     }
 
     /**
+     * Handled as a synonymous of {@code <srv:operationName>}.
+     */
+    private void setIdentifier(final String identifier) {
+        setOperationName(identifier);
+    }
+
+    /**
      * Returns the {@code <gco:ScopedName>} element to marshal in legacy ISO 19139:2007
element.
      * The {@code <srv:scopedName>} element wrapper (note the lower-case "s") was missing
in that
      * legacy specification. This departure from ISO patterns has been fixed in ISO 19115-3:2016.
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java
index a3a6db9..c9896fc 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java
@@ -162,10 +162,9 @@ public class DefaultProcessing extends ISOMetadata implements Processing
{
      *
      * @param  newValue  the new identifier value.
      */
+    @Override
     public void setIdentifier(final Identifier newValue) {
-        checkWritePermission();
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        NonMarshalledAuthority.setMarshallable(identifiers, newValue);
+        super.setIdentifier(newValue);
     }
 
     /**


Mime
View raw message