sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1569943 - in /sis/branches/JDK7/core/sis-metadata/src: main/java/org/apache/sis/metadata/ test/java/org/apache/sis/metadata/ test/java/org/apache/sis/metadata/iso/
Date Wed, 19 Feb 2014 22:40:59 GMT
Author: desruisseaux
Date: Wed Feb 19 22:40:59 2014
New Revision: 1569943

URL: http://svn.apache.org/r1569943
Log:
Look at the type explicitely declared by GeoAPI in order to determine if we shall check for
the "Abstract" or "Default" prefix in the implementation class name.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java?rev=1569943&r1=1569942&r2=1569943&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] Wed Feb 19 22:40:59 2014
@@ -130,12 +130,11 @@ public class MetadataStandard implements
      */
     public static final MetadataStandard ISO_19123;
     static {
-        final String[] prefix = {"Default", "Abstract"};
         final String[] acronyms = {"CoordinateSystem", "CS", "CoordinateReferenceSystem",
"CRS"};
 
         // If new StandardImplementation instances are added below, please update StandardImplementation.readResolve().
-        ISO_19111 = new StandardImplementation("ISO 19111", "org.opengis.referencing.", "org.apache.sis.referencing.",
prefix, acronyms);
-        ISO_19115 = new StandardImplementation("ISO 19115", "org.opengis.metadata.", "org.apache.sis.metadata.iso.",
prefix, null);
+        ISO_19111 = new StandardImplementation("ISO 19111", "org.opengis.referencing.", "org.apache.sis.referencing.",
acronyms);
+        ISO_19115 = new StandardImplementation("ISO 19115", "org.opengis.metadata.", "org.apache.sis.metadata.iso.",
null);
         ISO_19119 = new MetadataStandard      ("ISO 19119", "org.opengis.service.");
         ISO_19123 = new MetadataStandard      ("ISO 19123", "org.opengis.coverage.");
         INSTANCES = new MetadataStandard[] {

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java?rev=1569943&r1=1569942&r2=1569943&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java
[UTF-8] Wed Feb 19 22:40:59 2014
@@ -18,6 +18,8 @@ package org.apache.sis.metadata;
 
 import java.util.Map;
 import java.util.IdentityHashMap;
+import org.opengis.annotation.Classifier;
+import org.opengis.annotation.Stereotype;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.logging.Logging;
 
@@ -43,12 +45,6 @@ final class StandardImplementation exten
     private final String implementationPackage;
 
     /**
-     * The prefixes that implementation classes may have.
-     * The most common prefixes should be first, since the prefixes will be tried in that
order.
-     */
-    private final String[] prefix;
-
-    /**
      * The acronyms that implementation classes may have, or {@code null} if none. If non-null,
      * then this array shall contain (<var>full text</var>, <var>acronym</var>)
pairs. The full
      * text shall appear to the end of the class name, otherwise it is not replaced. This
is
@@ -77,20 +73,29 @@ final class StandardImplementation exten
      * @param citation              The title of the standard.
      * @param interfacePackage      The root package for metadata interfaces, with a trailing
{@code '.'}.
      * @param implementationPackage The root package for metadata implementations. with a
trailing {@code '.'}.
-     * @param prefix                The prefix of implementation class. This array is not
cloned.
      * @param acronyms              An array of (full text, acronyms) pairs. This array is
not cloned.
      */
     StandardImplementation(final String citation, final String interfacePackage,
-            final String implementationPackage, final String[] prefix, final String[] acronyms)
+            final String implementationPackage, final String[] acronyms)
     {
         super(citation, interfacePackage);
         this.implementationPackage = implementationPackage;
-        this.prefix                = prefix;
         this.acronyms              = acronyms;
         this.implementations       = new IdentityHashMap<>();
     }
 
     /**
+     * Returns {@code true} if the given type is conceptually abstract.
+     * The given type is usually an interface, so here "abstract" can not be in the Java
sense.
+     * If this method can not find information about whether the given type is abstract,
+     * then this method conservatively returns {@code false}.
+     */
+    private static boolean isAbstract(final Class<?> type) {
+        final Classifier c = type.getAnnotation(Classifier.class);
+        return (c != null) && c.value() == Stereotype.ABSTRACT;
+    }
+
+    /**
      * Returns the implementation class for the given interface, or {@code null} if none.
      * This class uses heuristic rules based on naming conventions.
      *
@@ -129,26 +134,19 @@ final class StandardImplementation exten
                         }
                     }
                     /*
-                     * Try to insert a prefix in front of the class name, until a match is
found.
+                     * Try to instantiate the implementation class.
                      */
                     final int prefixPosition = buffer.lastIndexOf(".") + 1;
-                    int length = 0;
-                    for (final String p : prefix) {
-                        name = buffer.replace(prefixPosition, prefixPosition + length, p).toString();
-                        try {
-                            candidate = Class.forName(name);
-                        } catch (ClassNotFoundException e) {
-                            Logging.recoverableException(MetadataStandard.class, "getImplementation",
e);
-                            length = p.length();
-                            continue;
-                        }
-                        if (candidate.isAnnotationPresent(Deprecated.class)) {
-                            // Skip deprecated implementations.
-                            length = p.length();
-                            continue;
+                    buffer.insert(prefixPosition, isAbstract(type) ? "Abstract" : "Default");
+                    name = buffer.toString();
+                    try {
+                        candidate = Class.forName(name);
+                        if (!candidate.isAnnotationPresent(Deprecated.class)) {
+                            implementations.put(type, candidate);
+                            return candidate;
                         }
-                        implementations.put(type, candidate);
-                        return candidate;
+                    } catch (ClassNotFoundException e) {
+                        Logging.recoverableException(MetadataStandard.class, "getImplementation",
e);
                     }
                     implementations.put(type, Void.TYPE); // Marker for "class not found".
                 }

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java?rev=1569943&r1=1569942&r2=1569943&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
[UTF-8] Wed Feb 19 22:40:59 2014
@@ -73,11 +73,15 @@ public abstract strictfp class MetadataT
 
     /**
      * Returns the SIS implementation for the given GeoAPI interface.
+     *
+     * @return {@inheritDoc}
      */
     @Override
     protected <T> Class<? extends T> getImplementation(final Class<T> type)
{
         assertTrue(standard.isMetadata(type));
-        return standard.getImplementation(type).asSubclass(type);
+        final Class<?> impl = standard.getImplementation(type);
+        assertNotNull(type.getName(), impl);
+        return impl.asSubclass(type);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java?rev=1569943&r1=1569942&r2=1569943&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
[UTF-8] Wed Feb 19 22:40:59 2014
@@ -214,6 +214,8 @@ public final strictfp class AllMetadataT
      * Returns the expected namespace for an element defined by the given specification.
      * For example the namespace of any type defined by {@link Specification#ISO_19115}
      * is {@code "http://www.isotc211.org/2005/gmd"}.
+     *
+     * @return {@inheritDoc}
      */
     @Override
     protected String getExpectedNamespace(final Class<?> impl, final Specification
specification) {
@@ -226,6 +228,8 @@ public final strictfp class AllMetadataT
     /**
      * Returns the type of the given element, or {@code null} if the type is not yet
      * determined (the later cases could change in a future version).
+     *
+     * @return {@inheritDoc}
      */
     @Override
     protected String getExpectedTypeForElement(final Class<?> type, final Class<?>
impl) {
@@ -251,6 +255,8 @@ public final strictfp class AllMetadataT
     /**
      * Returns the ISO 19139 wrapper for the given GeoAPI type,
      * or {@code null} if no adapter is expected for the given type.
+     *
+     * @return {@inheritDoc}
      */
     @Override
     protected Class<?> getWrapperFor(final Class<?> type) throws ClassNotFoundException
{
@@ -272,6 +278,8 @@ public final strictfp class AllMetadataT
 
     /**
      * Return {@code false} for the Apache SIS properties which are known to have no setter
methods.
+     *
+     * @return {@inheritDoc}
      */
     @Override
     protected boolean isWritable(final Class<?> impl, final String property) {



Mime
View raw message