Author: desruisseaux
Date: Tue May 16 15:58:40 2017
New Revision: 1795334

URL: http://svn.apache.org/viewvc?rev=1795334&view=rev
Log:
Give protected access to AbstractFeature.get|setOperationValue(…) for easier 
usage by subclasses defined outside Apache SIS.

Modified:
    
sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
    
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java

Modified: 
sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java?rev=1795334&r1=1795333&r2=1795334&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
 [UTF-8] Tue May 16 15:58:40 2017
@@ -248,6 +248,8 @@ public abstract class AbstractFeature im
 
     /**
      * Executes the parameterless operation of the given name and returns its 
result.
+     *
+     * @see #getOperationValue(String)
      */
     final Property getOperationResult(final String name) {
         /*
@@ -260,41 +262,6 @@ public abstract class AbstractFeature im
     }
 
     /**
-     * Executes the parameterless operation of the given name and returns the 
value of its result.
-     */
-    final Object getOperationValue(final String name) {
-        final Operation operation = (Operation) type.getProperty(name);
-        if (operation instanceof LinkOperation) {
-            return getPropertyValue(((LinkOperation) operation).referentName);
-        }
-        final Property result = operation.apply(this, null);
-        if (result instanceof Attribute<?>) {
-            return getAttributeValue((Attribute<?>) result);
-        } else if (result instanceof FeatureAssociation) {
-            return getAssociationValue((FeatureAssociation) result);
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Executes the parameterless operation of the given name and sets the 
value of its result.
-     */
-    final void setOperationValue(final String name, final Object value) {
-        final Operation operation = (Operation) type.getProperty(name);
-        if (operation instanceof LinkOperation) {
-            setPropertyValue(((LinkOperation) operation).referentName, value);
-        } else {
-            final Property result = operation.apply(this, null);
-            if (result != null) {
-                setPropertyValue(result, value);
-            } else {
-                throw new 
IllegalStateException(Resources.format(Resources.Keys.CanNotSetPropertyValue_1, 
name));
-            }
-        }
-    }
-
-    /**
      * Returns the default value to be returned by {@link 
#getPropertyValue(String)}
      * for the property of the given name.
      *
@@ -387,6 +354,73 @@ public abstract class AbstractFeature im
     public abstract void setPropertyValue(final String name, final Object 
value) throws IllegalArgumentException;
 
     /**
+     * Executes the parameterless operation of the given name and returns the 
value of its result.
+     * This is a convenience method for sub-classes where some properties may 
be operations that
+     * {@linkplain AbstractOperation#getDependencies() depend} on other 
properties of this {@code Feature} instance
+     * (for example a {@linkplain FeatureOperations#link link} to another 
property value).
+     * Invoking this method is equivalent to performing the following steps:
+     *
+     * {@preformat java
+     *     Operation operation = (Operation) type.getProperty(name);
+     *     Property result = operation.apply(this, null);
+     *     if (result instanceof Attribute<?>) {
+     *         return ...;                                      // the 
attribute value.
+     *     } else if (result instanceof FeatureAssociation) {
+     *         return ...;                                      // the 
associated feature.
+     *     } else {
+     *         return null;
+     *     }
+     * }
+     *
+     * @param  name  the name of the operation to execute. The caller is 
responsible to ensure that the
+     *               property type for that name is an instance of {@link 
Operation}.
+     * @return the result value of the given operation, or {@code null} if 
none.
+     *
+     * @since 0.8
+     */
+    protected Object getOperationValue(final String name) {
+        final Operation operation = (Operation) type.getProperty(name);
+        if (operation instanceof LinkOperation) {
+            return getPropertyValue(((LinkOperation) operation).referentName);
+        }
+        final Property result = operation.apply(this, null);
+        if (result instanceof Attribute<?>) {
+            return getAttributeValue((Attribute<?>) result);
+        } else if (result instanceof FeatureAssociation) {
+            return getAssociationValue((FeatureAssociation) result);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Executes the parameterless operation of the given name and sets the 
value of its result.
+     * This method is the complement of {@link #getOperationValue(String)} for 
subclasses where
+     * some properties may be operations. Not all operations accept 
assignments,
+     * but the {@linkplain FeatureOperations#link link} operation for instance 
does.
+     *
+     * @param  name   the name of the operation to execute. The caller is 
responsible to ensure that the
+     *                property type for that name is an instance of {@link 
Operation}.
+     * @param  value  the value to assign to the result of the named operation.
+     * @throws IllegalStateException if the operation of the given name does 
not accept assignment.
+     *
+     * @since 0.8
+     */
+    protected void setOperationValue(final String name, final Object value) {
+        final Operation operation = (Operation) type.getProperty(name);
+        if (operation instanceof LinkOperation) {
+            setPropertyValue(((LinkOperation) operation).referentName, value);
+        } else {
+            final Property result = operation.apply(this, null);
+            if (result != null) {
+                setPropertyValue(result, value);
+            } else {
+                throw new 
IllegalStateException(Resources.format(Resources.Keys.CanNotSetPropertyValue_1, 
name));
+            }
+        }
+    }
+
+    /**
      * Returns the value of the given attribute, as a singleton or as a 
collection depending
      * on the maximum number of occurrences.
      */

Modified: 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java?rev=1795334&r1=1795333&r2=1795334&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java
 [UTF-8] Tue May 16 15:58:40 2017
@@ -19,11 +19,9 @@ package org.apache.sis.metadata.sql;
 import javax.sql.DataSource;
 import org.postgresql.ds.PGSimpleDataSource;
 import org.opengis.metadata.citation.Citation;
-import org.opengis.metadata.citation.Responsibility;
 import org.opengis.metadata.citation.PresentationForm;
 import org.opengis.metadata.citation.OnLineFunction;
 import org.opengis.metadata.citation.OnlineResource;
-import org.opengis.metadata.citation.Party;
 import org.opengis.metadata.citation.Role;
 import org.apache.sis.internal.metadata.sql.TestDatabase;
 import org.apache.sis.metadata.iso.citation.HardCodedCitations;
@@ -36,6 +34,10 @@ import org.junit.Test;
 
 import static org.junit.Assert.*;
 
+// Branch-dependent imports
+import org.opengis.metadata.citation.Party;
+import org.opengis.metadata.citation.Responsibility;
+
 
 /**
  * Creates a metadata database, stores a few elements and read them back.


Reply via email to