sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1755515 - in /sis/branches/JDK8/core: sis-feature/src/main/java/org/apache/sis/feature/ sis-feature/src/main/java/org/apache/sis/feature/builder/ sis-feature/src/test/java/org/apache/sis/feature/ sis-utility/src/main/java/org/apache/sis/ut...
Date Mon, 08 Aug 2016 15:56:56 GMT
Author: desruisseaux
Date: Mon Aug  8 15:56:56 2016
New Revision: 1755515

URL: http://svn.apache.org/viewvc?rev=1755515&view=rev
Log:
DefaultFeatureType constructor should verify that the operation does not have a dependency
to a non-existent property.
This commit contains also opportunistic javadoc formatting.

Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractOperation.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractOperation.java?rev=1755515&r1=1755514&r2=1755515&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractOperation.java
[UTF-8] Mon Aug  8 15:56:56 2016
@@ -83,7 +83,7 @@ public abstract class AbstractOperation
      * Constructs an operation from the given properties. The identification map is given
unchanged to
      * the {@linkplain AbstractIdentifiedType#AbstractIdentifiedType(Map) super-class constructor}.
      *
-     * @param identification The name and other information to be given to this operation.
+     * @param  identification  the name and other information to be given to this operation.
      */
     public AbstractOperation(final Map<String,?> identification) {
         super(identification);
@@ -95,7 +95,7 @@ public abstract class AbstractOperation
      * If the given map contains at least one key prefixed by {@value #RESULT_PREFIX}, then
the values
      * associated to those keys will be used.
      *
-     * @param identification the map given by user to sub-class constructor.
+     * @param  identification  the map given by user to sub-class constructor.
      */
     final Map<String,Object> resultIdentification(final Map<String,?> identification)
{
         final Map<String,Object> properties = new HashMap<>(6);
@@ -117,7 +117,7 @@ public abstract class AbstractOperation
     /**
      * Returns a description of the input parameters.
      *
-     * @return Description of the input parameters.
+     * @return description of the input parameters.
      */
     @Override
     public abstract ParameterDescriptorGroup getParameters();
@@ -125,7 +125,7 @@ public abstract class AbstractOperation
     /**
      * Returns the expected result type, or {@code null} if none.
      *
-     * @return The type of the result, or {@code null} if none.
+     * @return the type of the result, or {@code null} if none.
      */
     @Override
     public abstract IdentifiedType getResult();
@@ -151,11 +151,11 @@ public abstract class AbstractOperation
      * in the Java language, and may be {@code null} if the operation does not need a feature
instance
      * (like static methods in the Java language).</div>
      *
-     * @param  feature    The feature on which to execute the operation.
-     *                    Can be {@code null} if the operation does not need feature instance.
-     * @param  parameters The parameters to use for executing the operation.
-     *                    Can be {@code null} if the operation does not take any parameters.
-     * @return The operation result, or {@code null} if this operation does not produce any
result.
+     * @param  feature     the feature on which to execute the operation.
+     *                     Can be {@code null} if the operation does not need feature instance.
+     * @param  parameters  the parameters to use for executing the operation.
+     *                     Can be {@code null} if the operation does not take any parameters.
+     * @return the operation result, or {@code null} if this operation does not produce any
result.
      */
     @Override
     public abstract Property apply(Feature feature, ParameterValueGroup parameters);
@@ -174,7 +174,7 @@ public abstract class AbstractOperation
      *
      * The default implementation returns an empty set.
      *
-     * @return The names of feature properties needed by this operation for performing its
task.
+     * @return the names of feature properties needed by this operation for performing its
task.
      */
     public Set<String> getDependencies() {
         return Collections.emptySet();
@@ -256,7 +256,7 @@ public abstract class AbstractOperation
      * Appends a string representation of the "formula" used for computing the result.
      * The "formula" may be for example a link to another property.
      *
-     * @param  buffer where to format the "formula".
+     * @param  buffer  where to format the "formula".
      * @return {@code true} if this method has formatted a formula, or {@code false} otherwise.
      */
     boolean formatResultFormula(Appendable buffer) {

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=1755515&r1=1755514&r2=1755515&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] Mon Aug  8 15:56:56 2016
@@ -283,6 +283,21 @@ public class DefaultFeatureType extends
             case 1:  this.properties = Collections.singletonList(sourceProperties.get(0));
break;
             default: this.properties = UnmodifiableArrayList.wrap(sourceProperties.toArray(new
PropertyType[size])); break;
         }
+        /*
+         * Before to resolve cyclic associations, verify that operations depend only on existing
properties.
+         * Note: the 'allProperties' collection has been created by computeTransientFields(…)
above.
+         */
+        for (final PropertyType property : allProperties) {
+            if (property instanceof AbstractOperation) {
+                for (final String dependency : ((AbstractOperation) property).getDependencies())
{
+                    if (!byName.containsKey(dependency)) {
+                        throw new IllegalArgumentException(Errors.format(Errors.Keys.DependencyNotFound_3,
+                                property.getName(), dependency, super.getName()));
+                    }
+                }
+            }
+        }
+        // Do not invoke before DefaultFeatureType construction succeed.
         isResolved = resolve(this, this.properties, null, isSimple);
     }
 

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java?rev=1755515&r1=1755514&r2=1755515&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java
[UTF-8] Mon Aug  8 15:56:56 2016
@@ -658,8 +658,9 @@ public final class AttributeTypeBuilder<
      */
     @Override
     public void remove() {
-        if (isIdentifier && owner()!=null) {
-            owner().identifierCount--;
+        if (isIdentifier) {
+            isIdentifier = false;
+            owner().identifierCount--;      // Owner should never be null since we set 'isIdentifier'
to false.
         }
         super.remove();
     }

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java?rev=1755515&r1=1755514&r2=1755515&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] Mon Aug  8 15:56:56 2016
@@ -362,6 +362,33 @@ public final strictfp class DefaultFeatu
     }
 
     /**
+     * Tests inclusion of a property of kind operation.
+     */
+    @Test
+    public void testOperationProperty() {
+        final Map<String,String> featureName = singletonMap(DefaultFeatureType.NAME_KEY,
"Identified city");
+        final Map<String,String> identifierName = singletonMap(DefaultAttributeType.NAME_KEY,
"identifier");
+        final DefaultFeatureType[] parent = {city()};
+        final DefaultFeatureType city = new DefaultFeatureType(featureName, false,
+                parent, new LinkOperation(identifierName, parent[0].getProperty("city")));
+        assertPropertiesEquals(city, true, "city", "population", "identifier");
+        /*
+         * Try to add an operation that depends on a non-existent property.
+         * Such construction shall not be allowed.
+         */
+        final PropertyType parliament = new LinkOperation(identifierName, DefaultAttributeTypeTest.parliament());
+        try {
+            final DefaultFeatureType illegal = new DefaultFeatureType(featureName, false,
parent, parliament);
+            fail("Should not have been allowed to create this feature:\n" + illegal);
+        } catch (IllegalArgumentException e) {
+            final String message = e.getLocalizedMessage();
+            assertTrue(message, message.contains("identifier"));
+            assertTrue(message, message.contains("parliament"));
+            assertTrue(message, message.contains("Identified city"));
+        }
+    }
+
+    /**
      * Tests a feature type which inherit from an other feature type, but without property
overriding.
      *
      * <p>Current implementation performs its tests on the {@link #capital()} feature.</p>

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java?rev=1755515&r1=1755514&r2=1755515&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java
[UTF-8] Mon Aug  8 15:56:56 2016
@@ -68,7 +68,7 @@ public class BackingStoreException exten
     /**
      * Constructs a new exception with the specified detail message.
      *
-     * @param message The detail message, saved for later retrieval by the {@link #getMessage()}
method.
+     * @param message  the detail message, saved for later retrieval by the {@link #getMessage()}
method.
      */
     public BackingStoreException(final String message) {
         super(message);
@@ -77,7 +77,7 @@ public class BackingStoreException exten
     /**
      * Constructs a new exception with the specified cause.
      *
-     * @param cause The cause, saved for later retrieval by the {@link #getCause()} method.
+     * @param cause  the cause, saved for later retrieval by the {@link #getCause()} method.
      */
     public BackingStoreException(final Throwable cause) {
         super(cause);
@@ -86,8 +86,8 @@ public class BackingStoreException exten
     /**
      * Constructs a new exception with the specified detail message and cause.
      *
-     * @param message The detail message, saved for later retrieval by the {@link #getMessage()}
method.
-     * @param cause The cause, saved for later retrieval by the {@link #getCause()} method.
+     * @param message  the detail message, saved for later retrieval by the {@link #getMessage()}
method.
+     * @param cause    the cause, saved for later retrieval by the {@link #getCause()} method.
      */
     public BackingStoreException(final String message, final Throwable cause) {
         super(message, cause);
@@ -118,10 +118,10 @@ public class BackingStoreException exten
      *     }
      * }
      *
-     * @param  <E>  The type of the exception to unwrap.
-     * @param  type The type of the exception to unwrap.
-     * @return The cause as an exception of the given type (never {@code null}).
-     * @throws RuntimeException If the cause is an instance of {@code RuntimeException},
+     * @param  <E>   the type of the exception to unwrap.
+     * @param  type  the type of the exception to unwrap.
+     * @return the cause as an exception of the given type (never {@code null}).
+     * @throws RuntimeException if the cause is an instance of {@code RuntimeException},
      *         in which case that instance is re-thrown.
      * @throws BackingStoreException if the cause is neither the given type or an instance
      *         of {@link RuntimeException}, in which case {@code this} exception is re-thrown.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1755515&r1=1755514&r2=1755515&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Mon Aug  8 15:56:56 2016
@@ -236,6 +236,11 @@ public final class Errors extends Indexe
         public static final short DeadThread_1 = 15;
 
         /**
+         * Operation “{0}” requires a “{1}” property, but no such property has been
found in “{2}”.
+         */
+        public static final short DependencyNotFound_3 = 235;
+
+        /**
          * The “{0}” file points to a directory instead of a regular file.
          */
         public static final short DirectoryNotExpected_1 = 165;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1755515&r1=1755514&r2=1755515&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Mon Aug  8 15:56:56 2016
@@ -58,6 +58,7 @@ CoordinateOperationNotFound_2     = Coor
 DatabaseError_2                   = Database error while creating a \u2018{0}\u2019 object
for code \u201c{1}\u201d.
 DatumOriginShallBeDate            = Origin of temporal datum shall be a date.
 DeadThread_1                      = Thread \u201c{0}\u201d is dead.
+DependencyNotFound_3              = Operation \u201c{0}\u201d requires a \u201c{1}\u201d
property, but no such property has been found in \u201c{2}\u201d.
 DirectoryNotExpected_1            = The \u201c{0}\u201d file points to a directory instead
of a regular file.
 DisposedInstanceOf_1              = This instance of \u2018{0}\u2019 has been disposed.
 DuplicatedElement_1               = Element \u201c{0}\u201d is duplicated.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1755515&r1=1755514&r2=1755515&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Mon Aug  8 15:56:56 2016
@@ -55,6 +55,7 @@ CoordinateOperationNotFound_2     = La c
 DatabaseError_2                   = Erreur de base de donn\u00e9es lors de la cr\u00e9ation
d\u2019un objet \u2018{0}\u2019 pour le code \u00ab\u202f{1}\u202f\u00bb.
 DatumOriginShallBeDate            = L\u2019origine d\u2019un r\u00e9f\u00e9rentiel temporel
doit \u00eatre une date.
 DeadThread_1                      = La t\u00e2che \u00ab\u202f{0}\u202f\u00bb est morte.
+DependencyNotFound_3              = L\u2019op\u00e9ration \u00ab\u202f{0}\u202f\u00bb n\u00e9cessite
une propri\u00e9t\u00e9 \u00ab\u202f{1}\u202f\u00bb, mais cette propri\u00e9t\u00e9 n\u2019a
pas \u00e9t\u00e9 trouv\u00e9e dans \u00ab\u202f{2}\u202f\u00bb.
 DirectoryNotExpected_1            = Le fichier \u00ab\u202f{0}\u202f\u00bb d\u00e9signe un
r\u00e9pertoire plut\u00f4t qu\u2019un fichier r\u00e9gulier.
 DisposedInstanceOf_1              = Cette instance de \u2018{0}\u2019 a \u00e9t\u00e9 dispos\u00e9e.
 DuplicatedElement_1               = L\u2019\u00e9lement \u00ab\u202f{0}\u202f\u00bb est dupliqu\u00e9.



Mime
View raw message