sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1631148 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-metadata/src/test/java/org/apache/sis/metadata/ sis-metadata/src/test/java/org/apache/sis...
Date Sun, 12 Oct 2014 06:53:34 GMT
Author: desruisseaux
Date: Sun Oct 12 06:53:33 2014
New Revision: 1631148

URL: http://svn.apache.org/r1631148
Log:
Added a special case for the "language" property, which is not handle in the same way than
what ISO 19115:2014 said.
Those difference exists because JDK already has its own java.util.Locale, which we want to
use and which is different
than the ISO 19115 PT_Locale construct.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1631148&r1=1631147&r2=1631148&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] Sun Oct 12 06:53:33 2014
@@ -250,10 +250,10 @@ class PropertyAccessor {
     /**
      * Creates a new property accessor for the specified metadata implementation.
      *
-     * @param  standard The standard which define the {@code type} interface.
-     * @param  type The interface implemented by the metadata class.
+     * @param  standard       The standard which define the {@code type} interface.
+     * @param  type           The interface implemented by the metadata class.
      * @param  implementation The class of metadata implementations, or {@code type} if none.
-     * @param  onlyUML {@code true} for taking only the getter methods having a {@link UML}
annotation.
+     * @param  onlyUML        {@code true} for taking only the getter methods having a {@link
UML} annotation.
      */
     PropertyAccessor(final Citation standard, final Class<?> type, final Class<?>
implementation, final boolean onlyUML) {
         assert type.isAssignableFrom(implementation) : implementation;
@@ -298,7 +298,12 @@ class PropertyAccessor {
             addMappingWithLowerCase(names[i] = toPropertyName(name, base), index);
             final UML annotation = getter.getAnnotation(UML.class);
             if (annotation != null) {
-                addMappingWithLowerCase(annotation.identifier().intern(), index);
+                final String identifier = annotation.identifier().intern();
+                addMappingWithLowerCase(identifier, index);
+                final String alt = SpecialCases.rename(type, annotation.identifier().intern());
+                if (alt != identifier) { // Identity comparison is okay here.
+                    addMappingWithLowerCase(alt, index);
+                }
             }
             /*
              * Now try to infer the setter from the getter. We replace the "get" prefix by

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java?rev=1631148&r1=1631147&r2=1631148&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
[UTF-8] Sun Oct 12 06:53:33 2014
@@ -16,8 +16,10 @@
  */
 package org.apache.sis.metadata;
 
+import org.opengis.metadata.Metadata;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.metadata.identification.DataIdentification;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.util.collection.BackingStoreException;
@@ -31,7 +33,7 @@ import org.apache.sis.util.collection.Ba
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.5
  * @module
  */
 final class SpecialCases extends PropertyAccessor {
@@ -68,6 +70,23 @@ final class SpecialCases extends Propert
     }
 
     /**
+     * Other special cases: rename particular UML identifiers found in
+     * {@link org.opengis.metadata.identification.DataIdentification#getLanguages()} and
+     * {@link org.opengis.metadata.Metadata#getLanguages()}.
+     *
+     * @param  identifier The UML identifier.
+     * @return The identifier to use.
+     */
+    static String rename(final Class<?> type, String identifier) {
+        if ((type == Metadata.class || type == DataIdentification.class)
+                && identifier.equals("defaultLocale+otherLocale"))
+        {
+            identifier = "language";
+        }
+        return identifier;
+    }
+
+    /**
      * Delegates to {@link PropertyAccessor#type(int)}, then substitutes the type for the
properties
      * handled in a special way.
      */

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java?rev=1631148&r1=1631147&r2=1631148&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
[UTF-8] Sun Oct 12 06:53:33 2014
@@ -324,7 +324,7 @@ class TreeNode implements Node {
          */
         @Override
         CharSequence getName() {
-            return CharSequences.camelCaseToSentence(getIdentifier()).toString();
+            return CharSequences.camelCaseToSentence(SpecialCases.rename(accessor.type, getIdentifier())).toString();
         }
 
         /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java?rev=1631148&r1=1631147&r2=1631148&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] Sun Oct 12 06:53:33 2014
@@ -538,6 +538,10 @@ public class DefaultMetadata extends ISO
 
             @Override
             public boolean add(final Locale newValue) {
+                if (languages.isEmpty()) {
+                    languages.add(newValue);
+                    // Add twice, since the first entry is assigned to the "language" legacy
property.
+                }
                 return languages.add(newValue);
             }
         };
@@ -561,6 +565,7 @@ public class DefaultMetadata extends ISO
             merged = new ArrayList<>(newValues.size() + 1);
             if (language == null) {
                 language = newValues.iterator().next();
+                // Add twice, since the first entry is assigned to the "language" legacy
property.
             }
             merged.add(language);
             merged.addAll(newValues);

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java?rev=1631148&r1=1631147&r2=1631148&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
[UTF-8] Sun Oct 12 06:53:33 2014
@@ -16,9 +16,12 @@
  */
 package org.apache.sis.metadata;
 
+import org.opengis.annotation.UML;
 import org.opengis.util.InternationalString;
+import org.opengis.metadata.Metadata;
 import org.opengis.metadata.ExtendedElementInformation;
 import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.metadata.identification.DataIdentification;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.measure.NumberRange;
@@ -37,7 +40,7 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.5
  * @module
  */
 @DependsOn(PropertyAccessorTest.class)
@@ -202,4 +205,21 @@ public final strictfp class SpecialCases
         assertEquals(-180, range.getMinDouble(), STRICT);
         assertEquals(+180, range.getMaxDouble(), STRICT);
     }
+
+    /**
+     * Verifies that the need for {@link SpecialCases#rename(String)} still apply.
+     * If this test fails, it does not necessarily means that the {@code rename} method is
wrong.
+     * It may mean that the GeoAPI interface changed, in which case the {@code rename} method
or
+     * this test should be adapted.
+     *
+     * @throws NoSuchMethodException If the methods for which {@code rename} were designed
do not exists anymore.
+     */
+    @Test
+    public void testRename() throws NoSuchMethodException {
+        String identifier = Metadata.class.getMethod("getLanguages").getAnnotation(UML.class).identifier();
+        assertFalse(identifier, identifier.equals(SpecialCases.rename(Metadata.class, identifier)));
+
+        identifier = DataIdentification.class.getMethod("getLanguages").getAnnotation(UML.class).identifier();
+        assertFalse(identifier, identifier.equals(SpecialCases.rename(DataIdentification.class,
identifier)));
+    }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java?rev=1631148&r1=1631147&r2=1631148&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
[UTF-8] Sun Oct 12 06:53:33 2014
@@ -16,6 +16,9 @@
  */
 package org.apache.sis.metadata.iso;
 
+import java.util.Locale;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.logging.LogRecord;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
@@ -45,7 +48,7 @@ import static org.apache.sis.test.Assert
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public final strictfp class DefaultMetadataTest extends XMLTestCase implements WarningListener<Object>
{
@@ -122,4 +125,71 @@ public final strictfp class DefaultMetad
         assertEquals("warning", "NullCollectionElement_1", resourceKey);
         assertArrayEquals("warning", new String[] {"CheckedArrayList<Responsibility>"},
parameters);
     }
+
+    /**
+     * Tests {@link DefaultMetadata#getFileIdentifier()} and {@link DefaultMetadata#setFileIdentifier(String)}
+     * legacy methods. Those methods should delegate to newer methods.
+     *
+     * @since 0.5
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testFileIdentifier() {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertNull("getFileIdentifier", metadata.getFileIdentifier());
+        metadata.setFileIdentifier("Apache SIS/Metadata test");
+        assertEquals("getMetadataIdentifier", "Apache SIS/Metadata test", metadata.getMetadataIdentifier().getCode());
+        assertEquals("getFileIdentifier",     "Apache SIS/Metadata test", metadata.getFileIdentifier());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getLanguage()}, {@link DefaultMetadata#setLanguage(Locale)},
+     * {@link DefaultMetadata#getLocales()} and {@link DefaultMetadata#setLocales(Collection)}
+     * legacy methods. Those methods should delegate to newer methods.
+     *
+     * @since 0.5
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testLocales() {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertNull("getLanguage", metadata.getLanguage());
+        /*
+         * Set the default language, which shall be the first entry in the collection.
+         * The "other locales" property shall be unmodified by the "language" one.
+         */
+        metadata.setLanguage(Locale.JAPANESE);
+        assertLanguagesEquals(metadata, Locale.JAPANESE);
+        /*
+         * Add other languages. They should appear as additional entries after the first
one.
+         * The "language" property shall be unmodified by changes in the "other locales"
one.
+         */
+        metadata.setLocales(Arrays.asList(Locale.FRENCH, Locale.ENGLISH));
+        assertLanguagesEquals(metadata, Locale.JAPANESE, Locale.FRENCH, Locale.ENGLISH);
+        /*
+         * Ensure that the "locales" list is modifiable, since JAXB writes directly in it.
+         */
+        metadata.getLocales().clear();
+        assertLanguagesEquals(metadata, Locale.JAPANESE);
+        final Collection<Locale> locales = metadata.getLocales();
+        assertTrue(locales.add(Locale.KOREAN));
+        assertTrue(locales.add(Locale.ENGLISH));
+        assertLanguagesEquals(metadata, Locale.JAPANESE, Locale.KOREAN, Locale.ENGLISH);
+        /*
+         * Changing again the default language shall not change the other locales.
+         */
+        metadata.setLanguage(Locale.GERMAN);
+        assertLanguagesEquals(metadata, Locale.GERMAN, Locale.KOREAN, Locale.ENGLISH);
+    }
+
+    /**
+     * Compares the {@link DefaultMetadata#getLanguages()}, {@link DefaultMetadata#getLanguage()}
and
+     * {@link DefaultMetadata#getLocales()} values against the expected array.
+     */
+    @SuppressWarnings("deprecation")
+    private static void assertLanguagesEquals(final DefaultMetadata metadata, final Locale...
expected) {
+        assertArrayEquals("getLanguages", expected,    metadata.getLanguages().toArray());
+        assertEquals     ("getLanguage",  expected[0], metadata.getLanguage());
+        assertArrayEquals("getLocales",   Arrays.copyOfRange(expected, 1, expected.length),
metadata.getLocales().toArray());
+    }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java?rev=1631148&r1=1631147&r2=1631148&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java
[UTF-8] Sun Oct 12 06:53:33 2014
@@ -16,6 +16,11 @@
  */
 package org.apache.sis.metadata.iso.identification;
 
+import java.util.Collection;
+import java.util.Map;
+import java.util.Locale;
+import java.nio.charset.StandardCharsets;
+import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.DateType;
 import org.opengis.metadata.identification.KeywordType;
 import org.opengis.metadata.spatial.SpatialRepresentationType;
@@ -29,6 +34,7 @@ import org.apache.sis.test.TestCase;
 import org.apache.sis.test.TestUtilities;
 import org.junit.Test;
 
+import static java.util.Arrays.asList;
 import static java.util.Collections.singleton;
 import static org.apache.sis.test.Assert.*;
 
@@ -38,11 +44,11 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.5
  * @module
  */
 @DependsOn({
-    org.apache.sis.metadata.PropertyAccessorTest.class, // For properties order
+    org.apache.sis.metadata.ValueMapTest.class,
     org.apache.sis.metadata.iso.citation.DefaultCitationTest.class,
     org.apache.sis.metadata.iso.citation.DefaultCitationDateTest.class,
     org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBoxTest.class,
@@ -50,6 +56,11 @@ import static org.apache.sis.test.Assert
 })
 public final strictfp class DefaultDataIdentificationTest extends TestCase {
     /**
+     * The locales used in this test.
+     */
+    private static final Locale[] LOCALES = {Locale.US, Locale.ENGLISH};
+
+    /**
      * Creates the instance to test.
      */
     private static DefaultDataIdentification create() {
@@ -88,6 +99,9 @@ public final strictfp class DefaultDataI
          *  ├─Resource constraints
          *  │   └─Use limitation………………………………………………………
Freely available
          *  ├─Spatial representation type……………………………… Grid
+         *  ├─Language (1 of 2)…………………………………………………………
en_US
+         *  ├─Language (2 of 2)…………………………………………………………
en
+         *  ├─Character set……………………………………………………………………
US-ASCII
          *  └─Extent
          *      └─Geographic element
          *          ├─West bound longitude…………………………… 180°W
@@ -102,6 +116,8 @@ public final strictfp class DefaultDataI
         info.setDescriptiveKeywords(singleton(keywords));
         info.setResourceConstraints(singleton(new DefaultConstraints("Freely available")));
         info.setExtents(singleton(Extents.WORLD));
+        info.setLanguages(asList(LOCALES));
+        info.setCharacterSets(singleton(StandardCharsets.US_ASCII));
         return info;
     }
 
@@ -135,6 +151,9 @@ public final strictfp class DefaultDataI
                 "  ├─Resource constraints\n" +
                 "  │   └─Use limitation……………………………… Freely
available\n" +
                 "  ├─Spatial representation type……… Grid\n" +
+                "  ├─Language (1 of 2)………………………………… en_US\n"
+
+                "  ├─Language (2 of 2)………………………………… en\n"
+
+                "  ├─Character set……………………………………………
US-ASCII\n" +
                 "  └─Extent\n" +
                 "      ├─Description………………………………………
World\n" +
                 "      └─Geographic element\n" +
@@ -145,4 +164,22 @@ public final strictfp class DefaultDataI
                 "          └─Extent type code……………… true\n",
             TestUtilities.formatNameAndValue(create().asTreeTable()));
     }
+
+    /**
+     * Tests {@link DefaultDataIdentification#asMap()}, in particular on the {@code "language"}
property.
+     * This property is handle in a special way since the declared UML identifier is
+     * {@code "defaultLocale+otherLocale"}.
+     */
+    @Test
+    public void testValueMap() {
+        final DefaultDataIdentification info = create();
+        final Map<String,Object> map = info.asMap();
+        assertEquals("abstract", "NCEP SST Global 5.0 x 2.5 degree model data", map.get("abstract").toString());
+        assertEquals("title", "Sea Surface Temperature Analysis Model", ((Citation) map.get("citation")).getTitle().toString());
+        assertEquals("spatialRepresentationType", singleton(SpatialRepresentationType.GRID),
map.get("spatialRepresentationType"));
+        assertArrayEquals("language",                  LOCALES, ((Collection<?>) map.get("language")).toArray());
+        assertArrayEquals("languages",                 LOCALES, ((Collection<?>) map.get("languages")).toArray());
+        assertArrayEquals("getLanguages",              LOCALES, ((Collection<?>) map.get("getLanguages")).toArray());
+        assertArrayEquals("defaultLocale+otherLocale", LOCALES, ((Collection<?>) map.get("defaultLocale+otherLocale")).toArray());
+    }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1631148&r1=1631147&r2=1631148&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] Sun Oct 12 06:53:33 2014
@@ -34,7 +34,7 @@ import static org.apache.sis.util.CharSe
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Johann Sorel (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
- * @version 0.4
+ * @version 0.5
  * @module
  */
 @DependsOn({
@@ -299,6 +299,16 @@ public final strictfp class CharSequence
     }
 
     /**
+     * Tests the {@link CharSequences#camelCaseToSentence(CharSequence)} method.
+     */
+    @Test
+    @DependsOnMethod("testCamelCaseToWords")
+    public void testCamelCaseToSentence() {
+        assertEquals("Default locale", camelCaseToSentence("defaultLocale").toString());
+        assertNull(camelCaseToSentence(null));
+    }
+
+    /**
      * Tests the {@link CharSequences#camelCaseToWords(CharSequence, boolean)} method.
      */
     @Test



Mime
View raw message