sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1748699 [2/2] - in /sis/branches/JDK6: ./ application/sis-console/src/main/java/org/apache/sis/console/ application/sis-console/src/test/java/org/apache/sis/console/ application/sis-console/src/test/java/org/apache/sis/test/suite/ applicat...
Date Thu, 16 Jun 2016 12:19:27 GMT
Modified: sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -26,6 +26,9 @@ import org.opengis.referencing.crs.Geogr
 import org.opengis.referencing.crs.GeocentricCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.datum.PrimeMeridian;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Utilities;
 
@@ -44,7 +47,7 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 @DependsOn({
@@ -59,6 +62,12 @@ public final strictfp class EPSGFactoryF
      */
     @Test
     public void testGetAuthorityCodes() throws FactoryException {
+        assertSetEquals(Arrays.asList(StandardDefinitions.GREENWICH),
+                EPSGFactoryFallback.INSTANCE.getAuthorityCodes(PrimeMeridian.class));
+        assertSetEquals(Arrays.asList("7030", "7043", "7019", "7008", "7022", "7048"),
+                EPSGFactoryFallback.INSTANCE.getAuthorityCodes(Ellipsoid.class));
+        assertSetEquals(Arrays.asList("6326", "6322", "6269", "6267", "6258", "6230", "6047",
"5100", "5103"),
+                EPSGFactoryFallback.INSTANCE.getAuthorityCodes(Datum.class));
         assertSetEquals(Arrays.asList("4978", "4984", "4936"),
                 EPSGFactoryFallback.INSTANCE.getAuthorityCodes(GeocentricCRS.class));
         assertSetEquals(Arrays.asList("4326", "4322", "4047", "4269", "4267", "4258", "4230",
"4979", "4985", "4937"),
@@ -68,6 +77,46 @@ public final strictfp class EPSGFactoryF
     }
 
     /**
+     * Tests {@link EPSGFactoryFallback#createPrimeMeridian(String)}.
+     *
+     * @throws FactoryException if a prime meridian can not be constructed.
+     */
+    @Test
+    public void testCreatePrimeMeridian() throws FactoryException {
+        verifyCreatePrimeMeridian(CommonCRS.WGS84.primeMeridian(), StandardDefinitions.GREENWICH);
+    }
+
+    /**
+     * Tests {@link EPSGFactoryFallback#createEllipsoid(String)}.
+     *
+     * @throws FactoryException if an ellipsoid can not be constructed.
+     */
+    @Test
+    public void testCreateEllipsoid() throws FactoryException {
+        verifyCreateEllipsoid(CommonCRS.WGS84 .ellipsoid(), "7030");
+        verifyCreateEllipsoid(CommonCRS.WGS72 .ellipsoid(), "7043");
+        verifyCreateEllipsoid(CommonCRS.NAD83 .ellipsoid(), "7019");
+        verifyCreateEllipsoid(CommonCRS.NAD27 .ellipsoid(), "7008");
+        verifyCreateEllipsoid(CommonCRS.ED50  .ellipsoid(), "7022");
+        verifyCreateEllipsoid(CommonCRS.SPHERE.ellipsoid(), "7048");
+    }
+
+    /**
+     * Tests {@link EPSGFactoryFallback#createEllipsoid(String)}.
+     *
+     * @throws FactoryException if an ellipsoid can not be constructed.
+     */
+    @Test
+    public void testCreateDatum() throws FactoryException {
+        verifyCreateDatum(CommonCRS.WGS84 .datum(), "6326");
+        verifyCreateDatum(CommonCRS.WGS72 .datum(), "6322");
+        verifyCreateDatum(CommonCRS.NAD83 .datum(), "6269");
+        verifyCreateDatum(CommonCRS.NAD27 .datum(), "6267");
+        verifyCreateDatum(CommonCRS.ED50  .datum(), "6230");
+        verifyCreateDatum(CommonCRS.SPHERE.datum(), "6047");
+    }
+
+    /**
      * Tests {@link EPSGFactoryFallback#createCoordinateReferenceSystem(String)}.
      *
      * @throws FactoryException if a CRS can not be constructed.
@@ -77,30 +126,55 @@ public final strictfp class EPSGFactoryF
      */
     @Test
     public void testCreateCRS() throws FactoryException {
-        verifyCreate(CommonCRS.WGS84 .geographic(),            "4326");
-        verifyCreate(CommonCRS.WGS72 .geographic(),            "4322");
-        verifyCreate(CommonCRS.SPHERE.geographic(),            "4047");
-        verifyCreate(CommonCRS.NAD83 .geographic(),            "4269");
-        verifyCreate(CommonCRS.NAD27 .geographic(),            "4267");
-        verifyCreate(CommonCRS.ETRS89.geographic(),            "4258");
-        verifyCreate(CommonCRS.ED50  .geographic(),            "4230");
-        verifyCreate(CommonCRS.WGS84 .geocentric(),            "4978");
-        verifyCreate(CommonCRS.WGS72 .geocentric(),            "4984");
-        verifyCreate(CommonCRS.ETRS89.geocentric(),            "4936");
-        verifyCreate(CommonCRS.WGS84 .geographic(),       "EPSG:4326");
-        verifyCreate(CommonCRS.WGS72 .geographic(),      "EPSG::4322");
-        verifyCreate(CommonCRS.WGS84 .geographic3D(),          "4979");
-        verifyCreate(CommonCRS.WGS72 .geographic3D(),          "4985");
-        verifyCreate(CommonCRS.ETRS89.geographic3D(),          "4937");
-        verifyCreate(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(),  "5714");
-        verifyCreate(CommonCRS.Vertical.DEPTH.crs(),           "5715");
+        verifyCreateCRS(CommonCRS.WGS84 .geographic(),            "4326");
+        verifyCreateCRS(CommonCRS.WGS72 .geographic(),            "4322");
+        verifyCreateCRS(CommonCRS.SPHERE.geographic(),            "4047");
+        verifyCreateCRS(CommonCRS.NAD83 .geographic(),            "4269");
+        verifyCreateCRS(CommonCRS.NAD27 .geographic(),            "4267");
+        verifyCreateCRS(CommonCRS.ETRS89.geographic(),            "4258");
+        verifyCreateCRS(CommonCRS.ED50  .geographic(),            "4230");
+        verifyCreateCRS(CommonCRS.WGS84 .geocentric(),            "4978");
+        verifyCreateCRS(CommonCRS.WGS72 .geocentric(),            "4984");
+        verifyCreateCRS(CommonCRS.ETRS89.geocentric(),            "4936");
+        verifyCreateCRS(CommonCRS.WGS84 .geographic(),       "EPSG:4326");
+        verifyCreateCRS(CommonCRS.WGS72 .geographic(),      "EPSG::4322");
+        verifyCreateCRS(CommonCRS.WGS84 .geographic3D(),          "4979");
+        verifyCreateCRS(CommonCRS.WGS72 .geographic3D(),          "4985");
+        verifyCreateCRS(CommonCRS.ETRS89.geographic3D(),          "4937");
+        verifyCreateCRS(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(),  "5714");
+        verifyCreateCRS(CommonCRS.Vertical.DEPTH.crs(),           "5715");
+    }
+
+    /**
+     * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the
given prime meridian.
+     */
+    private static void verifyCreatePrimeMeridian(final PrimeMeridian expected, final String
code) throws FactoryException {
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createPrimeMeridian(code));
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
+    }
+
+    /**
+     * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the
given ellipsoid.
+     */
+    private static void verifyCreateEllipsoid(final Ellipsoid expected, final String code)
throws FactoryException {
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createEllipsoid(code));
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
+    }
+
+    /**
+     * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the
given datum.
+     */
+    private static void verifyCreateDatum(final Datum expected, final String code) throws
FactoryException {
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createDatum(code));
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
     }
 
     /**
-     * Asserts that the result of {@link CommonCRS#forCode(String, String, FactoryException)}
is the given CRS.
+     * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the
given CRS.
      */
-    private static void verifyCreate(final SingleCRS expected, final String code) throws
FactoryException {
+    private static void verifyCreateCRS(final SingleCRS expected, final String code) throws
FactoryException {
         assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createCoordinateReferenceSystem(code));
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -286,14 +286,6 @@ public final strictfp class CoordinateSy
             }
 
             @Override
-            public Unit<?> getUnitReplacement(Unit<?> unit) {
-                if (Units.isAngular(unit)) {
-                    unit = NonSI.GRADE;
-                }
-                return unit;
-            }
-
-            @Override
             public Unit<?> getUnitReplacement(CoordinateSystemAxis axis, Unit<?>
unit) {
                 if (Units.isAngular(unit)) {
                     unit = NonSI.GRADE;
@@ -305,11 +297,6 @@ public final strictfp class CoordinateSy
             public AxisDirection getDirectionReplacement(CoordinateSystemAxis axis, final
AxisDirection direction) {
                 return direction;
             }
-
-            @Override
-            public AxisDirection getDirectionReplacement(final AxisDirection direction) {
-                return direction;
-            }
         });
         assertEqualsIgnoreMetadata(targetCS, actualCS);
     }
@@ -330,16 +317,6 @@ public final strictfp class CoordinateSy
             }
 
             @Override
-            public Unit<?> getUnitReplacement(final Unit<?> unit) {
-                return unit;
-            }
-
-            @Override
-            public AxisDirection getDirectionReplacement(final AxisDirection direction) {
-                return direction;
-            }
-
-            @Override
             public Unit<?> getUnitReplacement(CoordinateSystemAxis axis, final Unit<?>
unit) {
                 return unit;
             }

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -17,11 +17,11 @@
 package org.apache.sis.internal.converter;
 
 import java.util.Date;
-import java.util.ServiceLoader;
 import org.opengis.util.CodeList;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.ObjectConverter;
 import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.internal.system.Modules;
 
@@ -50,7 +50,7 @@ import org.apache.sis.internal.system.Mo
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  */
 public final class SystemRegistry extends ConverterRegistry {
@@ -105,7 +105,7 @@ public final class SystemRegistry extend
      */
     @Override
     protected void initialize() {
-        for (ObjectConverter<?,?> converter : ServiceLoader.load(ObjectConverter.class,
getClass().getClassLoader())) {
+        for (ObjectConverter<?,?> converter : DefaultFactories.createServiceLoader(ObjectConverter.class))
{
             if (converter instanceof SystemConverter<?,?>) {
                 converter = ((SystemConverter<?,?>) converter).unique();
             }

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -18,13 +18,13 @@ package org.apache.sis.internal.jaxb;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.ServiceLoader;
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.SystemListener;
+import org.apache.sis.internal.system.DefaultFactories;
 
 
 /**
@@ -40,7 +40,7 @@ import org.apache.sis.internal.system.Sy
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  *
  * @see org.apache.sis.xml.MarshallerPool
@@ -92,7 +92,7 @@ public abstract class TypeRegistration {
          * 2) The ClassLoader between different invocations may be different in an OSGi context.
          */
         final ArrayList<Class<?>> types = new ArrayList<Class<?>>();
-        for (final TypeRegistration t : ServiceLoader.load(TypeRegistration.class)) {
+        for (final TypeRegistration t : DefaultFactories.createServiceLoader(TypeRegistration.class))
{
             t.getTypes(types);
         }
         return types.toArray(new Class<?>[types.size()]);

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -16,11 +16,13 @@
  */
 package org.apache.sis.internal.system;
 
+import java.util.Set;
 import java.util.Map;
+import java.util.HashSet;
 import java.util.IdentityHashMap;
 import java.util.ServiceLoader;
 import java.util.ServiceConfigurationError;
-import org.apache.sis.internal.util.Utilities;
+import org.apache.sis.util.logging.Logging;
 
 
 /**
@@ -31,7 +33,7 @@ import org.apache.sis.internal.util.Util
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Guilhem Legal (Geomatys)
  * @since   0.3
- * @version 0.7
+ * @version 0.8
  * @module
  *
  * @see <a href="https://jcp.org/en/jsr/detail?id=330">JSR-330</a>
@@ -87,8 +89,8 @@ public final class DefaultFactories exte
         T factory = type.cast(FACTORIES.get(type));
         if (factory == null && !FACTORIES.containsKey(type)) {
             T fallback = null;
-            for (final T candidate : ServiceLoader.load(type)) {
-                if (Utilities.isSIS(candidate.getClass())) {
+            for (final T candidate : createServiceLoader(type)) {
+                if (candidate.getClass().getName().startsWith(Modules.CLASSNAME_PREFIX))
{
                     if (factory != null) {
                         throw new ServiceConfigurationError("Found two implementations of
" + type);
                     }
@@ -157,4 +159,77 @@ public final class DefaultFactories exte
         }
         return impl.cast(factory);
     }
+
+    /**
+     * Returns a service loader for the given type using the default class loader.
+     * The default is the current thread {@linkplain Thread#getContextClassLoader() context
class loader},
+     * provided that it can access at least the Apache SIS stores.
+     *
+     * @param  <T> The compile-time value of {@code service} argument.
+     * @param  service The interface or abstract class representing the service.
+     * @return A new service loader for the given service type.
+     *
+     * @since 0.8
+     */
+    public static <T> ServiceLoader<T> createServiceLoader(final Class<T>
service) {
+        try {
+            return ServiceLoader.load(service, getContextClassLoader());
+        } catch (SecurityException e) {
+            /*
+             * We were not allowed to invoke Thread.currentThread().getContextClassLoader().
+             * But ServiceLoader.load(Class) may be allowed to, since it is part of JDK.
+             */
+            Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM),
+                    DefaultFactories.class, "createServiceLoader", e);
+            return ServiceLoader.load(service);
+        }
+    }
+
+    /**
+     * Returns the context class loader, but makes sure that it has Apache SIS on its classpath.
+     * First, this method invokes {@link Thread#getContextClassLoader()} for the current
thread.
+     * Then this method scans over all Apache SIS classes on the stack trace. For each SIS
class,
+     * its loader is compared to the above-cited context class loader. If the context class
loader
+     * is equal or is a child of the SIS loader, then it is left unchanged. Otherwise the
context
+     * class loader is replaced by the SIS one.
+     *
+     * <p>The intend of this method is to ensure that {@link ServiceLoader#load(Class)}
will find the
+     * Apache SIS services even in an environment that defined an unsuitable context class
loader.</p>
+     *
+     * @return The context class loader if suitable, or another class loader otherwise.
+     * @throws SecurityException if this method is not allowed to get the current thread
+     *         context class loader or one of its parent.
+     *
+     * @since 0.8
+     */
+    private static ClassLoader getContextClassLoader() throws SecurityException {
+        final Thread thread = Thread.currentThread();
+        ClassLoader loader = thread.getContextClassLoader();
+        final Set<ClassLoader> parents = new HashSet<ClassLoader>();
+        for (ClassLoader c = loader; c != null; c = c.getParent()) {
+            parents.add(c);
+        }
+        boolean warnings = false;
+        for (final StackTraceElement trace : thread.getStackTrace()) {
+            final String element = trace.getClassName();
+            if (element.startsWith(Modules.CLASSNAME_PREFIX)) try {
+                ClassLoader c = Class.forName(element).getClassLoader();
+                if (!parents.contains(c)) {
+                    loader = c;
+                    parents.clear();
+                    while (c != null) {
+                        parents.add(c);
+                        c = c.getParent();
+                    }
+                }
+            } catch (Exception e) {     // This is (SecurityException | ClassNotFoundException)
on the JDK7 branch.
+                if (!warnings) {
+                    warnings = true;
+                    Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM),
+                            DefaultFactories.class, "getContextClassLoader", e);
+                }
+            }
+        }
+        return loader;
+    }
 }

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -77,6 +77,16 @@ public final class Modules {
     public static final int MINOR_VERSION = 8;
 
     /**
+     * The prefix of all classnames in Apache SIS, including a trailing dot.
+     */
+    public static final String CLASSNAME_PREFIX = "org.apache.sis.";
+
+    /**
+     * The prefix of all internal classnames in Apache SIS, including a trailing dot.
+     */
+    public static final String INTERNAL_CLASSNAME_PREFIX = CLASSNAME_PREFIX + "internal.";
+
+    /**
      * Do not allow instantiation of this class.
      */
     private Modules() {

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -125,7 +125,7 @@ public final class DefinitionURI {
     /**
      * The domain of URLs in the OGC namespace.
      */
-    private static final String DOMAIN = "www.opengis.net";
+    public static final String DOMAIN = "www.opengis.net";
 
     /**
      * Server and path portions of HTTP URL for various types (currently {@code "crs"}).

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -22,6 +22,7 @@ import java.util.Iterator;
 import java.util.ServiceLoader;
 import java.util.NoSuchElementException;
 import org.apache.sis.util.Workaround;
+import org.apache.sis.internal.system.DefaultFactories;
 
 // Branch-specific imports
 import org.apache.sis.internal.jdk7.Objects;
@@ -44,9 +45,9 @@ import org.apache.sis.internal.jdk7.Obje
  *
  * @param <E> The type of elements in the set.
  *
- * @author  Martin Desruisseaux (IRD)
+ * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.6
- * @version 0.7
+ * @version 0.8
  * @module
  */
 @Workaround(library="JDK", version="1.8.0_31-b13")
@@ -155,7 +156,7 @@ public class LazySet<E> extends SetOfUnk
      */
     private boolean canPullMore() {
         if (sourceIterator == null && cachedElements == null) {
-            sourceIterator = ServiceLoader.load(service).iterator();
+            sourceIterator = DefaultFactories.createServiceLoader(service).iterator();
             if (createCache()) {
                 return true;
             }

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -28,7 +28,7 @@ import org.apache.sis.util.CharSequences
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.6
+ * @version 0.8
  * @module
  */
 public final class Utilities extends Static {
@@ -39,16 +39,6 @@ public final class Utilities extends Sta
     }
 
     /**
-     * Returns {@code true} if the given class is an Apache SIS class.
-     *
-     * @param  type The class to verify.
-     * @return {@code true} if the given class is an Apache SIS class.
-     */
-    public static boolean isSIS(final Class<?> type) {
-        return type.getName().startsWith("org.apache.sis.");
-    }
-
-    /**
      * Appends to the given buffer only the characters that are valid for a Unicode identifier.
      * The given separator character is append before the given {@code text} only if the
buffer
      * is not empty and at least one {@code text} character is valid.

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java [UTF-8]
(original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java [UTF-8]
Thu Jun 16 12:19:26 2016
@@ -103,10 +103,10 @@ public final class Locales extends Stati
      */
     private static final short[] ISO3, ISO2;
     static {
-        final Short CONFLICT = 0; // Sentinal value for conflicts (paranoiac safety).
+        final Short CONFLICT = 0;                           // Sentinal value for conflicts
(paranoiac safety).
         final Map<Short,Short> map = new TreeMap<Short,Short>();
         for (final Locale locale : POOL.values()) {
-            short type = LANGUAGE; // 0 for language, or leftmost bit set for country.
+            short type = LANGUAGE;                          // 0 for language, or leftmost
bit set for country.
             do { // Executed exactly twice: once for language, than once for country.
                 final short alpha2 = toNumber((type == LANGUAGE) ? locale.getLanguage() :
locale.getCountry(), type);
                 if (alpha2 != 0) {
@@ -114,7 +114,7 @@ public final class Locales extends Stati
                     try {
                         alpha3 = toNumber((type == LANGUAGE) ? locale.getISO3Language() :
locale.getISO3Country(), type);
                     } catch (MissingResourceException e) {
-                        continue; // No 3-letters code to map for this locale.
+                        continue;                           // No 3-letters code to map for
this locale.
                     }
                     if (alpha3 != 0 && alpha3 != alpha2) {
                         final Short p = map.put(alpha3, alpha2);
@@ -127,7 +127,7 @@ public final class Locales extends Stati
                 }
             } while ((type ^= COUNTRY) != LANGUAGE);
         }
-        while (map.values().remove(CONFLICT)); // Remove all conflicts that we may have found.
+        while (map.values().remove(CONFLICT));              // Remove all conflicts that
we may have found.
         ISO3 = new short[map.size()];
         ISO2 = new short[map.size()];
         int i = 0;
@@ -318,8 +318,8 @@ filter: for (final Locale locale : local
     }
 
     /**
-     * Converts a 3-letters ISO code to a 2-letters one. If the given code is not recognized,
-     * then this method returns {@code code} unmodified.
+     * Converts a 3-letters ISO code to a 2-letters one.
+     * If the given code is not recognized, then this method returns {@code code} unmodified.
      *
      * @param  code The 3-letters code.
      * @param  type Either {@link #LANGUAGE} or {@link #COUNTRY}.

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -25,6 +25,7 @@ import org.apache.sis.util.Configuration
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.Classes;
+import org.apache.sis.internal.system.Modules;
 
 
 /**
@@ -85,6 +86,12 @@ public final class Logging extends Stati
      */
     private static volatile LoggerFactory<?> factory;
     static {
+        /*
+         * Use ServiceLoader.load(…), not DefaultFactories.createServiceLoader(…), for
avoiding a never-ending
+         * loop if a warning occurs in DefaultFactories. This risk exists because DefaultFactories
may use the
+         * logging services. Anyway, Apache SIS does not define any custom logger factory,
so DefaultFactories
+         * is not needed in this case.
+         */
         LoggerFactory<?> factory = null;
         for (final LoggerFactory<?> found : ServiceLoader.load(LoggerFactory.class))
{
             if (factory == null) {
@@ -170,8 +177,9 @@ public final class Logging extends Stati
         String name = classe.getName();
         final int separator = name.lastIndexOf('.');
         name = (separator >= 1) ? name.substring(0, separator) : "";
-        if (name.startsWith("org.apache.sis.internal.")) {
-            name = "org.apache.sis" + name.substring(23);       // Remove the "internal"
part from SIS package name.
+        if (name.startsWith(Modules.INTERNAL_CLASSNAME_PREFIX)) {
+            // Remove the "internal" part from Apache SIS package names.
+            name = Modules.CLASSNAME_PREFIX + name.substring(Modules.INTERNAL_CLASSNAME_PREFIX.length());
         }
         return getLogger(name);
     }
@@ -211,24 +219,6 @@ public final class Logging extends Stati
     }
 
     /**
-     * Invoked when an unexpected error occurred. This method logs a message at {@link Level#WARNING}
to the
-     * specified logger. The originating class name and method name are inferred from the
error stack trace,
-     * using the first {@linkplain StackTraceElement stack trace element} for which the class
name is inside
-     * a package or sub-package of the logger name.
-     *
-     * @param  logger Where to log the error, or {@code null} for inferring a default value
from other arguments.
-     * @param  error  The error that occurred, or {@code null} if none.
-     * @return {@code true} if the error has been logged, or {@code false} if the given {@code
error}
-     *         was null or if the logger does not log anything at {@link Level#WARNING}.
-     *
-     * @deprecated Use {@link #unexpectedException(Logger, Class, String, Throwable)} instead.
-     */
-    @Deprecated
-    public static boolean unexpectedException(final Logger logger, final Throwable error)
{
-        return unexpectedException(logger, null, null, error, Level.WARNING);
-    }
-
-    /**
      * Invoked when an unexpected error occurred. This method logs a message at {@link Level#WARNING}
      * to the specified logger. The originating class name and method name can optionally
be specified.
      * If any of them is {@code null}, then it will be inferred from the error stack trace
as described below.

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -29,6 +29,7 @@ import org.apache.sis.util.logging.Loggi
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.system.DelayedExecutor;
 import org.apache.sis.internal.system.DelayedRunnable;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.jaxb.AdapterReplacement;
 import org.apache.sis.internal.jaxb.TypeRegistration;
 import org.apache.sis.util.ArgumentChecks;
@@ -57,7 +58,7 @@ import org.apache.sis.util.ArgumentCheck
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  *
  * @see XML
@@ -184,7 +185,7 @@ public class MarshallerPool {
     public MarshallerPool(final JAXBContext context, final Map<String,?> properties)
throws JAXBException {
         ArgumentChecks.ensureNonNull("context", context);
         this.context = context;
-        replacements = ServiceLoader.load(AdapterReplacement.class);
+        replacements = DefaultFactories.createServiceLoader(AdapterReplacement.class);
         /*
          * Detects if we are using the endorsed JAXB implementation (i.e. the one provided
in
          * separated JAR files) or the one bundled in JDK 6. We use the JAXB context package

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -23,6 +23,7 @@ import java.util.logging.Handler;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.io.IOException;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.io.TableAppender;
 import org.junit.runner.Description;
 
@@ -99,7 +100,7 @@ final class LogRecordCollector extends H
                 method = "<unknown>";
                 for (final StackTraceElement t : Thread.currentThread().getStackTrace())
{
                     final String c = t.getClassName();
-                    if (c.startsWith("org.apache.sis.") && c.endsWith(TestSuite.CLASSNAME_SUFFIX))
{
+                    if (c.startsWith(Modules.CLASSNAME_PREFIX) && c.endsWith(TestSuite.CLASSNAME_SUFFIX))
{
                         cname  = c;
                         method = t.getMethodName();
                         break;

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
(original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
Thu Jun 16 12:19:26 2016
@@ -25,6 +25,7 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
+import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.logging.MonolineFormatter;
 import org.junit.runner.RunWith;
@@ -131,7 +132,7 @@ public abstract strictfp class TestCase
      * The parent logger of all Apache SIS loggers.
      * Needs to be retained by strong reference.
      */
-    static final Logger LOGGER = Logger.getLogger("org.apache.sis");
+    static final Logger LOGGER = Logger.getLogger(Loggers.ROOT);
 
     /**
      * Initializes {@link MonolineFormatter} if it has been specified in the {@code logging.properties}

Modified: sis/branches/JDK6/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/pom.xml?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/pom.xml (original)
+++ sis/branches/JDK6/pom.xml Thu Jun 16 12:19:26 2016
@@ -371,7 +371,7 @@ Apache SIS is a free software, Java lang
       <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-compress</artifactId>
-        <version>1.10</version>
+        <version>1.11</version>
       </dependency>
 
       <!-- Optional dependencies -->
@@ -390,8 +390,8 @@ Apache SIS is a free software, Java lang
       <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-jdk14</artifactId>
-        <version>1.7.5</version> <!-- Must matches the version used by NetCDF.
-->
-        <scope>runtime</scope> <!-- Should never be needed at compile time.
-->
+        <version>1.7.5</version>                <!-- Must matches the version
used by NetCDF. -->
+        <scope>runtime</scope>                  <!-- Should never be needed
at compile time.  -->
       </dependency>
     </dependencies>
   </dependencyManagement>
@@ -416,7 +416,7 @@ Apache SIS is a free software, Java lang
          The last properties in this list depend on the Apache SIS branch.
        =================================================================== -->
   <properties>
-    <netcdf.version>4.4.2</netcdf.version> <!-- Last version compatible with
JDK6. -->
+    <netcdf.version>4.4.2</netcdf.version>          <!-- Last version compatible
with JDK6. -->
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <website.encoding>UTF-8</website.encoding>
     <website.locale>en</website.locale>
@@ -530,17 +530,22 @@ Apache SIS is a free software, Java lang
            INDEX.LIST file is incomplete (which seem to happen in practice). -->
       <plugin>
         <artifactId>maven-jar-plugin</artifactId>
+        <version>2.6</version>
+        <!-- Regression in maven-jar-plugin version 3.0: the class-path entry in MANIFEST.MF
+             has the "repository" layout in sis-openoffice artifact even if we explicitely
+             ask for the "simple" layout. https://issues.apache.org/jira/browse/MJAR-223
-->
+
         <configuration>
           <archive>
             <addMavenDescriptor>false</addMavenDescriptor>
             <index>false</index>
             <manifest>
               <addClasspath>true</addClasspath>
+              <classpathLayoutType>simple</classpathLayoutType>
               <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
             </manifest>
             <manifestEntries>
               <Built-On>${maven.build.timestamp}</Built-On>
-              <Implementation-URL>${project.url}</Implementation-URL>
               <Specification-Title>GeoAPI</Specification-Title>
               <Specification-Version>${geoapi.version}</Specification-Version>
               <Specification-Vendor>Open Geospatial Consortium</Specification-Vendor>

Copied: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java
(from r1748682, sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java?p2=sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java&p1=sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java&r1=1748682&r2=1748699&rev=1748699&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -93,7 +93,7 @@ public enum CodeType {
      */
     private static final Map<String,CodeType> FOR_PROTOCOL;
     static {
-        FOR_PROTOCOL = new HashMap<>();
+        FOR_PROTOCOL = new HashMap<String,CodeType>();
         FOR_PROTOCOL.put("urn",   CodeType.URN);
         FOR_PROTOCOL.put("http",  CodeType.HTTP_OGC);   // Will actually need verification.
         FOR_PROTOCOL.put("https", CodeType.HTTP_OGC);   // Will actually need verification.

Modified: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -20,6 +20,7 @@ import java.util.List;
 import java.util.LinkedList;
 import java.util.Iterator;
 import java.util.ServiceLoader;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 
@@ -39,7 +40,7 @@ import org.apache.sis.util.resources.Err
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.8
  * @module
  */
 final class DataStoreRegistry {
@@ -51,19 +52,20 @@ final class DataStoreRegistry {
     private final ServiceLoader<DataStoreProvider> loader;
 
     /**
-     * Creates a new registry which will use the current thread
-     * {@linkplain Thread#getContextClassLoader() context class loader}.
+     * Creates a new registry which will look for data stores accessible to the default class
loader.
+     * The default is the current thread {@linkplain Thread#getContextClassLoader() context
class loader},
+     * provided that it can access at least the Apache SIS stores.
      */
-    DataStoreRegistry() {
-        loader = ServiceLoader.load(DataStoreProvider.class);
+    public DataStoreRegistry() {
+        loader = DefaultFactories.createServiceLoader(DataStoreProvider.class);
     }
 
     /**
-     * Creates a new registry which will use the given class loader.
+     * Creates a new registry which will look for data stores accessible to the given class
loader.
      *
      * @param loader The class loader to use for loading {@link DataStoreProvider} implementations.
      */
-    DataStoreRegistry(final ClassLoader loader) {
+    public DataStoreRegistry(final ClassLoader loader) {
         ArgumentChecks.ensureNonNull("loader", loader);
         this.loader = ServiceLoader.load(DataStoreProvider.class, loader);
     }

Modified: sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1748699&r1=1748698&r2=1748699&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] Thu Jun 16 12:19:26 2016
@@ -26,10 +26,11 @@ import org.junit.BeforeClass;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.7
+ * @version 0.8
  * @module
  */
 @Suite.SuiteClasses({
+    org.apache.sis.internal.storage.CodeTypeTest.class,
     org.apache.sis.internal.storage.IOUtilitiesTest.class,
     org.apache.sis.internal.storage.ChannelDataInputTest.class,
     org.apache.sis.internal.storage.ChannelDataOutputTest.class,




Mime
View raw message