sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1810214 - in /sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature: DefaultAssociationRole.java DefaultFeatureType.java
Date Sat, 30 Sep 2017 15:20:44 GMT
Author: desruisseaux
Date: Sat Sep 30 15:20:43 2017
New Revision: 1810214

URL: http://svn.apache.org/viewvc?rev=1810214&view=rev
Log:
Avoid invoking user-overrideable DefaultFeatureType.getProperties(boolean) during construction.

Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java?rev=1810214&r1=1810213&r2=1810214&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java
[UTF-8] Sat Sep 30 15:20:43 2017
@@ -19,6 +19,7 @@ package org.apache.sis.feature;
 import java.util.Map;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.IdentityHashMap;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
@@ -216,10 +217,14 @@ public class DefaultAssociationRole exte
      * to feature <var>B</var> which has an association back to <var>A</var>.
It may also be <var>A</var>
      * having an association to itself, <i>etc.</i>
      *
-     * @param  creating  the feature type in process of being constructed.
+     * @param  creating    the feature type in process of being constructed.
+     * @param  properties  {@code creating.getProperties(false)} given as a direct reference
to the internal field,
+     *         without invoking {@code getProperties(…)}. We do that because {@code resolve(…)}
is invoked while the
+     *         given {@code DefaultFeatureType} is under creation. Since {@code getProperties(…)}
can be overridden,
+     *         invoking that method on {@code creating} may cause a failure with user code.
      * @return {@code true} if this association references a resolved feature type after
this method call.
      */
-    final boolean resolve(final DefaultFeatureType creating) {
+    final boolean resolve(final DefaultFeatureType creating, final Collection<PropertyType>
properties) {
         final FeatureType type = valueType;
         if (type instanceof NamedFeatureType) {
             FeatureType resolved = ((NamedFeatureType) type).resolved;
@@ -234,7 +239,7 @@ public class DefaultAssociationRole exte
                      * the 'creating' feature itself. This is a little bit unusual, but not
illegal.
                      */
                     final List<FeatureType> deferred = new ArrayList<>();
-                    resolved = search(creating, name, deferred);
+                    resolved = search(creating, properties, name, deferred);
                     if (resolved == null) {
                         /*
                          * Did not found the desired FeatureType in the 'creating' instance.
@@ -261,19 +266,25 @@ public class DefaultAssociationRole exte
      * <p>Current implementation does not check that there is no duplicated names.
      * See {@link #deepSearch(List, GenericName)} for a rational.</p>
      *
-     * @param  feature   the feature in which to search.
-     * @param  name      the name of the feature to search.
-     * @param  deferred  where to store {@code FeatureType}s to be eventually used for a
deep search.
+     * @param  feature     the feature in which to search.
+     * @param  properties  {@code feature.getProperties(false)}, or {@code null} for letting
this method performing the call.
+     * @param  name        the name of the feature to search.
+     * @param  deferred    where to store {@code FeatureType}s to be eventually used for
a deep search.
      * @return the feature of the given name, or {@code null} if none.
      */
     @SuppressWarnings("null")
-    private static FeatureType search(final FeatureType feature, final GenericName name,
final List<FeatureType> deferred) {
+    private static FeatureType search(final FeatureType feature, Collection<? extends
PropertyType> properties,
+            final GenericName name, final List<FeatureType> deferred)
+    {
         /*
          * Search only in associations declared in the given feature, not in inherited associations.
          * The inherited associations will be checked in a separated loop below if we did
not found
          * the request feature type in explicitly declared associations.
          */
-        for (final PropertyType property : feature.getProperties(false)) {
+        if (properties == null) {
+            properties = feature.getProperties(false);
+        }
+        for (final PropertyType property : properties) {
             if (property instanceof FeatureAssociationRole) {
                 final FeatureType valueType;
                 if (property instanceof DefaultAssociationRole) {
@@ -300,7 +311,7 @@ public class DefaultAssociationRole exte
             if (name.equals(type.getName())) {
                 return type;
             }
-            type = search(type, name, deferred);
+            type = search(type, null, name, deferred);
             if (type != null) {
                 return type;
             }
@@ -309,7 +320,7 @@ public class DefaultAssociationRole exte
     }
 
     /**
-     * Potentially invoked after {@link #search(FeatureType, GenericName, List)} for searching
+     * Potentially invoked after {@link #search(FeatureType, Collection, GenericName, List)}
for searching
      * in associations of associations.
      *
      * <p>Current implementation does not check that there is no duplicated names.
Even if we did so,
@@ -317,7 +328,7 @@ public class DefaultAssociationRole exte
      * later. We rather put a warning in {@link #DefaultAssociationRole(Map, GenericName,
int, int)}
      * javadoc.</p>
      *
-     * @param  deferred  the feature types collected by {@link #search(FeatureType, GenericName,
List)}.
+     * @param  deferred  the feature types collected by {@link #search(FeatureType, Collection,
GenericName, List)}.
      * @param  name      the name of the feature to search.
      * @return the feature of the given name, or {@code null} if none.
      */
@@ -327,7 +338,7 @@ public class DefaultAssociationRole exte
             FeatureType valueType = deferred.get(i++);
             if (done.put(valueType, Boolean.TRUE) == null) {
                 deferred.subList(0, i).clear();                 // Discard previous value
for making more room.
-                valueType = search(valueType, name, deferred);
+                valueType = search(valueType, null, name, deferred);
                 if (valueType != null) {
                     return valueType;
                 }

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java?rev=1810214&r1=1810213&r2=1810214&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] Sat Sep 30 15:20:43 2017
@@ -530,7 +530,7 @@ public class DefaultFeatureType extends
          */
         if (feature instanceof DefaultFeatureType) {
             final DefaultFeatureType dt = (DefaultFeatureType) feature;
-            return dt.isResolved = resolve(feature, dt.properties, previous, dt.isResolved);
+            return dt.isResolved = resolve(dt, dt.properties, previous, dt.isResolved);
         } else {
             return resolve(feature, feature.getProperties(false), previous, feature.isSimple());
         }
@@ -559,7 +559,7 @@ public class DefaultFeatureType extends
             for (final PropertyType property : toUpdate) {
                 if (property instanceof FeatureAssociationRole) {
                     if (property instanceof DefaultAssociationRole) {
-                        if (!((DefaultAssociationRole) property).resolve(this)) {
+                        if (!((DefaultAssociationRole) property).resolve(this, properties))
{
                             resolved = false;
                             continue;
                         }



Mime
View raw message