sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1513589 - in /sis/branches/JDK7/core/sis-metadata/src: main/java/org/apache/sis/metadata/iso/ main/java/org/apache/sis/metadata/iso/identification/ test/java/org/apache/sis/metadata/iso/identification/ test/java/org/apache/sis/test/suite/
Date Tue, 13 Aug 2013 16:44:09 GMT
Author: desruisseaux
Date: Tue Aug 13 16:44:09 2013
New Revision: 1513589

URL: http://svn.apache.org/r1513589
Log:
DefaultRepresentiveFraction needs to implement IdentifiedObject (SIS-122).

Added:
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java?rev=1513589&r1=1513588&r2=1513589&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] Tue Aug 13 16:44:09 2013
@@ -99,6 +99,16 @@ public class ISOMetadata extends Modifia
         return MetadataStandard.ISO_19115;
     }
 
+
+
+
+    // --------------------------------------------------------------------------------------
+    // Code below this point also appears in other IdentifiedObject implementations.
+    // If this code is modified, consider revisiting also the following classes:
+    //
+    //   * org.apache.sis.metadata.iso.identification.DefaultRepresentativeFraction
+    // --------------------------------------------------------------------------------------
+
     /**
      * {@inheritDoc}
      */
@@ -170,10 +180,8 @@ public class ISOMetadata extends Modifia
     /**
      * Sets an unique identifier.
      * This method is invoked automatically by JAXB and should never be invoked explicitely.
-     *
-     * @throws IllegalArgumentException If the UUID is already assigned to an other object.
      */
-    private void setUUID(String id) {
+    private void setUUID(final String id) {
         /*
          * IdentifierMapWithSpecialCases will take care of converting the String to UUID
if possible,
          * or will store the value as a plain String if it can not be converted. In the later
case, a

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java?rev=1513589&r1=1513588&r2=1513589&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
[UTF-8] Tue Aug 13 16:44:09 2013
@@ -16,15 +16,28 @@
  */
 package org.apache.sis.metadata.iso.identification;
 
+import java.util.Collection;
+import javax.xml.bind.annotation.XmlID;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
+import org.opengis.metadata.Identifier;
 import org.opengis.metadata.identification.RepresentativeFraction;
+import org.apache.sis.internal.jaxb.IdentifierMapWithSpecialCases;
 import org.apache.sis.internal.jaxb.gco.GO_Integer64;
+import org.apache.sis.internal.util.CheckedArrayList;
+import org.apache.sis.xml.IdentifierMap;
+import org.apache.sis.xml.IdentifierSpace;
+import org.apache.sis.xml.IdentifiedObject;
+import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 
+import static org.apache.sis.util.collection.Containers.isNullOrEmpty;
+
 
 /**
  * A scale defined as the inverse of a denominator.
@@ -38,12 +51,12 @@ import org.apache.sis.util.resources.Err
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.4)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @XmlType(name = "MD_RepresentativeFraction_Type")
 @XmlRootElement(name = "MD_RepresentativeFraction")
-public class DefaultRepresentativeFraction extends Number implements RepresentativeFraction
{
+public class DefaultRepresentativeFraction extends Number implements RepresentativeFraction,
IdentifiedObject {
     /**
      * Serial number for compatibility with different versions.
      */
@@ -55,6 +68,12 @@ public class DefaultRepresentativeFracti
     private long denominator;
 
     /**
+     * All identifiers associated with this metadata, or {@code null} if none.
+     * This field is initialized to a non-null value when first needed.
+     */
+    private Collection<Identifier> identifiers;
+
+    /**
      * Creates a uninitialized representative fraction.
      * The {@linkplain #getDenominator() denominator} is initially zero
      * and the {@linkplain #doubleValue() double value} is NaN.
@@ -211,4 +230,78 @@ public class DefaultRepresentativeFracti
     public int hashCode() {
         return (int) denominator;
     }
+
+
+
+
+    // --------------------------------------------------------------------------------------
+    // Code below this point is basically a copy-and-paste of ISOMetadata, with some edition.
+    // The JAXB attributes defined here shall be the same than the ISOMetadata ones.
+    // --------------------------------------------------------------------------------------
+
+    /**
+     * Returns all identifiers associated to this object, or an empty collection if none.
+     * Those identifiers are marshalled in XML as {@code id} or {@code uuid} attributes.
+     */
+    @Override
+    public Collection<Identifier> getIdentifiers() {
+        if (identifiers == null) {
+            identifiers = new CheckedArrayList<>(Identifier.class);
+        }
+        return identifiers;
+    }
+
+    /**
+     * Returns a map view of the {@linkplain #getIdentifiers() identifiers} collection as
(<var>authority</var>,
+     * <var>code</var>) entries. That map is <cite>live</cite>: changes
in the identifiers list will be reflected
+     * in the map, and conversely.
+     */
+    @Override
+    public IdentifierMap getIdentifierMap() {
+        return new IdentifierMapWithSpecialCases(getIdentifiers());
+    }
+
+    /**
+     * Invoked by JAXB for fetching the unique identifier unique for the XML document.
+     *
+     * @see org.apache.sis.metadata.iso.ISOMetadata#getID()
+     */
+    @XmlID
+    @XmlAttribute  // Defined in "gco" as unqualified attribute.
+    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
+    private String getID() {
+        return isNullOrEmpty(identifiers) ? null : getIdentifierMap().getSpecialized(IdentifierSpace.ID);
+    }
+
+    /**
+     * Invoked by JAXB for specifying the unique identifier.
+     *
+     * @see org.apache.sis.metadata.iso.ISOMetadata#setID(String)
+     */
+    private void setID(String id) {
+        id = CharSequences.trimWhitespaces(id);
+        if (id != null && !id.isEmpty()) {
+            getIdentifierMap().putSpecialized(IdentifierSpace.ID, id);
+        }
+    }
+
+    /**
+     * Invoked by JAXB for fetching the unique identifier unique "worldwide".
+     *
+     * @see org.apache.sis.metadata.iso.ISOMetadata#getUUID()
+     */
+    @XmlAttribute  // Defined in "gco" as unqualified attribute.
+    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
+    private String getUUID() {
+        return isNullOrEmpty(identifiers) ? null : getIdentifierMap().get(IdentifierSpace.UUID);
+    }
+
+    /**
+     * Invoked by JAXB for specifying the unique identifier.
+     *
+     * @see org.apache.sis.metadata.iso.ISOMetadata#setUUID(String)
+     */
+    private void setUUID(final String id) {
+        getIdentifierMap().put(IdentifierSpace.UUID, id);
+    }
 }

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java?rev=1513589&r1=1513588&r2=1513589&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
[UTF-8] Tue Aug 13 16:44:09 2013
@@ -68,6 +68,20 @@ public class DefaultResolution extends I
     }
 
     /**
+     * Creates a new resolution initialized to the given scale.
+     *
+     * @param scale The scale, or {@code null} if none.
+     *
+     * @since 0.4
+     */
+    public DefaultResolution(final RepresentativeFraction scale) {
+        scaleOrDistance = scale;
+    }
+
+    // Note: there is not yet DefaultResolution(double) method because
+    //       we need to update the Unit Of Measurement package first.
+
+    /**
      * Constructs a new instance initialized with the values from the specified metadata
object.
      * This is a <cite>shallow</cite> copy constructor, since the other metadata
contained in the
      * given object are not recursively copied.

Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java?rev=1513589&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java
(added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java
[UTF-8] Tue Aug 13 16:44:09 2013
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.metadata.iso.identification;
+
+import javax.xml.bind.JAXBException;
+import org.apache.sis.xml.XML;
+import org.apache.sis.xml.IdentifierSpace;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link DefaultRepresentativeFraction}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final strictfp class DefaultRepresentativeFractionTest extends TestCase {
+    /**
+     * Test {@link DefaultRepresentativeFraction#setScale(double)}.
+     */
+    @Test
+    public void testSetScale() {
+        final DefaultRepresentativeFraction fraction = new DefaultRepresentativeFraction();
+        assertEquals("Initial value", 0L, fraction.getDenominator());
+        assertTrue("Initial value", Double.isNaN(fraction.doubleValue()));
+
+        fraction.setScale(0.25);
+        assertEquals("getDenominator()", 4L, fraction.getDenominator());
+        assertEquals("doubleValue()", 0.25, fraction.doubleValue(), 0.0);
+    }
+
+    /**
+     * Tests XML marshalling of identifiers.
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    public void testIdentifiers() throws JAXBException {
+        final DefaultRepresentativeFraction fraction = new DefaultRepresentativeFraction(8);
+        fraction.getIdentifierMap().putSpecialized(IdentifierSpace.ID, "scale");
+        final String xml = XML.marshal(fraction);
+        assertXmlEquals(
+                "<gmd:MD_RepresentativeFraction id=\"scale\">\n" +
+                "  <gmd:denominator>\n" +
+                "    <gco:Integer>8</gco:Integer>\n" +
+                "  </gmd:denominator>\n" +
+                "</gmd:MD_RepresentativeFraction>", xml, "xmlns:*");
+        /*
+         * Unmarshal the element back to a Java object and compare to the original.
+         */
+        assertEquals(fraction, XML.unmarshal(xml));
+    }
+}

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java?rev=1513589&r1=1513588&r2=1513589&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
[UTF-8] Tue Aug 13 16:44:09 2013
@@ -19,6 +19,7 @@ package org.apache.sis.metadata.iso.iden
 import javax.xml.bind.JAXBException;
 import org.apache.sis.xml.XML;
 import org.apache.sis.metadata.iso.LoggingWatcher;
+import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Rule;
 import org.junit.Test;
@@ -34,6 +35,7 @@ import static org.apache.sis.test.Assert
  * @version 0.3
  * @module
  */
+@DependsOn(DefaultRepresentativeFractionTest.class)
 public final strictfp class DefaultResolutionTest extends TestCase {
     /**
      * A JUnit {@linkplain Rule rule} for listening to log events. This field is public

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1513589&r1=1513588&r2=1513589&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Tue Aug 13 16:44:09 2013
@@ -34,6 +34,7 @@ import org.junit.BeforeClass;
     org.apache.sis.metadata.iso.citation.DefaultCitationDateTest.class,
     org.apache.sis.metadata.iso.citation.DefaultCitationTest.class,
     org.apache.sis.metadata.iso.identification.DefaultKeywordsTest.class,
+    org.apache.sis.metadata.iso.identification.DefaultRepresentativeFractionTest.class,
     org.apache.sis.metadata.iso.identification.DefaultResolutionTest.class,
     org.apache.sis.metadata.iso.spatial.DefaultGeorectifiedTest.class,
     org.apache.sis.metadata.iso.maintenance.DefaultScopeDescriptionTest.class,



Mime
View raw message