From commits-return-7788-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Thu Jun 16 10:18:33 2016 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3F19E194BA for ; Thu, 16 Jun 2016 10:18:33 +0000 (UTC) Received: (qmail 39493 invoked by uid 500); 16 Jun 2016 10:18:33 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 39460 invoked by uid 500); 16 Jun 2016 10:18:33 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 39451 invoked by uid 99); 16 Jun 2016 10:18:33 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2016 10:18:33 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 86E7F1A108B for ; Thu, 16 Jun 2016 10:18:32 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.374 X-Spam-Level: X-Spam-Status: No, score=0.374 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id wlgROn9EE3o8 for ; Thu, 16 Jun 2016 10:18:20 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id E9A815FAC8 for ; Thu, 16 Jun 2016 10:18:19 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 2FFEEE01D8 for ; Thu, 16 Jun 2016 10:18:19 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 47A423A00EC for ; Thu, 16 Jun 2016 10:18:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1748682 [1/2] - in /sis/branches/JDK7: ./ 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 10:18:17 -0000 To: commits@sis.apache.org From: desruisseaux@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160616101818.47A423A00EC@svn01-us-west.apache.org> Author: desruisseaux Date: Thu Jun 16 10:18:17 2016 New Revision: 1748682 URL: http://svn.apache.org/viewvc?rev=1748682&view=rev Log: Merge from JDK8 branch. Contains a first draft of OpenOffice add-ins. Added: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java - copied unchanged from r1748678, sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java sis/branches/JDK7/application/sis-openoffice/ - copied from r1748678, sis/branches/JDK8/application/sis-openoffice/ sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/unopkg/ - copied from r1748678, sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/unopkg/ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java - copied unchanged from r1748678, sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/CodeType.java sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/CodeTypeTest.java - copied unchanged from r1748678, sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/CodeTypeTest.java Modified: sis/branches/JDK7/ (props changed) sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java sis/branches/JDK7/application/sis-openoffice/pom.xml sis/branches/JDK7/application/sis-openoffice/src/main/unopkg/sis.png (props changed) sis/branches/JDK7/core/sis-build-helper/pom.xml sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/PackOutput.java sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java sis/branches/JDK7/pom.xml sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java Propchange: sis/branches/JDK7/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Jun 16 10:18:17 2016 @@ -1,4 +1,4 @@ /sis/branches/Android:1430670-1480699 /sis/branches/JDK6:1394913-1508480 -/sis/branches/JDK8:1584960-1746656 +/sis/branches/JDK8:1584960-1748678 /sis/trunk:1394364-1508466,1519089-1519674 Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java [UTF-8] (original) +++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -37,7 +37,7 @@ import org.apache.sis.io.wkt.Convention; */ final class CRSCommand extends MetadataCommand { /** - * Creates the {@code "metadata"}, {@code "crs"} or {@code "identifier"} sub-command. + * Creates the {@code "crs"} sub-command. */ CRSCommand(final int commandIndex, final String... args) throws InvalidOptionException { super(commandIndex, args); Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java [UTF-8] (original) +++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -91,7 +91,7 @@ final class IdentifierCommand extends Me } /** - * Creates the {@code "metadata"}, {@code "crs"} or {@code "identifier"} sub-command. + * Creates the {@code "identifier"} sub-command. */ IdentifierCommand(final int commandIndex, final String... args) throws InvalidOptionException { super(commandIndex, args); Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java [UTF-8] (original) +++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -16,11 +16,8 @@ */ package org.apache.sis.console; -import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; -import java.util.HashSet; -import java.util.Set; import java.io.Console; import java.io.IOException; import javax.xml.bind.Marshaller; @@ -39,6 +36,7 @@ import org.apache.sis.referencing.CRS; import org.apache.sis.storage.DataStore; import org.apache.sis.storage.DataStores; import org.apache.sis.storage.DataStoreException; +import org.apache.sis.internal.storage.CodeType; import org.apache.sis.util.collection.TableColumn; import org.apache.sis.util.collection.TreeTable; import org.apache.sis.util.collection.TreeTableFormat; @@ -58,18 +56,6 @@ import org.apache.sis.xml.XML; */ class MetadataCommand extends CommandRunner { /** - * The protocol part of the filename to be recognized as a CRS authority. - * In such case, this class will delegate to {@link CRS#forCode(String)} - * instead of opening the file. - */ - static final Set AUTHORITIES = new HashSet<>(Arrays.asList("URN", "EPSG", "CRS", "AUTO", "AUTO2")); - - /** - * Length of the longest authority name declared in {@link #AUTHORITIES}. - */ - static final int MAX_AUTHORITY_LENGTH = 5; - - /** * The output format. */ static enum Format { @@ -142,39 +128,7 @@ class MetadataCommand extends CommandRun } /** - * Returns {@code true} if the given argument begins with one of the known authorities - * ("URN", "EPSG", "CRS", "AUTO", etc.). - */ - static boolean isAuthorityCode(final String code) { - final char[] authority = new char[MAX_AUTHORITY_LENGTH]; - final int length = code.length(); - int p = 0, i = 0; - while (i < length) { - final int c = code.codePointAt(i); - if (c == ':') { - if (!AUTHORITIES.contains(new String(authority, 0, p))) { - break; - } - return true; - } - if (!Character.isWhitespace(c)) { - if (p >= MAX_AUTHORITY_LENGTH || !Character.isLetterOrDigit(c)) { - break; - } - /* - * Casting to char is okay because AUTHORITIES contains only ASCII values. - * If 'c' was a supplemental Unicode value, then the result of the cast - * would not match any AUTHORITIES value anyway. - */ - authority[p++] = (char) Character.toUpperCase(c); - } - i += Character.charCount(c); - } - return false; - } - - /** - * If the given argument begins with one of the known authorities ("URN", "EPSG", "CRS", "AUTO", etc.), + * If the given argument seems to be an authority code ("URN", "EPSG", "CRS", "AUTO", etc.), * delegates to {@link CRS#forCode(String)}. Otherwise reads the metadata using a datastore. * * @return A {@link Metadata} or {@link CoordinateReferenceSystem} instance, or {@code null} if none. @@ -189,7 +143,7 @@ class MetadataCommand extends CommandRun return null; } else { final String file = files.get(0); - if (isAuthorityCode(file)) { + if (CodeType.guess(file).isCRS) { return CRS.forCode(file); } else { try (DataStore store = DataStores.open(file)) { Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java [UTF-8] (original) +++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -53,6 +53,7 @@ import org.apache.sis.geometry.Immutable import org.apache.sis.internal.referencing.Formulas; import org.apache.sis.internal.referencing.DirectPositionView; import org.apache.sis.internal.referencing.ReferencingUtilities; +import org.apache.sis.internal.storage.CodeType; import org.apache.sis.internal.util.PatchedUnitFormat; import org.apache.sis.referencing.IdentifiedObjects; import org.apache.sis.referencing.CRS; @@ -164,7 +165,7 @@ final class TransformCommand extends Met final String name = option.label(); throw new InvalidOptionException(Errors.format(Errors.Keys.MissingValueForOption_1, name), name); } - if (isAuthorityCode(identifier)) try { + if (CodeType.guess(identifier).isCRS) try { return CRS.forCode(identifier); } catch (NoSuchAuthorityCodeException e) { final String name = option.label(); Modified: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java [UTF-8] (original) +++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -37,22 +37,9 @@ import static org.junit.Assert.*; @DependsOn(CommandRunnerTest.class) public final strictfp class MetadataCommandTest extends TestCase { /** - * Verifies the {@link MetadataCommand#MAX_AUTHORITY_LENGTH} value. - */ - @Test - public void verifyMaxAuthorityLength() { - int length = 0; - for (final String authority : MetadataCommand.AUTHORITIES) { - final int c = authority.length(); - if (c > length) length = c; - } - assertEquals("MAX_AUTHORITY_LENGTH", length, MetadataCommand.MAX_AUTHORITY_LENGTH); - } - - /** * Tests the sub-command on a NetCDF file. * - * @throws Exception Should never happen. + * @throws Exception if an error occurred while creating the command. */ @Test public void testNetCDF() throws Exception { @@ -78,7 +65,7 @@ public final strictfp class MetadataComm /** * Tests with the same file than {@link #testNetCDF()}, but producing a XML output. * - * @throws Exception Should never happen. + * @throws Exception if an error occurred while creating the command. */ @Test @DependsOnMethod("testNetCDF") Modified: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java [UTF-8] (original) +++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -26,7 +26,7 @@ import org.junit.BeforeClass; * * @author Martin Desruisseaux (Geomatys) * @since 0.3 - * @version 0.4 + * @version 0.8 * @module */ @Suite.SuiteClasses({ @@ -34,7 +34,8 @@ import org.junit.BeforeClass; org.apache.sis.console.HelpCommandTest.class, org.apache.sis.console.AboutCommandTest.class, org.apache.sis.console.MimeTypeCommandTest.class, - org.apache.sis.console.MetadataCommandTest.class + org.apache.sis.console.MetadataCommandTest.class, + org.apache.sis.console.CRSCommandTest.class }) public final strictfp class ConsoleTestSuite extends TestSuite { /** Modified: sis/branches/JDK7/application/sis-openoffice/pom.xml URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-openoffice/pom.xml?rev=1748682&r1=1748678&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/application/sis-openoffice/pom.xml (original) +++ sis/branches/JDK7/application/sis-openoffice/pom.xml Thu Jun 16 10:18:17 2016 @@ -28,7 +28,7 @@ org.apache.sis application - 0.8-jdk8-SNAPSHOT + 0.8-jdk7-SNAPSHOT Propchange: sis/branches/JDK7/application/sis-openoffice/src/main/unopkg/sis.png ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Jun 16 10:18:17 2016 @@ -1,3 +1,7 @@ +/sis/branches/Android/application/sis-openoffice/src/main/unopkg/sis.png:1430670-1480699 /sis/branches/Android/src/site/resources/images/banner.png:1430670-1480699 +/sis/branches/JDK6/application/sis-openoffice/src/main/unopkg/sis.png:1394913-1508480 /sis/branches/JDK6/src/site/resources/images/banner.png:1394913-1498321 +/sis/branches/JDK8/application/sis-openoffice/src/main/unopkg/sis.png:1584960-1746656,1747178-1748678 +/sis/trunk/application/sis-openoffice/src/main/unopkg/sis.png:1394364-1508466,1519089-1519674 /sis/trunk/src/site/resources/images/banner.png:1394364-1498284 Modified: sis/branches/JDK7/core/sis-build-helper/pom.xml URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-build-helper/pom.xml?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-build-helper/pom.xml (original) +++ sis/branches/JDK7/core/sis-build-helper/pom.xml Thu Jun 16 10:18:17 2016 @@ -45,9 +45,9 @@ Define Maven Mojos and Javadoc taglets for generating resource files - or formatting the Javadoc. While any project could use it, this module - is primarily for internal use by Apache SIS and may change in any - future version. + formatting the Javadoc or creating ".oxt" files for OpenOffice.org. + While any project could use it, this module is primarily for internal + use by Apache SIS and may change in any future version. @@ -108,12 +108,12 @@ Define Maven Mojos and Javadoc taglets f org.apache.maven maven-core - 3.3.3 + 3.3.9 org.apache.maven maven-plugin-api - 3.3.3 + 3.3.9 org.apache.maven.plugin-tools Modified: sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -91,7 +91,7 @@ public class Assembler extends AbstractM * have been zipped. Now generate the Pack200 file and zip it directly (without creating * a temporary "sis.pack.gz" file). */ - final Packer packer = new Packer(project.getName(), project.getUrl(), version, targetDirectory); + final Packer packer = new Packer(project.getName(), version, targetDirectory); final ZipArchiveEntry entry = new ZipArchiveEntry( artifactBase + '/' + LIB_DIRECTORY + '/' + FATJAR_FILE + PACK_EXTENSION); entry.setMethod(ZipArchiveEntry.STORED); Modified: sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -74,7 +74,7 @@ public class BundleCreator extends Abstr } final String version = project.getVersion(); try { - final Packer packer = new Packer(project.getName(), project.getUrl(), version, targetDirectory); + final Packer packer = new Packer(project.getName(), version, targetDirectory); packer.preparePack200(FINALNAME_PREFIX + version + ".jar").pack(); } catch (IOException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); Modified: sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/PackOutput.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/PackOutput.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/PackOutput.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/PackOutput.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -118,11 +118,10 @@ final class PackOutput implements Closea * Opens the given JAR file for writing and creates its manifest. * * @param projectName The project name, or {@code null} if none. - * @param projectURL The project URL, or {@code null} if none. * @param version The project version, or {@code null} if none. * @throws IOException if the file can't be open. */ - void open(final String projectName, final String projectURL, final String version) throws IOException { + void open(final String projectName, final String version) throws IOException { final Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); @@ -132,9 +131,6 @@ final class PackOutput implements Closea attributes.put(Attributes.Name.IMPLEMENTATION_TITLE, projectName); attributes.put(Attributes.Name.IMPLEMENTATION_VENDOR, projectName); } - if (projectURL != null) { - attributes.put(Attributes.Name.IMPLEMENTATION_URL, projectURL); - } if (version != null) { attributes.put(Attributes.Name.SPECIFICATION_VERSION, version); attributes.put(Attributes.Name.IMPLEMENTATION_VERSION, version); @@ -181,8 +177,7 @@ final class PackOutput implements Closea copy(src, attributes, Attributes.Name.SPECIFICATION_VERSION) | copy(src, attributes, Attributes.Name.IMPLEMENTATION_TITLE) | copy(src, attributes, Attributes.Name.IMPLEMENTATION_VENDOR) | - copy(src, attributes, Attributes.Name.IMPLEMENTATION_VERSION) | - copy(src, attributes, Attributes.Name.IMPLEMENTATION_URL)) + copy(src, attributes, Attributes.Name.IMPLEMENTATION_VERSION)) { manifest.getEntries().put(packageName, attributes); } @@ -324,11 +319,13 @@ final class PackOutput implements Closea final File inputFile = outputJAR; final Pack200.Packer packer = Pack200.newPacker(); final Map p = packer.properties(); - p.put(EFFORT, String.valueOf(9)); // Maximum compression level. - p.put(KEEP_FILE_ORDER, FALSE); // Reorder files for better compression. - p.put(MODIFICATION_TIME, LATEST); // Smear modification times to a single value. - p.put(DEFLATE_HINT, TRUE); // Ignore all JAR deflation requests. - p.put(UNKNOWN_ATTRIBUTE, ERROR); // Throw an error if an attribute is unrecognized + p.put(EFFORT, String.valueOf(9)); // Maximum compression level. + p.put(SEGMENT_LIMIT, "-1"); // use largest-possible archive segments (>10% better compression). + p.put(KEEP_FILE_ORDER, FALSE); // Reorder files for better compression. + p.put(MODIFICATION_TIME, LATEST); // Smear modification times to a single value. + p.put(DEFLATE_HINT, TRUE); // Ignore all JAR deflation requests. + p.put(UNKNOWN_ATTRIBUTE, ERROR); // Throw an error if an attribute is unrecognized + p.put(CODE_ATTRIBUTE_PFX+"LocalVariableTable", STRIP); // discard debug attributes. try (JarFile jarFile = new JarFile(inputFile)) { try (OutputStream deflater = new GZIPOutputStream(out)) { packer.pack(jarFile, deflater); Modified: sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -40,9 +40,9 @@ import static org.apache.sis.internal.ma */ final class Packer implements FilenameFilter { /** - * The project name, URL and version to declare in the manifest file, or {@code null} if none. + * The project name and version to declare in the manifest file, or {@code null} if none. */ - private final String projectName, projectURL, version; + private final String projectName, version; /** * The Maven target directory. Shall contain the {@code "binaries"} sub-directory, @@ -59,16 +59,12 @@ final class Packer implements FilenameFi * Creates a packer. * * @param projectName The project name to declare in the manifest file, or {@code null} if none. - * @param projectURL The project URL to declare in the manifest file, or {@code null} if none. * @param version The project version to declare in the manifest file, or {@code null} if none. * @param targetDirectory The Maven target directory. * @throws FileNotFoundException if the {@code target/binaries} directory is not found. */ - Packer(final String projectName, final String projectURL, final String version, - final File targetDirectory) throws FileNotFoundException - { + Packer(final String projectName, final String version, final File targetDirectory) throws FileNotFoundException { this.projectName = projectName; - this.projectURL = projectURL; this.version = version; this.targetDirectory = targetDirectory; this.binariesDirectory = new File(targetDirectory, BINARIES_DIRECTORY); @@ -130,7 +126,7 @@ final class Packer implements FilenameFi final File outDirectory = distributionDirectory(targetDirectory); final PackOutput output = new PackOutput(getInputJARs(), new File(outDirectory, outputJAR)); try { - output.open(projectName, projectURL, version); + output.open(projectName, version); output.writeContent(); } finally { output.close(); Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -19,7 +19,6 @@ package org.apache.sis.internal.metadata import java.util.Locale; import java.net.URL; import java.net.URLClassLoader; -import java.util.ServiceLoader; import java.util.logging.Level; import java.util.logging.LogRecord; import java.security.AccessController; @@ -37,6 +36,7 @@ import javax.naming.event.EventContext; import javax.naming.event.NamingEvent; import javax.naming.event.NamingExceptionEvent; import javax.naming.event.ObjectChangeListener; +import org.apache.sis.internal.system.DefaultFactories; import org.apache.sis.internal.system.DataDirectory; import org.apache.sis.internal.system.Shutdown; import org.apache.sis.internal.system.Loggers; @@ -61,7 +61,7 @@ import java.nio.file.Paths; * * @author Martin Desruisseaux (Geomatys) * @since 0.7 - * @version 0.7 + * @version 0.8 * @module */ public abstract class Initializer { @@ -181,7 +181,7 @@ public abstract class Initializer { */ Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM), Listener.class, "objectChanged", e); } - for (Initializer init : ServiceLoader.load(Initializer.class)) { + for (Initializer init : DefaultFactories.createServiceLoader(Initializer.class)) { init.dataSourceChanged(); } } @@ -298,7 +298,7 @@ public abstract class Initializer { final Method m = source.getClass().getMethod("setCreateDatabase", String.class); m.invoke(source, "create"); try (Connection c = source.getConnection()) { - for (Initializer init : ServiceLoader.load(Initializer.class)) { + for (Initializer init : DefaultFactories.createServiceLoader(Initializer.class)) { init.createSchema(c); } } finally { 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=1748682&r1=1748681&r2=1748682&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] Thu Jun 16 10:18:17 2016 @@ -33,7 +33,7 @@ import org.apache.sis.metadata.Modifiabl import org.apache.sis.internal.jaxb.IdentifierMapAdapter; import org.apache.sis.internal.jaxb.ModifiableIdentifierMap; import org.apache.sis.internal.metadata.MetadataUtilities; -import org.apache.sis.internal.util.Utilities; +import org.apache.sis.internal.system.Modules; import org.apache.sis.util.collection.Containers; import static org.apache.sis.util.collection.Containers.isNullOrEmpty; @@ -96,7 +96,7 @@ public class ISOMetadata extends Modifia * without invoking super.getIdentifiers(), in which case their identifiers will not be copied. * For safety, we will do this optimization only if the implementation is an Apache SIS one. */ - if (Utilities.isSIS(object.getClass())) { + if (object.getClass().getName().startsWith(Modules.CLASSNAME_PREFIX)) { return; } } Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -22,6 +22,12 @@ import java.util.LinkedHashSet; import java.util.Locale; import org.opengis.referencing.IdentifiedObject; import org.opengis.referencing.NoSuchAuthorityCodeException; +import org.opengis.referencing.datum.DatumAuthorityFactory; +import org.opengis.referencing.datum.PrimeMeridian; +import org.opengis.referencing.datum.Ellipsoid; +import org.opengis.referencing.datum.Datum; +import org.opengis.referencing.datum.GeodeticDatum; +import org.opengis.referencing.datum.VerticalDatum; import org.opengis.referencing.crs.GeocentricCRS; import org.opengis.referencing.crs.GeographicCRS; import org.opengis.referencing.crs.ProjectedCRS; @@ -49,11 +55,11 @@ import org.apache.sis.util.Debug; * * @author Martin Desruisseaux (Geomatys) * @since 0.7 - * @version 0.7 + * @version 0.8 * @module */ @Fallback -final class EPSGFactoryFallback extends GeodeticAuthorityFactory implements CRSAuthorityFactory { +final class EPSGFactoryFallback extends GeodeticAuthorityFactory implements CRSAuthorityFactory, DatumAuthorityFactory { /** * Whether to disallow {@code CommonCRS} to use {@link org.apache.sis.referencing.factory.sql.EPSGFactory} * (in which case {@code CommonCRS} will fallback on hard-coded values). @@ -65,7 +71,12 @@ final class EPSGFactoryFallback extends /** * The singleton instance. */ - static final CRSAuthorityFactory INSTANCE = new EPSGFactoryFallback(); + static final EPSGFactoryFallback INSTANCE = new EPSGFactoryFallback(); + + /** + * Kinds of object created by this factory. Used as bitmask. + */ + private static final int CRS = 1, DATUM = 2, ELLIPSOID = 4, PRIME_MERIDIAN = 8; /** * The authority, created when first needed. @@ -107,18 +118,22 @@ final class EPSGFactoryFallback extends */ @Override public Set getAuthorityCodes(Class type) { + final boolean pm = type.isAssignableFrom(PrimeMeridian.class); + final boolean ellipsoid = type.isAssignableFrom(Ellipsoid .class); + final boolean datum = type.isAssignableFrom(GeodeticDatum.class); final boolean geographic = type.isAssignableFrom(GeographicCRS.class); final boolean geocentric = type.isAssignableFrom(GeocentricCRS.class); final boolean projected = type.isAssignableFrom(ProjectedCRS .class); final Set codes = new LinkedHashSet<>(); + if (pm) codes.add(StandardDefinitions.GREENWICH); for (final CommonCRS crs : CommonCRS.values()) { + if (ellipsoid) add(codes, crs.ellipsoid); + if (datum) add(codes, crs.datum); + if (geocentric) add(codes, crs.geocentric); if (geographic) { add(codes, crs.geographic); add(codes, crs.geo3D); } - if (geocentric) { - add(codes, crs.geocentric); - } if (projected && (crs.northUTM != 0 || crs.southUTM != 0)) { for (int zone = crs.firstZone; zone <= crs.lastZone; zone++) { if (crs.northUTM != 0) codes.add(Integer.toString(crs.northUTM + zone)); @@ -126,10 +141,13 @@ final class EPSGFactoryFallback extends } } } - if (type.isAssignableFrom(VerticalCRS.class)) { + final boolean vertical = type.isAssignableFrom(VerticalCRS .class); + final boolean vdatum = type.isAssignableFrom(VerticalDatum.class); + if (vertical || vdatum) { for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values()) { if (candidate.isEPSG) { - codes.add(Integer.toString(candidate.crs)); + if (vertical) codes.add(Integer.toString(candidate.crs)); + if (vdatum) codes.add(Integer.toString(candidate.datum)); } } } @@ -147,11 +165,55 @@ final class EPSGFactoryFallback extends } /** + * Returns a prime meridian for the given EPSG code. + */ + @Override + public PrimeMeridian createPrimeMeridian(final String code) throws NoSuchAuthorityCodeException { + return (PrimeMeridian) predefined(code, PRIME_MERIDIAN); + } + + /** + * Returns an ellipsoid for the given EPSG code. + */ + @Override + public Ellipsoid createEllipsoid(final String code) throws NoSuchAuthorityCodeException { + return (Ellipsoid) predefined(code, ELLIPSOID); + } + + /** + * Returns a datum for the given EPSG code. + */ + @Override + public Datum createDatum(final String code) throws NoSuchAuthorityCodeException { + return (Datum) predefined(code, DATUM); + } + + /** * Returns a coordinate reference system for the given EPSG code. This method is invoked * as a fallback when {@link CRS#forCode(String)} can not create a CRS for a given code. */ @Override + public CoordinateReferenceSystem createCoordinateReferenceSystem(final String code) throws NoSuchAuthorityCodeException { + return (CoordinateReferenceSystem) predefined(code, CRS); + } + + /** + * Returns a coordinate reference system, datum or ellipsoid for the given EPSG code. + */ + @Override public IdentifiedObject createObject(final String code) throws NoSuchAuthorityCodeException { + return predefined(code, -1); + } + + /** + * Implementation of the {@code createFoo(String)} methods. + * + * @param code the EPSG code. + * @param kind any combination of {@link #CRS}, {@link #DATUM}, {@link #ELLIPSOID} or {@link #PRIME_MERIDIAN} bits. + * @return the requested object. + * @throws NoSuchAuthorityCodeException if no matching object has been found. + */ + private IdentifiedObject predefined(final String code, final int kind) throws NoSuchAuthorityCodeException { NumberFormatException cause = null; try { /* @@ -164,32 +226,55 @@ final class EPSGFactoryFallback extends final int n = Integer.parseInt(CharSequences.trimWhitespaces(code, code.lastIndexOf(DefaultNameSpace.DEFAULT_SEPARATOR) + 1, code.length()).toString()); + if ((kind & PRIME_MERIDIAN) != 0 && n == 8901) { + return CommonCRS.WGS84.primeMeridian(); + } for (final CommonCRS crs : CommonCRS.values()) { - if (n == crs.geographic) return crs.geographic(); - if (n == crs.geocentric) return crs.geocentric(); - if (n == crs.geo3D) return crs.geographic3D(); - final double latitude; - int zone; - if (crs.northUTM != 0 && (zone = n - crs.northUTM) >= crs.firstZone && zone <= crs.lastZone) { - latitude = +1; - } else if (crs.southUTM != 0 && (zone = n - crs.southUTM) >= crs.firstZone && zone <= crs.lastZone) { - latitude = -1; - } else { - continue; + /* + * In a complete EPSG dataset we could have an ambiguity below because the same code can be used + * for datum, ellipsoid and CRS objects. However in the particular case of this EPSG-subset, we + * ensured that there is no such collision - see CommonCRSTest.ensureNoCodeCollision(). + */ + if ((kind & ELLIPSOID) != 0 && n == crs.ellipsoid) return crs.ellipsoid(); + if ((kind & DATUM) != 0 && n == crs.datum) return crs.datum(); + if ((kind & CRS) != 0) { + if (n == crs.geographic) return crs.geographic(); + if (n == crs.geocentric) return crs.geocentric(); + if (n == crs.geo3D) return crs.geographic3D(); + final double latitude; + int zone; + if (crs.northUTM != 0 && (zone = n - crs.northUTM) >= crs.firstZone && zone <= crs.lastZone) { + latitude = +1; + } else if (crs.southUTM != 0 && (zone = n - crs.southUTM) >= crs.firstZone && zone <= crs.lastZone) { + latitude = -1; + } else { + continue; + } + return crs.UTM(latitude, TransverseMercator.centralMeridian(zone)); } - return crs.UTM(latitude, TransverseMercator.centralMeridian(zone)); } - for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values()) { - if (candidate.isEPSG && candidate.crs == n) { - return candidate.crs(); + if ((kind & (DATUM | CRS)) != 0) { + for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values()) { + if (candidate.isEPSG) { + if ((kind & DATUM) != 0 && candidate.datum == n) return candidate.datum(); + if ((kind & CRS) != 0 && candidate.crs == n) return candidate.crs(); + } } } } catch (NumberFormatException e) { cause = e; } - final String authority = Constants.EPSG + " subset"; + final Class type; + switch (kind) { + case CRS: type = CoordinateReferenceSystem.class; break; + case DATUM: type = Datum.class; break; + case ELLIPSOID: type = Ellipsoid.class; break; + case PRIME_MERIDIAN: type = PrimeMeridian.class; break; + default: type = IdentifiedObject.class; break; + } + final String authority = Constants.EPSG + "-subset"; final NoSuchAuthorityCodeException e = new NoSuchAuthorityCodeException(Errors.format( - Errors.Keys.NoSuchAuthorityCode_3, authority, CoordinateReferenceSystem.class, code), authority, code); + Errors.Keys.NoSuchAuthorityCode_3, authority, type, code), authority, code); e.initCause(cause); throw e; } Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -182,6 +182,9 @@ abstract class AuthorityFactoryProxy @Override InternationalString createFromAPI(AuthorityFactory factory, String code) throws FactoryException { return factory.getDescriptionText(code); } + @Override AuthorityFactoryProxy specialize(String typeName) { + return this; + } }; /** Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -751,7 +751,8 @@ public class MultiAuthoritiesFactory ext if (code == null) { message = Errors.format(Errors.Keys.MissingComponentInElement_2, s, "code"); } else { - message = Errors.format(Errors.Keys.CanNotCreateObjectAsInstanceOf_2, type, uri.type); + message = Errors.format(Errors.Keys.CanNotCreateObjectAsInstanceOf_2, type, + DefinitionURI.PREFIX + DefinitionURI.SEPARATOR + uri.type); } throw new NoSuchAuthorityCodeException(message, authority, code, s); } Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -17,7 +17,6 @@ package org.apache.sis.referencing.factory.sql; import java.util.Locale; -import java.util.ServiceLoader; import java.io.IOException; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -32,6 +31,7 @@ import java.io.BufferedReader; import org.apache.sis.util.StringBuilders; import org.apache.sis.internal.metadata.sql.ScriptRunner; import org.apache.sis.internal.metadata.sql.SQLUtilities; +import org.apache.sis.internal.system.DefaultFactories; import org.apache.sis.internal.util.Fallback; import org.apache.sis.util.CharSequences; import org.apache.sis.util.Exceptions; @@ -52,7 +52,7 @@ import org.apache.sis.internal.jdk8.BiFu * * @author Martin Desruisseaux (Geomatys) * @since 0.7 - * @version 0.7 + * @version 0.8 * @module */ final class EPSGInstaller extends ScriptRunner { @@ -275,7 +275,7 @@ final class EPSGInstaller extends Script */ private static InstallationResources lookupProvider(final Locale locale) throws IOException { InstallationResources fallback = null; - for (final InstallationResources provider : ServiceLoader.load(InstallationResources.class)) { + for (final InstallationResources provider : DefaultFactories.createServiceLoader(InstallationResources.class)) { if (provider.getAuthorities().contains(EPSG)) { if (provider.getClass().isAnnotationPresent(Fallback.class)) { return provider; Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -47,8 +47,8 @@ import org.apache.sis.referencing.operat import org.apache.sis.internal.referencing.provider.MapProjection; import org.apache.sis.internal.metadata.ReferencingServices; import org.apache.sis.internal.referencing.Formulas; +import org.apache.sis.internal.system.Modules; import org.apache.sis.internal.util.Constants; -import org.apache.sis.internal.util.Utilities; import org.apache.sis.internal.util.Numerics; import org.apache.sis.util.resources.Errors; @@ -594,7 +594,7 @@ public abstract class NormalizedProjecti group = DESCRIPTORS.get(type); if (group == null) { final ParameterBuilder builder = new ParameterBuilder().setRequired(true); - if (Utilities.isSIS(type)) { + if (type.getName().startsWith(Modules.CLASSNAME_PREFIX)) { builder.setCodeSpace(Citations.SIS, Constants.SIS); } final String[] names = getInternalParameterNames(); Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -46,7 +46,7 @@ import static org.apache.sis.test.Assert * * @author Martin Desruisseaux (Geomatys) * @since 0.7 - * @version 0.7 + * @version 0.8 * @module */ public final strictfp class AuthorityFactoriesTest extends TestCase { @@ -66,6 +66,20 @@ public final strictfp class AuthorityFac } /** + * Tests {@link CRSAuthorityFactory#getDescriptionText(String)}. + * + * @throws FactoryException if the EPSG:4326 name can not be obtained. + * + * @since 0.8 + */ + @Test + public void testGetDescriptionText() throws FactoryException { + final CRSAuthorityFactory factory = AuthorityFactories.ALL; + assertEquals("WGS 84", factory.getDescriptionText("EPSG:4326").toString()); + assertEquals("WGS 84", factory.getDescriptionText("urn:ogc:def:crs:epsg::4326").toString()); + } + + /** * Tests creation of {@code CRS:84} from various codes. * * @throws FactoryException if a CRS:84 creation failed. Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -20,6 +20,7 @@ import org.opengis.referencing.crs.Coord import org.opengis.referencing.crs.GeodeticCRS; import org.opengis.referencing.crs.SingleCRS; import org.opengis.util.FactoryException; +import org.opengis.util.NoSuchIdentifierException; import org.apache.sis.referencing.crs.DefaultCompoundCRS; import org.apache.sis.referencing.crs.DefaultGeographicCRS; import org.apache.sis.referencing.crs.HardCodedCRS; @@ -40,7 +41,7 @@ import static org.apache.sis.test.Assert * * @author Martin Desruisseaux (Geomatys) * @since 0.4 - * @version 0.7 + * @version 0.8 * @module */ @DependsOn({ @@ -106,6 +107,21 @@ public final strictfp class CRSTest exte } /** + * Test {@link CRS#forCode(String)} with values that should be invalid. + * + * @throws FactoryException if an error other than {@link NoSuchIdentifierException} happened. + */ + @Test + public void testForInvalidCode() throws FactoryException { + try { + CRS.forCode("EPSG:4"); + fail("Should not find EPSG:4"); + } catch (NoSuchIdentifierException e) { + assertEquals("4", e.getIdentifierCode()); + } + } + + /** * Tests simple WKT parsing. It is not the purpose of this class to test extensively the WKT parser; * those tests are rather done by {@link org.apache.sis.io.wkt.GeodeticObjectParserTest}. * Here we merely test that {@link CRS#fromWKT(String)} is connected to the parser. Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java [UTF-8] Thu Jun 16 10:18:17 2016 @@ -17,6 +17,8 @@ package org.apache.sis.referencing; import java.util.Date; +import java.util.Map; +import java.util.HashMap; import org.opengis.parameter.ParameterValueGroup; import org.opengis.referencing.crs.TemporalCRS; import org.opengis.referencing.crs.VerticalCRS; @@ -49,7 +51,7 @@ import static org.apache.sis.test.TestUt * * @author Martin Desruisseaux (IRD, Geomatys) * @since 0.4 - * @version 0.7 + * @version 0.8 * @module */ @DependsOn({ @@ -64,6 +66,58 @@ public final strictfp class CommonCRSTes private static final double DAY_LENGTH = 24 * 60 * 60 * 1000; /** + * Verifies that the same EPSG code is not used for two objects. Collisions are not allowed between + * {@code geographic}, {@code geocentric}, {@code geo3D} and all UTM projections. Strictly speaking + * all the above-cited codes may collide with {@code datum} and {@code ellipsoid}, but we nevertheless + * avoid those collisions in order to simplify {@link EPSGFactoryFallback#createObject(String)} implementation. + */ + @Test + public void ensureNoCodeCollision() { + final Map> codes = new HashMap<>(); + final CommonCRS[] values = CommonCRS.values(); + for (final CommonCRS crs : values) { + assertNoCodeCollision(codes, crs, crs.geographic); + assertNoCodeCollision(codes, crs, crs.geocentric); + assertNoCodeCollision(codes, crs, crs.geo3D); + for (int zone = crs.firstZone; zone <= crs.lastZone; zone++) { + if (crs.northUTM != 0) assertNoCodeCollision(codes, crs, crs.northUTM + zone); + if (crs.southUTM != 0) assertNoCodeCollision(codes, crs, crs.southUTM + zone); + } + } + final CommonCRS.Vertical[] vertical = CommonCRS.Vertical.values(); + for (final CommonCRS.Vertical crs : vertical) { + if (crs.isEPSG) { + assertNoCodeCollision(codes, crs, crs.crs); + } + } + /* + * Following restrictions are not strictly required, but their enforcement + * simplifies the EPSGFactoryFallback.createObject(String) implementation. + */ + assertNull(codes.put(Integer.valueOf(StandardDefinitions.GREENWICH), CommonCRS.WGS84)); + for (final CommonCRS crs : values) assertNull (crs.name(), codes.get(Integer.valueOf(crs.ellipsoid))); + for (final CommonCRS crs : values) assertNotSame(crs.name(), crs, codes.put(Integer.valueOf(crs.ellipsoid), crs)); + for (final CommonCRS crs : values) assertNull (crs.name(), codes.get(Integer.valueOf(crs.datum))); + for (final CommonCRS.Vertical crs : vertical) { + if (crs.isEPSG) { + assertNull(crs.name(), codes.get(Integer.valueOf(crs.datum))); + } + } + } + + /** + * Helper method for {@link #ensureNoCodeCollision()} only. + */ + private static void assertNoCodeCollision(final Map> codes, final Enum crs, final int n) { + if (n != 0) { + final Enum existing = codes.put(n, crs); + if (existing != null) { + fail(existing + " and " + crs + " both use the same EPSG:" + n + " code."); + } + } + } + + /** * Tests the {@link CommonCRS#geographic()} method. */ @Test Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java [UTF-8] Thu Jun 16 10:18:17 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java [UTF-8] Thu Jun 16 10:18:17 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java [UTF-8] Thu Jun 16 10:18:17 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> types = new ArrayList<>(); - 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java [UTF-8] Thu Jun 16 10:18:17 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 JSR-330 @@ -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 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 ServiceLoader createServiceLoader(final Class 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. + * + *

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.

+ * + * @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 parents = new HashSet<>(); + 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 (SecurityException | ClassNotFoundException e) { + if (!warnings) { + warnings = true; + Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM), + DefaultFactories.class, "getContextClassLoader", e); + } + } + } + return loader; + } } 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=1748682&r1=1748681&r2=1748682&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] Thu Jun 16 10:18:17 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java [UTF-8] Thu Jun 16 10:18:17 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java [UTF-8] Thu Jun 16 10:18:17 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 java.util.Objects; @@ -44,9 +45,9 @@ import java.util.Objects; * * @param 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 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java [UTF-8] Thu Jun 16 10:18:17 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java [UTF-8] Thu Jun 16 10:18:17 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 map = new TreeMap<>(); 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; @@ -298,8 +298,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/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] Thu Jun 16 10:18:17 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); } Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java [UTF-8] Thu Jun 16 10:18:17 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 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/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java?rev=1748682&r1=1748681&r2=1748682&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java [UTF-8] Thu Jun 16 10:18:17 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; @@ -96,7 +97,7 @@ final class LogRecordCollector extends H method = ""; 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;