sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1631337 - in /sis/branches/JDK6: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ core/sis-metadata/s...
Date Mon, 13 Oct 2014 10:32:55 GMT
Author: desruisseaux
Date: Mon Oct 13 10:32:55 2014
New Revision: 1631337

URL: http://svn.apache.org/r1631337
Log:
Merge from the JDK7 branch.

Added:
    sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
      - copied, changed from r1631332, sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
    sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
      - copied, changed from r1631332, sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
Modified:
    sis/branches/JDK6/   (props changed)
    sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
    sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
    sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
    sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
    sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
    sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
    sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java
    sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
    sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardCharsets.java
    sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java

Propchange: sis/branches/JDK6/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK8:r1630660-1631330
  Merged /sis/branches/JDK7:r1630662-1631332

Copied: sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
(from r1631332, sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java?p2=sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java&p1=sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java&r1=1631332&r2=1631337&rev=1631337&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
[UTF-8] Mon Oct 13 10:32:55 2014
@@ -133,7 +133,7 @@ public final class OtherLocales extends 
         if (Containers.isNullOrEmpty(otherLocales)) {
             merged = LegacyPropertyAdapter.asCollection(defaultLocale);
         } else {
-            merged = new ArrayList<>(otherLocales.size() + 1);
+            merged = new ArrayList<Locale>(otherLocales.size() + 1);
             if (defaultLocale == null) {
                 defaultLocale = Locale.getDefault();
                 if (otherLocales.contains(defaultLocale)) {
@@ -200,7 +200,7 @@ public final class OtherLocales extends 
             values.add(newValue);
         } else {
             if (!(values instanceof List<?>)) {
-                values = new ArrayList<>(values);
+                values = new ArrayList<T>(values);
             }
             ((List<T>) values).set(0, newValue);
         }

Modified: sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] Mon Oct 13 10:32:55 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/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
[UTF-8] Mon Oct 13 10:32:55 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/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
[UTF-8] Mon Oct 13 10:32:55 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/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] Mon Oct 13 10:32:55 2014
@@ -21,8 +21,6 @@ import java.util.Locale;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.AbstractCollection;
 import java.util.Iterator;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -56,7 +54,6 @@ import org.opengis.metadata.quality.Data
 import org.opengis.metadata.spatial.SpatialRepresentation;
 import org.opengis.referencing.ReferenceSystem;
 import org.opengis.util.InternationalString;
-import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
@@ -64,6 +61,7 @@ import org.apache.sis.metadata.iso.citat
 import org.apache.sis.metadata.iso.identification.AbstractIdentification;
 import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+import org.apache.sis.internal.metadata.OtherLocales;
 import org.apache.sis.internal.jaxb.code.PT_Locale;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.xml.Namespaces;
@@ -444,27 +442,12 @@ public class DefaultMetadata extends ISO
     @Deprecated
     @XmlElement(name = "language")
     public final Locale getLanguage() {
-        return first(languages);
+        return OtherLocales.getFirst(languages);
         // No warning if the collection contains more than one locale, because
         // this is allowed by the "getLanguage() + getLocales()" contract.
     }
 
     /**
-     * Returns the first element of the given collection, or {@code null} if none.
-     * This method does not emit warning if more than one element is found.
-     * Consequently, this method should be used only when multi-occurrence is not ambiguous.
-     */
-    private static <T> T first(final Collection<T> values) {
-        if (values != null) {
-            final Iterator<T> it = values.iterator();
-            if (it.hasNext()) {
-                return it.next();
-            }
-        }
-        return null;
-    }
-
-    /**
      * Sets the language used for documenting metadata.
      * This method modifies the collection returned by {@link #getLanguages()} as below:
      *
@@ -480,31 +463,7 @@ public class DefaultMetadata extends ISO
     @Deprecated
     public final void setLanguage(final Locale newValue) {
         checkWritePermission();
-        setLanguages(setFirst(languages, newValue));
-    }
-
-    /**
-     * Sets the first element in the given collection to the given value.
-     * If the given collection is empty, the given value will be added to it.
-     */
-    private static <T> Collection<T> setFirst(Collection<T> values, final
T newValue) {
-        if (values == null) {
-            return LegacyPropertyAdapter.asCollection(newValue);
-        }
-        if (newValue == null) {
-            final Iterator<T> it = values.iterator();
-            if (it.hasNext()) {
-                it.remove();
-            }
-        } else if (values.isEmpty()) {
-            values.add(newValue);
-        } else {
-            if (!(values instanceof List<?>)) {
-                values = new ArrayList<T>(values);
-            }
-            ((List<T>) values).set(0, newValue);
-        }
-        return values;
+        setLanguages(OtherLocales.setFirst(languages, newValue));
     }
 
     /**
@@ -519,28 +478,7 @@ public class DefaultMetadata extends ISO
     @XmlElement(name = "locale")
     @XmlJavaTypeAdapter(PT_Locale.class)
     public final Collection<Locale> getLocales() {
-        final Collection<Locale> languages = getLanguages();
-        if (languages == null) { // May happen at XML marshalling time.
-            return Collections.emptySet();
-        }
-        return new AbstractCollection<Locale>() {
-            @Override
-            public int size() {
-                return Math.max(0, languages.size() - 1);
-            }
-
-            @Override
-            public Iterator<Locale> iterator() {
-                final Iterator<Locale> it = languages.iterator();
-                if (it.hasNext()) it.next(); // Skip the first element.
-                return it;
-            }
-
-            @Override
-            public boolean add(final Locale newValue) {
-                return languages.add(newValue);
-            }
-        };
+        return OtherLocales.filter(getLanguages());
     }
 
     /**
@@ -553,19 +491,7 @@ public class DefaultMetadata extends ISO
     @Deprecated
     public final void setLocales(final Collection<? extends Locale> newValues) {
         checkWritePermission();
-        Locale language = getLanguage();
-        final Collection<Locale> merged;
-        if (Containers.isNullOrEmpty(newValues)) {
-            merged = LegacyPropertyAdapter.asCollection(language);
-        } else {
-            merged = new ArrayList<Locale>(newValues.size() + 1);
-            if (language == null) {
-                language = newValues.iterator().next();
-            }
-            merged.add(language);
-            merged.addAll(newValues);
-        }
-        setLanguages(merged);
+        setLanguages(OtherLocales.merge(getLanguage(), newValues));
     }
 
     /**
@@ -1210,7 +1136,7 @@ public class DefaultMetadata extends ISO
         final URI uri = new URI(newValue);
         checkWritePermission();
         Collection<Identification> identificationInfo = this.identificationInfo;
-        AbstractIdentification firstId = AbstractIdentification.castOrCopy(first(identificationInfo));
+        AbstractIdentification firstId = AbstractIdentification.castOrCopy(OtherLocales.getFirst(identificationInfo));
         if (firstId == null) {
             firstId = new DefaultDataIdentification();
         }
@@ -1219,15 +1145,15 @@ public class DefaultMetadata extends ISO
             citation = new DefaultCitation();
         }
         Collection<OnlineResource> onlineResources = citation.getOnlineResources();
-        DefaultOnlineResource firstOnline = DefaultOnlineResource.castOrCopy(first(onlineResources));
+        DefaultOnlineResource firstOnline = DefaultOnlineResource.castOrCopy(OtherLocales.getFirst(onlineResources));
         if (firstOnline == null) {
             firstOnline = new DefaultOnlineResource();
         }
         firstOnline.setLinkage(uri);
-        onlineResources = setFirst(onlineResources, firstOnline);
+        onlineResources = OtherLocales.setFirst(onlineResources, firstOnline);
         citation.setOnlineResources(onlineResources);
         firstId.setCitation(citation);
-        identificationInfo = setFirst(identificationInfo, firstId);
+        identificationInfo = OtherLocales.setFirst(identificationInfo, firstId);
         setIdentificationInfo(identificationInfo);
     }
 
@@ -1502,7 +1428,7 @@ public class DefaultMetadata extends ISO
      * This method sets the locale to be used for XML marshalling to the metadata language.
      */
     private void beforeMarshal(final Marshaller marshaller) {
-        Context.push(first(languages));
+        Context.push(OtherLocales.getFirst(languages));
     }
 
     /**

Copied: sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
(from r1631332, sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java?p2=sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java&p1=sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java&r1=1631332&r2=1631337&rev=1631337&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
[UTF-8] Mon Oct 13 10:32:55 2014
@@ -42,7 +42,7 @@ public final strictfp class OtherLocales
      */
     @Test
     public void testFilter() {
-        final Collection<Locale> languages = new LinkedHashSet<>();
+        final Collection<Locale> languages = new LinkedHashSet<Locale>();
         final Collection<Locale> otherLocales = OtherLocales.filter(languages);
         assertEquals("size", 0, otherLocales.size());
         /*
@@ -119,7 +119,7 @@ public final strictfp class OtherLocales
         assertSame("Shall set value in-place.", locales, OtherLocales.setFirst(locales, GERMAN));
         assertArrayEquals(new Locale[] {GERMAN, JAPANESE, FRENCH}, locales.toArray());
 
-        locales = new LinkedHashSet<>(Arrays.asList(ENGLISH, JAPANESE, FRENCH));
+        locales = new LinkedHashSet<Locale>(Arrays.asList(ENGLISH, JAPANESE, FRENCH));
         locales = OtherLocales.setFirst(locales, ITALIAN);
         assertArrayEquals(new Locale[] {ITALIAN, JAPANESE, FRENCH}, locales.toArray());
 

Modified: sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
[UTF-8] Mon Oct 13 10:32:55 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/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
[UTF-8] Mon Oct 13 10:32:55 2014
@@ -16,17 +16,33 @@
  */
 package org.apache.sis.metadata.iso;
 
+import java.util.Date;
+import java.util.Locale;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Collection;
 import java.util.logging.LogRecord;
+import java.net.URISyntaxException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
+import org.opengis.metadata.MetadataScope;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.citation.DateType;
+import org.opengis.metadata.maintenance.ScopeCode;
 import org.apache.sis.xml.XML;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.MarshallerPool;
 import org.apache.sis.util.logging.WarningListener;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
 import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.test.TestUtilities.date;
+import static org.apache.sis.test.TestUtilities.getSingleton;
 
 
 /**
@@ -45,9 +61,10 @@ 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
  */
+@DependsOn(org.apache.sis.internal.metadata.OtherLocalesTest.class)
 public final strictfp class DefaultMetadataTest extends XMLTestCase implements WarningListener<Object>
{
     /**
      * The resource key for the message of the warning that occurred while unmarshalling
a XML fragment,
@@ -122,4 +139,197 @@ 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("fileIdentifier", metadata.getFileIdentifier());
+        metadata.setFileIdentifier("Apache SIS/Metadata test");
+        assertEquals("metadataIdentifier", "Apache SIS/Metadata test", metadata.getMetadataIdentifier().getCode());
+        assertEquals("fileIdentifier",     "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("language", 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("languages", expected,    metadata.getLanguages().toArray());
+        assertEquals     ("language",  expected[0], metadata.getLanguage());
+        assertArrayEquals("locales",   Arrays.copyOfRange(expected, 1, expected.length),
metadata.getLocales().toArray());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getParentIdentifier()} and {@link DefaultMetadata#setParentIdentifier(String)}
+     * methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testParentIdentifier() {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertNull("parentIdentifier", metadata.getParentIdentifier());
+        metadata.setParentIdentifier("ParentID");
+        assertEquals("parentIdentifier", "ParentID", metadata.getParentIdentifier());
+
+        DefaultCitation c = (DefaultCitation) metadata.getParentMetadata();
+        assertEquals("parentMetadata", "ParentID", c.getTitle().toString());
+        c.setTitle(new SimpleInternationalString("New parent"));
+        assertEquals("parentIdentifier", "New parent", metadata.getParentIdentifier());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getHierarchyLevels()}, {@link DefaultMetadata#getHierarchyLevelNames()},
+     * {@link DefaultMetadata#setHierarchyLevel(Collection)} and {@link DefaultMetadata#setHierarchyLevelNames(Collection)}
+     * methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testHierarchyLevels() {
+        final String[]    names  = new String[] {"Bridges", "Golden Gate Bridge"};
+        final ScopeCode[] levels = new ScopeCode[] {ScopeCode.FEATURE_TYPE, ScopeCode.FEATURE};
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertTrue("hierarchyLevelNames", metadata.getHierarchyLevelNames().isEmpty());
+        assertTrue("hierarchyLevels",     metadata.getHierarchyLevels().isEmpty());
+
+        metadata.setHierarchyLevelNames(Arrays.asList(names));
+        metadata.setHierarchyLevels(Arrays.asList(levels));
+        assertArrayEquals("hierarchyLevelNames", names,  metadata.getHierarchyLevelNames().toArray());
+        assertArrayEquals("hierarchyLevels",     levels, metadata.getHierarchyLevels().toArray());
+        /*
+         * The above deprecated methods shall have created MetadataScope object. Verify that.
+         */
+        final Collection<MetadataScope> scopes = metadata.getMetadataScopes();
+        final Iterator<MetadataScope> it = scopes.iterator();
+        MetadataScope scope = it.next();
+        assertEquals("metadataScopes[0].name", "Bridges", scope.getName().toString());
+        assertEquals("metadataScopes[0].resourceScope", ScopeCode.FEATURE_TYPE, scope.getResourceScope());
+        scope = it.next();
+        assertEquals("metadataScopes[1].name", "Golden Gate Bridge", scope.getName().toString());
+        assertEquals("metadataScopes[1].resourceScope", ScopeCode.FEATURE, scope.getResourceScope());
+        /*
+         * Changes in the MetadataScope object shall be relfected immediately on the scope
collection.
+         * Verify that.
+         */
+        it.remove();
+        assertFalse(it.hasNext());
+        final DefaultMetadataScope c = new DefaultMetadataScope(levels[1] = ScopeCode.ATTRIBUTE_TYPE);
+        c.setName(new SimpleInternationalString(names[1] = "Clearance"));
+        assertTrue(scopes.add(c));
+        assertArrayEquals("hierarchyLevelNames", names,  metadata.getHierarchyLevelNames().toArray());
+        assertArrayEquals("hierarchyLevels",     levels, metadata.getHierarchyLevels().toArray());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getDateStamp()} and {@link DefaultMetadata#setDateStamp(Date)}
methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testDateStamp() {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertNull("dateStamp", metadata.getDateStamp());
+        /*
+         * Verifies that the deprecated method get its value from the CitationDate objects.
+         */
+        Date creation = date("2014-10-07 00:00:00");
+        final DefaultCitationDate[] dates = new DefaultCitationDate[] {
+                new DefaultCitationDate(date("2014-10-09 00:00:00"), DateType.LAST_UPDATE),
+                new DefaultCitationDate(creation, DateType.CREATION)
+        };
+        metadata.setDates(Arrays.asList(dates));
+        assertEquals("dateStamp", creation, metadata.getDateStamp());
+        /*
+         * Invoking the deprecated setters shall modify the CitationDate object
+         * associated to DateType.CREATION.
+         */
+        creation = date("2014-10-06 00:00:00");
+        metadata.setDateStamp(creation);
+        assertEquals("citationDates[1].date", creation, dates[1].getDate());
+        assertArrayEquals("dates", dates, metadata.getDates().toArray());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getMetadataStandardName()}, {@link DefaultMetadata#getMetadataStandardVersion()},
+     * {@link DefaultMetadata#setMetadataStandardName(String)} and {@link DefaultMetadata#setMetadataStandardVersion(String)}
+     * methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testMetadataStandard() {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertNull("metadataStandardName",    metadata.getMetadataStandardName());
+        assertNull("metadataStandardVersion", metadata.getMetadataStandardVersion());
+
+        String name = "ISO 19115-2 Geographic Information - Metadata Part 2 Extensions for
imagery and gridded data";
+        String version = "ISO 19115-2:2009(E)";
+        metadata.setMetadataStandardName(name);
+        metadata.setMetadataStandardVersion(version);
+        assertEquals("metadataStandardName",    name,    metadata.getMetadataStandardName());
+        assertEquals("metadataStandardVersion", version, metadata.getMetadataStandardVersion());
+        final Citation standard = getSingleton(metadata.getMetadataStandards());
+        assertEquals(name,    standard.getTitle()  .toString());
+        assertEquals(version, standard.getEdition().toString());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getDataSetUri()}.
+     *
+     * @throws URISyntaxException Should not happen.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testDataSetUri() throws URISyntaxException {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        metadata.setDataSetUri("file:/tmp/myfile.txt");
+        assertEquals("file:/tmp/myfile.txt", metadata.getDataSetUri());
+        assertEquals("file:/tmp/myfile.txt", getSingleton(getSingleton(metadata.getIdentificationInfo())
+                .getCitation().getOnlineResources()).getLinkage().toString());
+    }
 }

Modified: sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java
[UTF-8] Mon Oct 13 10:32:55 2014
@@ -16,6 +16,10 @@
  */
 package org.apache.sis.metadata.iso.identification;
 
+import java.util.Collection;
+import java.util.Map;
+import java.util.Locale;
+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,20 +33,24 @@ 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.*;
 
+// Branch-specific imports
+import org.apache.sis.internal.jdk7.StandardCharsets;
+
 
 /**
  * Tests {@link DefaultDataIdentification}.
  *
  * @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 +58,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 +101,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 +118,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 +153,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 +166,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/JDK6/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Mon Oct 13 10:32:55 2014
@@ -32,6 +32,7 @@ import org.junit.BeforeClass;
 @Suite.SuiteClasses({
     org.apache.sis.internal.metadata.MetadataUtilitiesTest.class,
     org.apache.sis.internal.metadata.ReferencingUtilitiesTest.class,
+    org.apache.sis.internal.metadata.OtherLocalesTest.class,
 
     // Classes using Java reflection.
     org.apache.sis.metadata.PropertyInformationTest.class,

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardCharsets.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardCharsets.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardCharsets.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardCharsets.java
[UTF-8] Mon Oct 13 10:32:55 2014
@@ -49,4 +49,9 @@ public final class StandardCharsets {
      * ISO/IEC 8859-1, Information technology - 8-bit single byte coded graphic character
sets - Part 1 : Latin alphabet No.1.
      */
     public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
+
+    /**
+     * Seven-bit ASCII, a.k.a. ISO646-US.
+     */
+    public static final Charset US_ASCII = Charset.forName("US-ASCII");
 }

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1631337&r1=1631336&r2=1631337&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] Mon Oct 13 10:32:55 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