sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1531309 - in /sis/branches/JDK7/core: sis-referencing/src/main/java/org/apache/sis/referencing/ sis-referencing/src/main/java/org/apache/sis/referencing/datum/ sis-utility/src/main/java/org/apache/sis/internal/system/ sis-utility/src/test/...
Date Fri, 11 Oct 2013 14:31:02 GMT
Author: desruisseaux
Date: Fri Oct 11 14:31:01 2013
New Revision: 1531309

URL: http://svn.apache.org/r1531309
Log:
Moved DefaultEllipsoid constants to StandardObjects.Geodetic.

Added:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
  (with props)
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java

Added: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java?rev=1531309&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
[UTF-8] Fri Oct 11 14:31:01 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.referencing;
+
+import java.util.Map;
+import java.util.HashMap;
+import javax.measure.unit.SI;
+import javax.measure.unit.Unit;
+import javax.measure.quantity.Length;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.referencing.datum.Ellipsoid;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.referencing.datum.DefaultEllipsoid;
+
+import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
+import static org.opengis.referencing.IdentifiedObject.ALIAS_KEY;
+import static org.opengis.referencing.IdentifiedObject.IDENTIFIERS_KEY;
+
+
+/**
+ * Definitions of referencing objects identified by the {@link StandardObjects} constants.
+ * This class is used only as a fallback if the objects can not be fetched from the EPSG
database.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4 (derived from geotk-1.2)
+ * @version 0.4
+ * @module
+ */
+final class StandardDefinitions {
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private StandardDefinitions() {
+    }
+
+    /**
+     * Creates an ellipsoid from hard-coded values for the given code.
+     *
+     * @param  code The EPSG or SIS code.
+     * @return The ellipsoid for the given code.
+     */
+    static Ellipsoid createEllipsoid(final short code) {
+        String  name;          // No default value
+        String  alias          = null;
+        double  semiMajorAxis; // No default value
+        double  other;         // No default value
+        boolean ivfDefinitive  = true;
+        Unit<Length> unit      = SI.METRE;
+        switch (code) {
+            case 7030: name  = "WGS 84";       alias = "WGS84";              semiMajorAxis
= 6378137.0; other = 298.257223563; break;
+            case 7043: name  = "WGS 72";       alias = "NWL 10D";            semiMajorAxis
= 6378135.0; other = 298.26;        break;
+            case 7019: name  = "GRS 1980";     alias = "International 1979"; semiMajorAxis
= 6378137.0; other = 298.257222101; break;
+            case 7022: alias = "Hayford 1909"; name  = "International 1924"; semiMajorAxis
= 6378388.0; other = 297.0;         break;
+            case 7008: name  = "Clarke 1866";  ivfDefinitive = false;        semiMajorAxis
= 6378206.4; other = 6356583.8;     break;
+            case   -1: name  = "Sphere";       ivfDefinitive = false;        semiMajorAxis
=            other = 6371000;       break;
+            default:   throw new AssertionError(code);
+        }
+        final Map<String,Object> map = new HashMap<>(8);
+        final Citation authority;
+        if (code >= 0) {
+            map.put(IDENTIFIERS_KEY, new NamedIdentifier(authority = Citations.EPSG, String.valueOf(code)));
+        } else {
+            authority = Citations.SIS;
+        }
+        map.put(NAME_KEY, new NamedIdentifier(authority, name));
+        map.put(ALIAS_KEY, alias); // May be null, which is okay.
+        if (ivfDefinitive) {
+            return DefaultEllipsoid.createFlattenedSphere(map, semiMajorAxis, other, unit);
+        } else {
+            return DefaultEllipsoid.createEllipsoid(map, semiMajorAxis, other, unit);
+        }
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java?rev=1531309&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
[UTF-8] Fri Oct 11 14:31:01 2013
@@ -0,0 +1,383 @@
+/*
+ * 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.referencing;
+
+import java.lang.reflect.Field;
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
+import javax.measure.unit.SI;
+import org.opengis.util.FactoryException;
+import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.crs.GeodeticCRS;
+import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.DatumAuthorityFactory;
+import org.apache.sis.internal.system.Modules;
+import org.apache.sis.internal.system.SystemListener;
+import org.apache.sis.util.logging.Logging;
+
+
+/**
+ * Frequently-used referencing objects that are guaranteed to be available in SIS.
+ * Methods in sub-classes are shortcuts for object definitions in the EPSG database.
+ * If there is no EPSG database available, or if the query failed, or if there is no EPSG
definition for an object,
+ * then {@code StandardObjects} fallback on hard-coded values. Consequently, those methods
never return {@code null}.
+ *
+ * <p>Referencing objects are cached after creation. Invoking the same method on the
same {@code StandardObjects}
+ * instance twice will return the same {@link IdentifiedObject} instance, unless the internal
cache has been cleared
+ * (e.g. the application is running in a container environment, and some modules have been
installed or uninstalled).</p>
+ *
+ * <blockquote><font size="-1"><b>Example:</b> the following code
fetches a Coordinate Reference System using
+ * (<var>longitude</var>, <var>latitude</var>) axis order on the
{@link Geodetic#WGS84 WGS84} geodetic datum:
+ *
+ * {@preformat java
+ *   GeographicCRS crs = StandardObjects.Geodetic.WGS84.crs(true);
+ * }
+ * </font></blockquote>
+ *
+ * {@section Index}
+ * <blockquote><table class="compact">
+ *   <tr><td>Clarke 1866</td>                                       <td>{@link
Geodetic#NAD27  Geodetic.NAD27}</td></tr>
+ *   <tr><td>European Datum 1950 (ED50)</td>                        <td>{@link
Geodetic#ED50   Geodetic.ED50}</td></tr>
+ *   <tr><td>European Terrestrial Reference Frame (ETRS) 1989</td>  <td>{@link
Geodetic#ETRS89 Geodetic.ETRS89}</td></tr>
+ *   <tr><td>European Terrestrial Reference System (ETRF) 1989</td> <td>{@link
Geodetic#ETRS89 Geodetic.ETRS89}</td></tr>
+ *   <tr><td>GRS 1980</td>                                          <td>{@link
Geodetic#ETRS89 Geodetic.ETRS89}, {@link Geodetic#NAD83 NAD83}</td></tr>
+ *   <tr><td>Hayford 1909</td>                                      <td>{@link
Geodetic#ED50   Geodetic.ED50}</td></tr>
+ *   <tr><td>International 1924</td>                                <td>{@link
Geodetic#ED50   Geodetic.ED50}</td></tr>
+ *   <tr><td>International 1979</td>                                <td>{@link
Geodetic#ETRS89 Geodetic.ETRS89}, {@link Geodetic#NAD83 NAD83}</td></tr>
+ *   <tr><td>North American Datum 1927</td>                         <td>{@link
Geodetic#NAD27  Geodetic.NAD27}</td></tr>
+ *   <tr><td>North American Datum 1983</td>                         <td>{@link
Geodetic#NAD83  Geodetic.NAD83}</td></tr>
+ *   <tr><td>NWL 10D</td>                                           <td>{@link
Geodetic#WGS72  Geodetic.WGS72}</td></tr>
+ *   <tr><td>World Geodetic System (WGS) 1972</td>                  <td>{@link
Geodetic#WGS72  Geodetic.WGS72}</td></tr>
+ *   <tr><td>World Geodetic System (WGS) 1984</td>                  <td>{@link
Geodetic#WGS84  Geodetic.WGS84}</td></tr>
+ * </table></blockquote>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public abstract class StandardObjects implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = 4441181475750580370L;
+
+    /**
+     * Invoked when the classpath changed. The listener will clear the cache of all constants.
+     */
+    static {
+        SystemListener.add(new SystemListener(Modules.REFERENCING) {
+            @Override protected void classpathChanged() {
+                try {
+                    for (final Class<?> c : StandardObjects.class.getClasses()) {
+                        for (final Field field : c.getFields()) {
+                            final StandardObjects s = (StandardObjects) field.get(null);
+                            s.clear();
+                        }
+                    }
+                } catch (ReflectiveOperationException e) {
+                    throw new AssertionError(e); // Should never happen.
+                }
+            }
+        });
+    }
+
+    /**
+     * The programmatic constant name.
+     */
+    private final String name;
+
+    /**
+     * The cached object. This is initially {@code null}, then set to various kind of objects
depending
+     * on which method has been invoked. The kind of object stored in this field may change
during the
+     * application execution.
+     */
+    transient volatile IdentifiedObject cached;
+
+    /**
+     * For sub-classes constructors only.
+     *
+     * @param name The programmatic constant name.
+     */
+    StandardObjects(final String name) {
+        this.name = name;
+    }
+
+    /**
+     * Invoked when the cache needs to be cleared.
+     */
+    synchronized void clear() {
+        cached = null;
+    }
+
+    /**
+     * Returns the EPSG factory to use for creating datum, ellipsoids and prime meridians,
or {@code null} if none.
+     * If this method returns {@code null}, then the caller will silently fallback on hard-coded
values.
+     */
+    static DatumAuthorityFactory datumFactory() {
+        return null; // TODO
+    }
+
+    /**
+     * Invoked when a factory failed to create an object.
+     * After invoking this method, then the caller will fallback on hard-coded values.
+     */
+    final void failure(final String method, final FactoryException e) {
+        Logging.unexpectedException(getClass(), method, e);
+    }
+
+    /**
+     * Returns a string representation of this constant.
+     */
+    @Override
+    public final String toString() {
+        return getClass().getSimpleName() + '.' + name;
+    }
+
+    /**
+     * Invoked on deserialization for resolving to the singleton constant.
+     */
+    final Object readResolve() throws ObjectStreamException {
+        try {
+            return getClass().getField(name).get(null);
+        } catch (ReflectiveOperationException e) {
+            throw (InvalidObjectException) new InvalidObjectException(toString()).initCause(e);
+        }
+    }
+
+
+
+
+    /**
+     * Frequently-used geodetic CRS and datum that are guaranteed to be available in SIS.
+     * Methods in this class are shortcuts for object definitions in the EPSG database.
+     * If there is no EPSG database available, or if the query failed, or if there is no
EPSG definition for an object,
+     * then {@code StandardObjects} fallback on hard-coded values. Consequently, those methods
never return {@code null}.
+     *
+     * {@section Index}
+     * <blockquote><table class="compact">
+     *   <tr><td>Clarke 1866</td>                                     
 <td>{@link #NAD27}</td></tr>
+     *   <tr><td>European Datum 1950 (ED50)</td>                      
 <td>{@link #ED50}</td></tr>
+     *   <tr><td>European Terrestrial Reference Frame (ETRS) 1989</td>
 <td>{@link #ETRS89}</td></tr>
+     *   <tr><td>European Terrestrial Reference System (ETRF) 1989</td>
<td>{@link #ETRS89}</td></tr>
+     *   <tr><td>GRS 1980</td>                                        
 <td>{@link #ETRS89}, {@link #NAD83}</td></tr>
+     *   <tr><td>Hayford 1909</td>                                    
 <td>{@link #ED50}</td></tr>
+     *   <tr><td>International 1924</td>                              
 <td>{@link #ED50}</td></tr>
+     *   <tr><td>International 1979</td>                              
 <td>{@link #ETRS89}, {@link #NAD83}</td></tr>
+     *   <tr><td>North American Datum 1927</td>                       
 <td>{@link #NAD27}</td></tr>
+     *   <tr><td>North American Datum 1983</td>                       
 <td>{@link #NAD83}</td></tr>
+     *   <tr><td>NWL 10D</td>                                         
 <td>{@link #WGS72}</td></tr>
+     *   <tr><td>World Geodetic System (WGS) 1972</td>                
 <td>{@link #WGS72}</td></tr>
+     *   <tr><td>World Geodetic System (WGS) 1984</td>                
 <td>{@link #WGS84}</td></tr>
+     * </table></blockquote>
+     *
+     * @author  Martin Desruisseaux (Geomatys)
+     * @since   0.4
+     * @version 0.4
+     * @module
+     */
+    public static final class Geodetic extends StandardObjects {
+        /**
+         * For cross-version compatibility.
+         */
+        private static final long serialVersionUID = 7751726848523836148L;
+
+        /**
+         * The EPSG or SIS code of the ellipsoid.
+         */
+        private final short ellipsoid;
+
+        /**
+         * World Geodetic System 1984.
+         * This is the default CRS for most {@code org.apache.sis} packages.
+         *
+         * <blockquote><table class="compact" style="text-align:left">
+         *   <tr><th>WMS identifier:</th>          <td>CRS:84</td></tr>
+         *   <tr><th>EPSG identifiers:</th>        <td>4326 &nbsp;(<i>datum:</i>
6326, &nbsp;<i>ellipsoid:</i> 7030)</td></tr>
+         *   <tr><th>Primary names:</th>           <td>"WGS 84" &nbsp;(<i>datum:</i>
"World Geodetic System 1984")</td></tr>
+         *   <tr><th>Abbreviations or aliases:</th><td>(<i>datum:</i>
"WGS 84", &nbsp;<i>ellipsoid:</i> "WGS84")</td></tr>
+         *   <tr><th>Semi-major axis length:</th>  <td>6378137</td></tr>
+         *   <tr><th>Semi-minor axis length:</th>  <td>6356752 <i>(approximative)</i></td></tr>
+         *   <tr><th>Inverse flattening:</th>      <td>298.257223563
<i>(definitive)</i></td></tr>
+         *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
+         * </table></blockquote>
+         */
+        public static final Geodetic WGS84 = new Geodetic("WGS84", (short) 7030);
+
+        /**
+         * World Geodetic System 1972.
+         *
+         * <blockquote><table class="compact" style="text-align:left">
+         *   <tr><th>EPSG identifiers:</th>        <td>4322 &nbsp;(<i>datum:</i>
6322, &nbsp;<i>ellipsoid:</i> 7043)</td></tr>
+         *   <tr><th>Primary names:</th>           <td>"WGS 72" &nbsp;(<i>datum:</i>
"World Geodetic System 1972")</td></tr>
+         *   <tr><th>Abbreviations or aliases:</th><td>(<i>datum:</i>
"WGS 72", &nbsp;<i>ellipsoid:</i> "NWL 10D")</td></tr>
+         *   <tr><th>Semi-major axis length:</th>  <td>6378135</td></tr>
+         *   <tr><th>Semi-minor axis length:</th>  <td>6356751 <i>(approximative)</i></td></tr>
+         *   <tr><th>Inverse flattening:</th>      <td>298.26 <i>(definitive)</i></td></tr>
+         *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
+         * </table></blockquote>
+         */
+        public static final Geodetic WGS72 = new Geodetic("WGS72", (short) 7043);
+
+        /**
+         * European Terrestrial Reference System 1989.
+         * The ellipsoid is <cite>"GRS 1980"</cite>, also known as <cite>"International
1979"</cite>.
+         * This ellipsoid is very close, but not identical, to the {@linkplain #WGS84} one.
+         *
+         * <blockquote><table class="compact" style="text-align:left">
+         *   <tr><th>EPSG identifiers:</th>        <td>4258 &nbsp;(<i>datum:</i>
6258, &nbsp;<i>ellipsoid:</i> 7019)</td></tr>
+         *   <tr><th>Primary names:</th>           <td>"ETRS89" &nbsp;(<i>datum:</i>
"European Terrestrial Reference System 1989", &nbsp;<i>ellipsoid:</i> "GRS
1980")</td></tr>
+         *   <tr><th>Abbreviations or aliases:</th><td>"ETRF89",
"EUREF89", "ETRS89-GRS80" &nbsp;(<i>ellipsoid:</i> "International 1979")</td></tr>
+         *   <tr><th>Semi-major axis length:</th>  <td>6378137</td></tr>
+         *   <tr><th>Semi-minor axis length:</th>  <td>6356752 <i>(approximative)</i></td></tr>
+         *   <tr><th>Inverse flattening:</th>      <td>298.257222101
<i>(definitive)</i></td></tr>
+         *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
+         * </table></blockquote>
+         *
+         * {@note <cite>NAD83</cite> uses the same ellipsoid for a different
datum.
+         *        The <cite>Web Map Server</cite> <code>"CRS:83"</code>
authority code uses the NAD83 datum,
+         *        while the <code>"IGNF:MILLER"</code> authority code uses the
GRS80 datum.}
+         */
+        public static final Geodetic ETRS89 = new Geodetic("ETRS89", (short) 7019);
+
+        /**
+         * North American Datum 1983.
+         * The ellipsoid is <cite>"GRS 1980"</cite>, also known as <cite>"International
1979"</cite>.
+         * This ellipsoid is very close, but not identical, to the {@linkplain #WGS84} one.
+         *
+         * <blockquote><table class="compact" style="text-align:left">
+         *   <tr><th>WMS identifier:</th>          <td>CRS:83</td></tr>
+         *   <tr><th>EPSG identifiers:</th>        <td>4269 &nbsp;(<i>datum:</i>
6269, &nbsp;<i>ellipsoid:</i> 7019)</td></tr>
+         *   <tr><th>Primary names:</th>           <td>"NAD83" &nbsp;(<i>datum:</i>
"North American Datum 1983", &nbsp;<i>ellipsoid:</i> "GRS 1980")</td></tr>
+         *   <tr><th>Abbreviations or aliases:</th><td>"NAD83 (1986)"
&nbsp;(<i>ellipsoid:</i> "International 1979")</td></tr>
+         *   <tr><th>Semi-major axis length:</th>  <td>6378137</td></tr>
+         *   <tr><th>Semi-minor axis length:</th>  <td>6356752 <i>(approximative)</i></td></tr>
+         *   <tr><th>Inverse flattening:</th>      <td>298.257222101
<i>(definitive)</i></td></tr>
+         *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
+         * </table></blockquote>
+         *
+         * {@note <cite>ETRS89</cite> uses the same ellipsoid for a different
datum.
+         *        The <cite>Web Map Server</cite> <code>"CRS:83"</code>
authority code uses the NAD83 datum,
+         *        while the <code>"IGNF:MILLER"</code> authority code uses the
GRS80 datum.}
+         */
+        public static final Geodetic NAD83 = new Geodetic("NAD83", (short) 7019);
+
+        /**
+         * North American Datum 1927.
+         *
+         * <blockquote><table class="compact" style="text-align:left">
+         *   <tr><th>WMS identifier:</th>          <td>CRS:27</td></tr>
+         *   <tr><th>EPSG identifiers:</th>        <td>4267 &nbsp;(<i>datum:</i>
6267, &nbsp;<i>ellipsoid:</i> 7008)</td></tr>
+         *   <tr><th>Primary names:</th>           <td>"NAD27" &nbsp;(<i>datum:</i>
"North American Datum 1927", &nbsp;<i>ellipsoid:</i> "Clarke 1866")</td></tr>
+         *   <tr><th>Abbreviations or aliases:</th><td>(<i>datum:</i>
"NAD27")</td></tr>
+         *   <tr><th>Semi-major axis length:</th>  <td>6378206.4</td></tr>
+         *   <tr><th>Semi-minor axis length:</th>  <td>6356583.8
<i>(definitive)</i></td></tr>
+         *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
+         * </table></blockquote>
+         */
+        public static final Geodetic NAD27 = new Geodetic("NAD27", (short) 7008);
+
+        /**
+         * European Datum 1950.
+         *
+         * <blockquote><table class="compact" style="text-align:left">
+         *   <tr><th>EPSG identifiers:</th>        <td>4230 &nbsp;(<i>datum:</i>
6230, &nbsp;<i>ellipsoid:</i> 7022)</td></tr>
+         *   <tr><th>Primary names:</th>           <td>"ED50" &nbsp;(<i>datum:</i>
"European Datum 1950", &nbsp;<i>ellipsoid:</i> "International 1924")</td></tr>
+         *   <tr><th>Abbreviations or aliases:</th><td>(<i>datum:</i>
"ED50", <i>ellipsoid:</i> "Hayford 1909")</td></tr>
+         *   <tr><th>Semi-major axis length:</th>  <td>6378388</td></tr>
+         *   <tr><th>Semi-minor axis length:</th>  <td>6356912 <i>(approximative)</i></td></tr>
+         *   <tr><th>Inverse flattening:</th>      <td>297 <i>(definitive)</i></td></tr>
+         *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
+         * </table></blockquote>
+         */
+        public static final Geodetic ED50 = new Geodetic("ED50", (short) 7022);
+
+        /**
+         * A sphere with a radius of 6371000 metres. Spheres use a simpler algorithm for
+         * {@linkplain org.apache.sis.referencing.datum.DefaultEllipsoid#orthodromicDistance
+         * orthodromic distance computation}, which may be faster and more robust.
+         *
+         * <blockquote><table class="compact" style="text-align:left">
+         *   <tr><th>Primary names:</th>           <td>"Sphere"</td></tr>
+         *   <tr><th>Semi-major axis length:</th>  <td>6371000</td></tr>
+         *   <tr><th>Semi-minor axis length:</th>  <td>6371000 <i>(definitive)</i></td></tr>
+         *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
+         * </table></blockquote>
+         *
+         * {@note This ellipsoid is close to the <cite>GRS 1980 Authalic Sphere</cite>
(EPSG:7048),
+         *        which has a radius of 6371007 metres.}
+         */
+        public static final Geodetic SPHERE = new Geodetic("SPHERE", (short) -1);
+
+        /**
+         * Creates a new constant for the given EPSG or SIS codes.
+         * By convention, SIS codes are negative.
+         *
+         * @param name The programmatic constant name.
+         * @param ellipsoid The code for the ellipsoid.
+         */
+        private Geodetic(final String name, final short ellipsoid) {
+            super(name);
+            this.ellipsoid = ellipsoid;
+        }
+
+        /**
+         * Returns the ellipsoid associated to this geodetic object.
+         *
+         * @return The ellipsoid.
+         */
+        public Ellipsoid ellipsoid() {
+            Ellipsoid object = ellipsoid(cached);
+            if (object == null) {
+                synchronized (this) {
+                    object = ellipsoid(cached);
+                    if (object == null) {
+                        if (ellipsoid >= 0) {
+                            final DatumAuthorityFactory factory = datumFactory();
+                            if (factory != null) try {
+                                cached = object = factory.createEllipsoid(String.valueOf(ellipsoid));
+                                return object;
+                            } catch (FactoryException e) {
+                                failure("ellipsoid", e);
+                            }
+                        }
+                        cached = object = StandardDefinitions.createEllipsoid(ellipsoid);
+                    }
+                }
+            }
+            return object;
+        }
+
+        /**
+         * Returns the ellipsoid associated to the given object, or {@code null} if none.
+         */
+        private static Ellipsoid ellipsoid(final IdentifiedObject object) {
+            if (object instanceof Ellipsoid) {
+                return (Ellipsoid) object;
+            }
+            if (object instanceof GeodeticDatum) {
+                return ((GeodeticDatum) object).getEllipsoid();
+            }
+            if (object instanceof GeodeticCRS) {
+                return ((GeodeticCRS) object).getDatum().getEllipsoid();
+            }
+            return null;
+        }
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1531309&r1=1531308&r2=1531309&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Fri Oct 11 14:31:01 2013
@@ -17,7 +17,6 @@
 package org.apache.sis.referencing.datum;
 
 import java.util.Map;
-import java.util.HashMap;
 import java.util.Collections;
 import javax.measure.unit.SI;
 import javax.measure.unit.Unit;
@@ -33,10 +32,8 @@ import org.apache.sis.internal.jaxb.Cont
 import org.apache.sis.internal.jaxb.gco.Measure;
 import org.apache.sis.internal.jaxb.referencing.SecondDefiningParameter;
 import org.apache.sis.internal.referencing.Formulas;
-import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
-import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.util.ComparisonMode;
@@ -72,11 +69,15 @@ import java.util.Objects;
  *   <li>{@linkplain #getEccentricity() eccentricity}</li>
  * </ul>
  *
- * {@section Calculations}
+ * {@section Distance calculations}
  * This class contains an {@link #orthodromicDistance(double, double, double, double)} convenience
method
  * for calculating distances on the great circle. This convenience method is provided as
an alternative to
  * the {@link org.apache.sis.referencing.GeodeticCalculator}.
  *
+ * {@section Frequently used ellipsoids}
+ * A set of constants for frequently used ellipsoids is defined in the
+ * {@link org.apache.sis.referencing.StandardObjects.Geodetic} class.
+ *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Cédric Briançon (Geomatys)
  * @since   0.4 (derived from geotk-1.2)
@@ -113,97 +114,6 @@ public class DefaultEllipsoid extends Ab
     private static final double COMPARISON_THRESHOLD = 1E-10;
 
     /**
-     * Returns a properties map with the given name and EPSG code.
-     * This is used for the creation of default ellipsoid constants.
-     */
-    private static Map<String,?> properties(final String name, final int code, final
Object alias) {
-        final Map<String,Object> map = new HashMap<>(8);
-        map.put(NAME_KEY, name);
-        map.put(IDENTIFIERS_KEY, new NamedIdentifier(Citations.EPSG, String.valueOf(code)));
-        if (alias != null) {
-            map.put(ALIAS_KEY, alias);
-        }
-        return map;
-    }
-
-    /**
-     * WGS 1984 ellipsoid used in GPS systems.
-     * This is the default ellipsoid for most {@code org.apache.sis} packages.
-     *
-     *  <blockquote><table class="compact" style="text-align: left;">
-     *   <tr><th>EPSG code:</th>          <td>7030</td></tr>
-     *   <tr><th>Name and aliases:</th>   <td>WGS84, WGS 1984</td></tr>
-     *   <tr><th>Semi-major axis:</th>    <td>6378137</td></tr>
-     *   <tr><th>Semi-minor axis:</th>    <td>6356752 (approximative)</td></tr>
-     *   <tr><th>Inverse flattening:</th> <td>298.257223563 (definitive)</td></tr>
-     *   <tr><th>Axis unit:</th>          <td>{@link SI#METRE}</td></tr>
-     * </table></blockquote>
-     *
-     * @see DefaultGeodeticDatum#WGS84
-     * @see org.apache.sis.referencing.crs.DefaultGeographicCRS#WGS84
-     */
-    public static final DefaultEllipsoid WGS84 = createFlattenedSphere(
-            properties("WGS84", 7030, "WGS 1984"), 6378137.0, 298.257223563, SI.METRE);
-
-    /**
-     * WGS 1972 ellipsoid (EPSG:7043).
-     * The semi-major and semi-minor axis length are approximatively 6378135 and 6356751
-     * {@linkplain SI#METRE metres} respectively.
-     *
-     * @see DefaultGeodeticDatum#WGS72
-     */
-    public static final DefaultEllipsoid WGS72 = createFlattenedSphere(
-            properties("WGS72", 7043, "WGS 1972"), 6378135.0, 298.26, SI.METRE);
-
-    /**
-     * GRS 1980 ellipsoid (EPSG:7019), also called "<cite>International 1979</cite>".
-     * The semi-major and semi-minor axis length are approximatively 6378137 and 6356752
-     * {@linkplain SI#METRE metres} respectively. This ellipsoid is very close, but not
-     * identical, to {@linkplain #WGS84}.
-     *
-     * {@note The <cite>NAD83</cite> ellipsoid uses the same semi-axis length
and units.
-     *        The <cite>Web Map Server</cite> <code>"CRS:83"</code>
authority code uses that NAD83 ellipsoid.
-     *        The <code>"IGNF:MILLER"</code> authority code uses the GRS80 ellipsoid.}
-     */
-    public static final DefaultEllipsoid GRS80 = createFlattenedSphere(
-            properties("GRS80", 7019, new String[] {"GRS 1980", "International 1979"}),
-            6378137.0, 298.257222101, SI.METRE);
-
-    /**
-     * International 1924 ellipsoid (EPSG:7022).
-     * The semi-major and semi-minor axis length are approximatively 6378388 and 6356912
-     * {@linkplain SI#METRE metres} respectively.
-     *
-     * {@note The <cite>European Datum 1950</cite> ellipsoid uses the same semi-axis
length and units.}
-     */
-    public static final DefaultEllipsoid INTERNATIONAL_1924 = createFlattenedSphere(
-            properties("International 1924", 7022, null), 6378388.0, 297.0, SI.METRE);
-
-    /**
-     * Clarke 1866 ellipsoid (EPSG:7008).
-     * The semi-major and semi-minor axis length are approximatively 6378206 and 6356584
-     * {@linkplain SI#METRE metres} respectively.
-     *
-     * {@note The <cite>NAD27</cite> ellipsoid uses the same semi-axis length
and units.
-     *        The <cite>Web Map Server</cite> <code>"CRS:27"</code>
authority code uses that NAD27 ellipsoid.}
-     */
-    public static final DefaultEllipsoid CLARKE_1866 = createEllipsoid(
-            properties("Clarke 1866", 7008, null), 6378206.4, 6356583.8, SI.METRE);
-
-    /**
-     * A sphere with a radius of 6371000 {@linkplain SI#METRE metres}. Spheres use a simpler
-     * algorithm for {@linkplain #orthodromicDistance orthodromic distance computation},
which
-     * may be faster and more robust.
-     *
-     * {@note This ellipsoid is close to the <cite>GRS 1980 Authalic Sphere</cite>
(EPSG:7048),
-     *        which has a radius of 6371007 metres.}
-     *
-     * @see DefaultGeodeticDatum#SPHERE
-     */
-    public static final DefaultEllipsoid SPHERE =
-            createEllipsoid("Sphere", 6371000, 6371000, SI.METRE);
-
-    /**
      * The equatorial radius. This field should be considered as final.
      * It is modified only by JAXB at unmarshalling time.
      *
@@ -261,9 +171,9 @@ public class DefaultEllipsoid extends Ab
     }
 
     /**
-     * Constructs a new ellipsoid using the specified axis length. The properties map is
-     * given unchanged to the {@linkplain AbstractIdentifiedObject#AbstractIdentifiedObject(Map)
-     * super-class constructor}.
+     * Constructs a new ellipsoid using the specified axis length.
+     * The properties map is given unchanged to the
+     * {@linkplain AbstractIdentifiedObject#AbstractIdentifiedObject(Map) super-class constructor}.
      *
      * @param properties        Set of properties. Should contains at least {@code "name"}.
      * @param semiMajorAxis     The equatorial radius.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java?rev=1531309&r1=1531308&r2=1531309&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] Fri Oct 11 14:31:01 2013
@@ -24,7 +24,7 @@ package org.apache.sis.internal.system;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final class Modules {
@@ -41,6 +41,11 @@ public final class Modules {
     /**
      * The {@value} module name.
      */
+    public static final String REFERENCING = "org.apache.sis.referencing";
+
+    /**
+     * The {@value} module name.
+     */
     public static final String STORAGE = "org.apache.sis.storage";
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java?rev=1531309&r1=1531308&r2=1531309&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java [UTF-8]
Fri Oct 11 14:31:01 2013
@@ -22,7 +22,11 @@ import java.util.HashSet;
 import java.io.File;
 import java.net.URL;
 import java.net.URISyntaxException;
+import javax.management.JMException;
+import org.apache.sis.internal.system.Shutdown;
+import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.util.Classes;
+import org.junit.AfterClass;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
@@ -185,4 +189,21 @@ public abstract strictfp class TestSuite
             }
         }
     }
+
+    /**
+     * Simulates a module uninstall after all tests. This method will first notify any classpath-dependant
+     * services that the should clear their cache, then stop the SIS daemon threads. Those
operations are
+     * actually not needed in non-server environment (it is okay to just let the JVM stop
by itself), but
+     * the intend here is to ensure that no exception is thrown.
+     *
+     * <p>Since this method stops SIS daemon threads, the SIS library shall not be
used anymore after
+     * this method execution.</p>
+     *
+     * @throws JMException If an error occurred during unregistration of the supervisor MBean.
+     */
+    @AfterClass
+    public static void shutdown() throws JMException {
+        SystemListener.fireClasspathChanged();
+        Shutdown.stop(TestSuite.class);
+    }
 }



Mime
View raw message