sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1631981 - in /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata: AbstractMetadata.java Pruner.java
Date Wed, 15 Oct 2014 09:43:59 GMT
Author: desruisseaux
Date: Wed Oct 15 09:43:59 2014
New Revision: 1631981

URL: http://svn.apache.org/r1631981
Log:
Make 'prune()' and 'isEmpty()' operations tolerant to metadata properties of unknown type.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java?rev=1631981&r1=1631980&r2=1631981&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] Wed Oct 15 09:43:59 2014
@@ -144,7 +144,7 @@ public abstract class AbstractMetadata i
      */
     @Override
     public boolean isEmpty() {
-        return Pruner.isEmpty(this, false);
+        return Pruner.isEmpty(this, true, false);
     }
 
     /**
@@ -155,7 +155,7 @@ public abstract class AbstractMetadata i
      * @throws UnmodifiableMetadataException If this metadata is not modifiable.
      */
     public void prune() {
-        Pruner.isEmpty(this, true);
+        Pruner.isEmpty(this, true, true);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java?rev=1631981&r1=1631980&r2=1631981&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java
[UTF-8] Wed Oct 15 09:43:59 2014
@@ -57,8 +57,14 @@ final class Pruner {
      * Returns the metadata properties. When used for pruning empty values, the map needs
to
      * include empty (but non-null) values in order to allow us to set them to {@code null}.
      */
-    private static Map<String, Object> asMap(final MetadataStandard standard, final
Object metadata, final boolean prune) {
-        return standard.asValueMap(metadata, KeyNamePolicy.JAVABEANS_PROPERTY, prune ? NON_NULL
: NON_EMPTY);
+    private static Map<String, Object> asMap(final MetadataStandard standard, final
Object metadata,
+            final boolean mandatory, final boolean prune)
+    {
+        final PropertyAccessor accessor = standard.getAccessor(metadata.getClass(), mandatory);
+        if (accessor != null) {
+            return new ValueMap(metadata, accessor, KeyNamePolicy.JAVABEANS_PROPERTY, prune
? NON_NULL : NON_EMPTY);
+        }
+        return null;
     }
 
     /**
@@ -78,12 +84,16 @@ final class Pruner {
      * It creates a map of visited nodes when the iteration begin, and deletes that map when
the
      * iteration ends.</p>
      *
-     * @param  metadata The metadata object.
-     * @param  prune {@code true} for deleting empty entries.
+     * @param  metadata  The metadata object.
+     * @param  mandatory {@code true} if we shall throw an exception if {@code metadata}
is not of the expected class.
+     * @param  prune     {@code true} for deleting empty entries.
      * @return {@code true} if all metadata properties are null or empty.
      */
-    static boolean isEmpty(final AbstractMetadata metadata, final boolean prune) {
-        final Map<String,Object> properties = asMap(metadata.getStandard(), metadata,
prune);
+    static boolean isEmpty(final AbstractMetadata metadata, final boolean mandatory, final
boolean prune) {
+        final Map<String,Object> properties = asMap(metadata.getStandard(), metadata,
mandatory, prune);
+        if (properties == null) {
+            return false; // For metadata of unknown class, conservatively assume non-empty.
+        }
         final Map<Object,Boolean> tested = MAPS.get();
         if (!tested.isEmpty()) {
             return isEmpty(properties, tested, prune);
@@ -165,7 +175,7 @@ final class Pruner {
                         } else if (!(element instanceof Enumerated)) {
                             final MetadataStandard standard = MetadataStandard.forClass(element.getClass());
                             if (standard != null) {
-                                isEmptyElement = isEmpty(asMap(standard, element, prune),
tested, prune);
+                                isEmptyElement = isEmpty(asMap(standard, element, false,
prune), tested, prune);
                                 if (!isEmptyElement && element instanceof Emptiable)
{
                                     isEmptyElement = ((Emptiable) element).isEmpty();
                                 }



Mime
View raw message