sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1597108 - in /sis/branches/JDK8/core: sis-feature/src/main/java/org/apache/sis/feature/ sis-utility/src/main/java/org/apache/sis/util/resources/
Date Fri, 23 May 2014 14:50:12 GMT
Author: desruisseaux
Date: Fri May 23 14:50:11 2014
New Revision: 1597108

URL: http://svn.apache.org/r1597108
Log:
Ensure that the feature is not abstract before to instantiate it, and do not use reflection
anymore for some clone implementation.
The reflection was used for cloning a final field. But given that the classes that used them
are not so big, the risk of removing
the 'final' keyword may be reasonable.

Modified:
    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/MultiValuedAttribute.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.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/DefaultFeatureType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java?rev=1597108&r1=1597107&r2=1597108&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] Fri May 23 14:50:11 2014
@@ -395,10 +395,11 @@ public class DefaultFeatureType extends 
 
     /**
      * Returns {@code true} if the feature type acts as an abstract super-type.
+     * Abstract types can not be {@linkplain #newInstance() instantiated}.
      *
      * @return {@code true} if the feature type acts as an abstract super-type.
      */
-    public boolean isAbstract() {
+    public final boolean isAbstract() {
         return isAbstract;
     }
 
@@ -569,8 +570,12 @@ public class DefaultFeatureType extends 
      * Creates a new feature instance of this type.
      *
      * @return A new feature instance.
+     * @throws IllegalStateException if this feature type {@linkplain #isAbstract() is abstract}.
      */
-    public AbstractFeature newInstance() {
+    public AbstractFeature newInstance() throws IllegalStateException {
+        if (isAbstract) {
+            throw new IllegalStateException(Errors.format(Errors.Keys.AbstractType_1, getName()));
+        }
         return isSparse ? new SparseFeature(this) : new DenseFeature(this);
     }
 

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java?rev=1597108&r1=1597107&r2=1597108&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java
[UTF-8] Fri May 23 14:50:11 2014
@@ -17,7 +17,6 @@
 package org.apache.sis.feature;
 
 import java.util.Collection;
-import java.lang.reflect.Field;
 import org.apache.sis.internal.util.CheckedArrayList;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
@@ -57,7 +56,7 @@ final class MultiValuedAttribute<V> exte
     /**
      * The attribute values.
      */
-    private final CheckedArrayList<V> values;
+    private CheckedArrayList<V> values;
 
     /**
      * Creates a new attribute of the given type initialized to the
@@ -161,13 +160,7 @@ final class MultiValuedAttribute<V> exte
     @SuppressWarnings("unchecked")
     public MultiValuedAttribute<V> clone() throws CloneNotSupportedException {
         final MultiValuedAttribute<V> clone = (MultiValuedAttribute<V>) super.clone();
-        try {
-            final Field field = MultiValuedAttribute.class.getDeclaredField("values");
-            field.setAccessible(true);
-            field.set(clone, clone.values.clone());
-        } catch (ReflectiveOperationException e) {
-            throw new AssertionError(e);
-        }
+        clone.values = (CheckedArrayList<V>) clone.values.clone();
         return clone;
     }
 

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java?rev=1597108&r1=1597107&r2=1597108&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
[UTF-8] Fri May 23 14:50:11 2014
@@ -19,7 +19,6 @@ package org.apache.sis.feature;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.ConcurrentModificationException;
-import java.lang.reflect.Field;
 import org.opengis.metadata.maintenance.ScopeCode;
 import org.opengis.metadata.quality.DataQuality;
 import org.apache.sis.internal.util.Cloner;
@@ -73,7 +72,7 @@ final class SparseFeature extends Abstra
      *
      * @see #valuesKind
      */
-    private final HashMap<String, Object> properties;
+    private HashMap<String, Object> properties;
 
     /**
      * {@link #PROPERTIES} if the values in the {@link #properties} map are {@link Property}
instances,
@@ -272,15 +271,10 @@ final class SparseFeature extends Abstra
      *         {@code clone()} on a property instance failed.
      */
     @Override
+    @SuppressWarnings("unchecked")
     public SparseFeature clone() throws CloneNotSupportedException {
         final SparseFeature clone = (SparseFeature) super.clone();
-        try {
-            final Field field = SparseFeature.class.getDeclaredField("properties");
-            field.setAccessible(true);
-            field.set(clone, clone.properties.clone());
-        } catch (ReflectiveOperationException e) {
-            throw new AssertionError(e);
-        }
+        clone.properties = (HashMap<String,Object>) clone.properties.clone();
         switch (clone.valuesKind) {
             default:        throw new AssertionError(clone.valuesKind);
             case CORRUPTED: throw new CorruptedObjectException(clone.getName());

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=1597108&r1=1597107&r2=1597108&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] Fri May 23 14:50:11 2014
@@ -64,6 +64,11 @@ public final class Errors extends Indexe
         }
 
         /**
+         * Type ‘{0}’ is abstract.
+         */
+        public static final short AbstractType_1 = 159;
+
+        /**
          * Name “{2}” is ambiguous because it can be understood as either “{0}” or
“{1}”.
          */
         public static final short AmbiguousName_3 = 151;

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=1597108&r1=1597107&r2=1597108&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] Fri May 23 14:50:11 2014
@@ -24,6 +24,7 @@
 # programmatic parameters do not have to be last in the formatted text, since each localized
message
 # can reorder the parameters as they want.
 #
+AbstractType_1                    = Type \u2018{0}\u2019 is abstract.
 AmbiguousName_3                   = Name \u201c{2}\u201d is ambiguous because it can be understood
as either \u201c{0}\u201d or \u201c{1}\u201d.
 CanNotAddToExclusiveSet_2         = No element can be added to this set because properties
\u2018{0}\u2019 and \u2018{1}\u2019 are mutually exclusive.
 CanNotConnectTo_1                 = Can not connect to \u201c{0}\u201d.

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=1597108&r1=1597107&r2=1597108&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] Fri May 23 14:50:11 2014
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+AbstractType_1                    = Le type \u2018{0}\u2019 est abstrait.
 AmbiguousName_3                   = Le nom \u00ab\u202f{2}\u202f\u00bb est ambigu\u00eb car
il peut \u00eatre interpr\u00e9t\u00e9 comme \u00ab\u202f{0}\u202f\u00bb ou \u00ab\u202f{1}\u202f\u00bb.
 CanNotAddToExclusiveSet_2         = Aucun \u00e9l\u00e9ment ne peut \u00eatre ajout\u00e9
\u00e0 cet ensemble car les propri\u00e9t\u00e9s \u2018{0}\u2019 et \u2018{1}\u2019 sont mutuellement
exclusives.
 CanNotConnectTo_1                 = Ne peut pas se connecter \u00e0 \u00ab\u202f{0}\u202f\u00bb.



Mime
View raw message