You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2016/02/22 16:01:37 UTC
svn commit: r1731655 - in /sis/branches/JDK7: ./
core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/
core/sis-referencing/src/main/java/org/apache/sis/parameter/
core/sis-referencing/src/main/java/org/apache/sis/referencing...
Author: desruisseaux
Date: Mon Feb 22 15:01:37 2016
New Revision: 1731655
URL: http://svn.apache.org/viewvc?rev=1731655&view=rev
Log:
Merge from the JDK8 branch: use of PostgreSQL enumerated values and other safety improvements.
Added:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameter.java
- copied unchanged from r1731653, sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameter.java
sis/branches/JDK7/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Finish.sql
- copied unchanged from r1731653, sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Finish.sql
sis/branches/JDK7/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql
- copied unchanged from r1731653, sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql
Removed:
sis/branches/JDK7/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG.sql
Modified:
sis/branches/JDK7/ (props changed)
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.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/crs/DefaultDerivedCRS.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.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/factory/sql/InstallationScriptProvider.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 22 15:01:37 2016
@@ -1,4 +1,4 @@
/sis/branches/Android:1430670-1480699
/sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1730896
+/sis/branches/JDK8:1584960-1731653
/sis/trunk:1394364-1508466,1519089-1519674
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -224,6 +224,8 @@ public final class Equirectangular exten
/**
* Gets a parameter value identified by the given descriptor and stores it only if different than zero.
+ * This method performs the same work than {@code Initializer.getAndStore(ParameterDescriptor)} in the
+ * {@link org.apache.sis.referencing.operation.projection} package.
*
* @param source The parameters from which to read the value.
* @param target Where to store the parameter values.
@@ -235,7 +237,7 @@ public final class Equirectangular exten
final ParameterDescriptor<Double> descriptor) throws IllegalArgumentException
{
final double value = source.doubleValue(descriptor); // Apply a unit conversion if needed.
- MapProjection.validate(descriptor, value); // Unconditional validation for semi-axes.
+ MapProjection.validate(descriptor, value); // Unconditional validation for all parameters.
if (value != 0) { // All default values in this class are zero.
target.parameter(descriptor.getName().getCode()).setValue(value);
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.NoSuchElementException;
import javax.xml.bind.annotation.XmlTransient;
import javax.measure.unit.SI;
+import javax.measure.unit.Unit;
import org.opengis.util.FactoryException;
import org.opengis.util.InternationalString;
import org.opengis.metadata.Identifier;
@@ -142,7 +143,11 @@ public abstract class MapProjection exte
}
/**
- * Validates the given parameter value.
+ * Validates the given parameter value. This method duplicates the verification already
+ * done by {@link org.apache.sis.parameter.DefaultParameterValue#setValue(Object, Unit)}.
+ * But we check again because we have no guarantee that the parameters given by the user
+ * were instances of {@code DefaultParameterValue}, or that the descriptor associated to
+ * the user-specified {@code ParameterValue} has sufficient information.
*
* @param descriptor The descriptor that specify the parameter to validate.
* @param value The parameter value in the units given by the descriptor.
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -120,7 +120,7 @@ import java.nio.file.Path;
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4
- * @version 0.6
+ * @version 0.7
* @module
*
* @see DefaultParameterDescriptor
@@ -152,16 +152,20 @@ public class DefaultParameterValue<T> ex
/**
* The value, or {@code null} if undefined.
* Except for the constructors, the {@link #equals(Object)} and the {@link #hashCode()} methods,
- * this field shall be read only by {@link #getValue()} and written by {@link #setValue(Object, Unit)}.
+ * this field should be read only by {@link #getValue()} and written only by {@link #setValue(Object, Unit)}.
+ *
+ * @since 0.7
*/
- private T value;
+ protected T value;
/**
* The unit of measure for the value, or {@code null} if it does not apply.
* Except for the constructors, the {@link #equals(Object)} and the {@link #hashCode()} methods,
- * this field shall be read only by {@link #getUnit()} and written by {@link #setValue(Object, Unit)}.
+ * this field should be read only by {@link #getUnit()} and written only by {@link #setValue(Object, Unit)}.
+ *
+ * @since 0.7
*/
- private Unit<?> unit;
+ protected Unit<?> unit;
/**
* Creates a parameter value from the specified descriptor.
@@ -724,17 +728,19 @@ public class DefaultParameterValue<T> ex
* @param unit The unit associated to the new parameter value, or {@code null}.
* @throws InvalidParameterValueException if the type of {@code value} is inappropriate for this parameter,
* or if the value is illegal for some other reason (for example the value is numeric and out of range).
+ *
+ * @see #validate(Object)
*/
@SuppressWarnings("unchecked")
protected void setValue(final Object value, final Unit<?> unit) throws InvalidParameterValueException {
final T convertedValue = Verifier.ensureValidValue(descriptor, value, unit);
if (value != null) {
validate(convertedValue);
- this.value = (T) value; // Type has been verified by Verifier.ensureValidValue(…).
+ this.value = (T) value; // Type has been verified by Verifier.ensureValidValue(…).
} else {
this.value = descriptor.getDefaultValue();
}
- this.unit = unit; // Assign only on success.
+ this.unit = unit; // Assign only on success.
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -18,6 +18,8 @@ package org.apache.sis.parameter;
import java.util.Map;
import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
import java.lang.reflect.Array;
import javax.measure.unit.Unit;
import javax.measure.converter.UnitConverter;
@@ -27,9 +29,12 @@ import org.opengis.parameter.ParameterDe
import org.opengis.parameter.GeneralParameterDescriptor;
import org.opengis.parameter.InvalidParameterValueException;
import org.apache.sis.internal.referencing.EPSGParameterDomain;
+import org.apache.sis.internal.system.Semaphores;
+import org.apache.sis.internal.system.Loggers;
import org.apache.sis.measure.Range;
import org.apache.sis.measure.Units;
import org.apache.sis.util.Numbers;
+import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.resources.Vocabulary;
@@ -180,7 +185,7 @@ final class Verifier {
}
/*
* At this point the user's value has been fully converted to the unit of measurement specified
- * by the ParameterDescriptor. Now compares the converted value to the restricting given by the
+ * by the ParameterDescriptor. Now compare the converted value to the restriction given by the
* descriptor (set of valid values and range of value domain).
*/
if (convertedValue != null) {
@@ -193,10 +198,23 @@ final class Verifier {
error = ensureValidValue(valueClass, validValues,
descriptor.getMinimumValue(), descriptor.getMaximumValue(), convertedValue);
}
+ /*
+ * If we found an error, we will usually throw an exception. An exception to this rule is
+ * when EPSGDataAccess is creating a deprecated ProjectedCRS in which some parameters are
+ * known to be invalid (the CRS was deprecated precisely for that reason). In such cases,
+ * we will log a warning instead than throwing an exception.
+ */
if (error != null) {
error.convertRange(converter);
final String name = getDisplayName(descriptor);
- throw new InvalidParameterValueException(error.message(null, name, value), name, value);
+ final String message = error.message(null, name, value);
+ if (!Semaphores.query(Semaphores.SUSPEND_PARAMETER_CHECK)) {
+ throw new InvalidParameterValueException(message, name, value);
+ } else {
+ final LogRecord record = new LogRecord(Level.WARNING, message);
+ record.setLoggerName(Loggers.COORDINATE_OPERATION);
+ Logging.log(DefaultParameterValue.class, "setValue", record);
+ }
}
}
return valueClass.cast(convertedValue);
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=1731655&r1=1731654&r2=1731655&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] Mon Feb 22 15:01:37 2016
@@ -35,7 +35,9 @@ import org.apache.sis.referencing.factor
import org.apache.sis.internal.referencing.provider.TransverseMercator;
import org.apache.sis.internal.util.Constants;
import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.util.iso.DefaultNameSpace;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.CharSequences;
import org.apache.sis.util.Debug;
@@ -150,7 +152,16 @@ final class EPSGFactoryFallback extends
public IdentifiedObject createObject(final String code) throws NoSuchAuthorityCodeException {
NumberFormatException cause = null;
try {
- final int n = Integer.parseInt(code);
+ /*
+ * Parse the value after the last ':'. We do not bother to verify if the part before ':' is legal
+ * (e.g. "EPSG:4326", "EPSG::4326", "urn:ogc:def:crs:epsg::4326", etc.) because this analysis has
+ * already be done by MultiAuthoritiesFactory. We nevertheless skip the prefix in case this factory
+ * is used directly (not through MultiAuthoritiesFactory), which should be rare. The main case is
+ * when using the factory returned by AuthorityFactories.fallback(…).
+ */
+ final int n = Integer.parseInt(CharSequences.trimWhitespaces(code,
+ code.lastIndexOf(DefaultNameSpace.DEFAULT_SEPARATOR) + 1,
+ code.length()).toString());
for (final CommonCRS crs : CommonCRS.values()) {
if (n == crs.geographic) return crs.geographic();
if (n == crs.geocentric) return crs.geocentric();
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -37,7 +37,6 @@ import org.opengis.referencing.crs.Proje
import org.opengis.referencing.crs.EngineeringCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystem;
-import org.opengis.referencing.cs.EllipsoidalCS;
import org.opengis.referencing.cs.VerticalCS;
import org.opengis.referencing.cs.TimeCS;
import org.opengis.referencing.operation.Conversion;
@@ -288,9 +287,9 @@ public class DefaultDerivedCRS extends A
if (baseCRS != null && derivedCS != null) {
final String type = getType(baseCRS, derivedCS);
if (type != null) switch (type) {
- case WKTKeywords.GeodeticCRS: return new Geodetic(properties, (GeodeticCRS) baseCRS, conversion, (EllipsoidalCS) derivedCS);
- case WKTKeywords.VerticalCRS: return new Vertical(properties, (VerticalCRS) baseCRS, conversion, (VerticalCS) derivedCS);
- case WKTKeywords.TimeCRS: return new Temporal(properties, (TemporalCRS) baseCRS, conversion, (TimeCS) derivedCS);
+ case WKTKeywords.GeodeticCRS: return new Geodetic(properties, (GeodeticCRS) baseCRS, conversion, derivedCS);
+ case WKTKeywords.VerticalCRS: return new Vertical(properties, (VerticalCRS) baseCRS, conversion, (VerticalCS) derivedCS);
+ case WKTKeywords.TimeCRS: return new Temporal(properties, (TemporalCRS) baseCRS, conversion, (TimeCS) derivedCS);
case WKTKeywords.EngineeringCRS: {
/*
* This case may happen for baseCRS of kind GeodeticCRS, ProjectedCRS or EngineeringCRS.
@@ -341,9 +340,9 @@ public class DefaultDerivedCRS extends A
if (baseCRS != null && derivedCS != null) {
final String type = getType(baseCRS, derivedCS);
if (type != null) switch (type) {
- case WKTKeywords.GeodeticCRS: return new Geodetic(properties, (GeodeticCRS) baseCRS, interpolationCRS, method, baseToDerived, (EllipsoidalCS) derivedCS);
- case WKTKeywords.VerticalCRS: return new Vertical(properties, (VerticalCRS) baseCRS, interpolationCRS, method, baseToDerived, (VerticalCS) derivedCS);
- case WKTKeywords.TimeCRS: return new Temporal(properties, (TemporalCRS) baseCRS, interpolationCRS, method, baseToDerived, (TimeCS) derivedCS);
+ case WKTKeywords.GeodeticCRS: return new Geodetic(properties, (GeodeticCRS) baseCRS, interpolationCRS, method, baseToDerived, derivedCS);
+ case WKTKeywords.VerticalCRS: return new Vertical(properties, (VerticalCRS) baseCRS, interpolationCRS, method, baseToDerived, (VerticalCS) derivedCS);
+ case WKTKeywords.TimeCRS: return new Temporal(properties, (TemporalCRS) baseCRS, interpolationCRS, method, baseToDerived, (TimeCS) derivedCS);
case WKTKeywords.EngineeringCRS: {
if (baseCRS instanceof EngineeringCRS) {
// See the comment in create(Map, SingleCRS, Conversion, CoordinateSystem)
@@ -650,13 +649,13 @@ public class DefaultDerivedCRS extends A
}
/** Creates a new geodetic CRS from the given properties. */
- Geodetic(Map<String,?> properties, GeodeticCRS baseCRS, Conversion conversion, EllipsoidalCS derivedCS) {
+ Geodetic(Map<String,?> properties, GeodeticCRS baseCRS, Conversion conversion, CoordinateSystem derivedCS) {
super(properties, baseCRS, conversion, derivedCS);
}
/** Creates a new geodetic CRS from the given properties. */
Geodetic(Map<String,?> properties, GeodeticCRS baseCRS, CoordinateReferenceSystem interpolationCRS,
- OperationMethod method, MathTransform baseToDerived, EllipsoidalCS derivedCS)
+ OperationMethod method, MathTransform baseToDerived, CoordinateSystem derivedCS)
{
super(properties, baseCRS, interpolationCRS, method, baseToDerived, derivedCS);
}
@@ -666,19 +665,14 @@ public class DefaultDerivedCRS extends A
return (GeodeticDatum) super.getDatum();
}
- /** Returns the coordinate system given at construction time. */
- @Override public EllipsoidalCS getCoordinateSystem() {
- return (EllipsoidalCS) super.getCoordinateSystem();
- }
-
/** Returns a coordinate reference system of the same type than this CRS but with different axes. */
@Override AbstractCRS createSameType(final Map<String,?> properties, final CoordinateSystem derivedCS) {
final Conversion conversionFromBase = getConversionFromBase();
return new Geodetic(properties, (GeodeticCRS) conversionFromBase.getSourceCRS(),
- conversionFromBase, (EllipsoidalCS) derivedCS);
+ conversionFromBase, derivedCS);
}
- /** Returns the WKT keyword for this derived CRS type.*/
+ /** Returns the WKT keyword for this derived CRS type. */
@Override String keyword(final Formatter formatter) {
return formatter.shortOrLong(WKTKeywords.GeodCRS, WKTKeywords.GeodeticCRS);
}
@@ -731,7 +725,7 @@ public class DefaultDerivedCRS extends A
conversionFromBase, (VerticalCS) derivedCS);
}
- /** Returns the WKT keyword for this derived CRS type.*/
+ /** Returns the WKT keyword for this derived CRS type. */
@Override String keyword(final Formatter formatter) {
return formatter.shortOrLong(WKTKeywords.VertCRS, WKTKeywords.VerticalCRS);
}
@@ -784,7 +778,7 @@ public class DefaultDerivedCRS extends A
conversionFromBase, (TimeCS) derivedCS);
}
- /** Returns the WKT keyword for this derived CRS type.*/
+ /** Returns the WKT keyword for this derived CRS type. */
@Override String keyword(final Formatter formatter) {
return WKTKeywords.TimeCRS;
}
@@ -834,7 +828,7 @@ public class DefaultDerivedCRS extends A
return new Engineering(properties, (EngineeringCRS) conversionFromBase.getSourceCRS(), conversionFromBase, derivedCS);
}
- /** Returns the WKT keyword for this derived CRS type.*/
+ /** Returns the WKT keyword for this derived CRS type. */
@Override String keyword(final Formatter formatter) {
return formatter.shortOrLong(WKTKeywords.EngCRS, WKTKeywords.EngineeringCRS);
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -74,6 +74,7 @@ import org.apache.sis.internal.referenci
import org.apache.sis.internal.referencing.EPSGParameterDomain;
import org.apache.sis.internal.referencing.Formulas;
import org.apache.sis.internal.system.Loggers;
+import org.apache.sis.internal.system.Semaphores;
import org.apache.sis.internal.util.Constants;
import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.metadata.iso.ImmutableIdentifier;
@@ -976,6 +977,9 @@ addURIs: for (int i=0; ; i++) {
* The given {@code name} may be prefixed by {@code "epsg_"} and may contain abbreviations of the full name.
* For example {@code "epsg_coordoperation"} is considered as a match for {@code "Coordinate_Operation"}.
*
+ * <p>The table name should be one of the values enumerated in the {@code epsg_table_name} type of the
+ * {@code EPSG_Prepare.sql} file.</p>
+ *
* @param expected The expected table name (e.g. {@code "Coordinate_Operation"}).
* @param name The actual table name.
* @return Whether the given {@code name} is considered to match the expected name.
@@ -1322,6 +1326,9 @@ addURIs: for (int i=0; ; i++) {
/*
* Note: Do not invoke 'createProperties' now, even if we have all required informations,
* because the 'properties' map is going to overwritten by calls to 'createDatum', etc.
+ *
+ * The following switch statement should have a case for all "epsg_crs_kind" values enumerated
+ * in the "EPSG_Prepare.sql" file, except that the values in this Java code are in lower cases.
*/
final CRSFactory crsFactory = owner.crsFactory;
final CoordinateReferenceSystem crs;
@@ -1371,23 +1378,65 @@ addURIs: for (int i=0; ; i++) {
ensureNoCycle(ProjectedCRS.class, epsg);
try {
final CartesianCS cs = owner.createCartesianCS(csCode);
- final GeographicCRS baseCRS;
- if (deprecated) try {
- quiet = true;
- replaceDeprecatedCS = true;
- baseCRS = createGeographicCRS(geoCode); // Do not cache that CRS.
- } finally {
- quiet = false;
- replaceDeprecatedCS = false;
- } else {
- baseCRS = owner.createGeographicCRS(geoCode);
+ final Conversion op;
+ try {
+ op = (Conversion) owner.createCoordinateOperation(opCode);
+ } catch (ClassCastException e) {
+ // Should never happen in a well-formed EPSG database.
+ // If happen anyway, the ClassCastException cause will give more hints than just the message.
+ throw (NoSuchAuthorityCodeException) noSuchAuthorityCode(Projection.class, opCode).initCause(e);
}
- final CoordinateOperation op = owner.createCoordinateOperation(opCode);
- if (op instanceof Conversion) {
- crs = crsFactory.createProjectedCRS(createProperties("Coordinate Reference System",
- name, epsg, area, scope, remarks, deprecated), baseCRS, (Conversion) op, cs);
+ final CoordinateReferenceSystem baseCRS;
+ final boolean resumeParamChecks;
+ if (!deprecated) {
+ baseCRS = owner.createCoordinateReferenceSystem(geoCode);
+ resumeParamChecks = false;
} else {
- throw noSuchAuthorityCode(Projection.class, opCode);
+ /*
+ * If the ProjectedCRS is deprecated, one reason among others may be that it uses one of
+ * the deprecated coordinate systems. Those deprecated CS used non-linear units like DMS.
+ * Apache SIS can not instantiate a ProjectedCRS when the baseCRS uses such units, so we
+ * set a flag asking to replace the deprecated CS by a supported one. Since that baseCRS
+ * would not be exactly as defined by EPSG, we must not cache it because we do not want
+ * 'owner.createGeographicCRS(geoCode)' to return that modified CRS. Since the same CRS
+ * may be recreated every time a deprecated ProjectedCRS is created, we temporarily
+ * shutdown the loggings in order to avoid the same warning to be logged many time.
+ */
+ try {
+ quiet = true;
+ replaceDeprecatedCS = true;
+ baseCRS = createCoordinateReferenceSystem(geoCode); // Do not cache that CRS.
+ } finally {
+ replaceDeprecatedCS = false;
+ quiet = false;
+ }
+ /*
+ * The crsFactory method calls will indirectly create a parameterized MathTransform.
+ * Their constructor will try to verify the parameter validity. But some deprecated
+ * CRS had invalid parameter values (they were deprecated precisely for that reason).
+ * If and only if we are creating a deprecated CRS, temporarily suspend the parameter
+ * checks.
+ */
+ resumeParamChecks = !Semaphores.queryAndSet(Semaphores.SUSPEND_PARAMETER_CHECK);
+ // Try block must be immediately after above line (do not insert any code between).
+ }
+ try {
+ /*
+ * For a ProjectedCRS, the baseCRS is always geographic. So in theory we would not
+ * need the 'instanceof' check. However the EPSG dataset version 8.9 also uses the
+ * "projected" type for CRS that are actually derived CRS. See EPSG:5820 and 5821.
+ */
+ final Map<String, Object> properties = createProperties("Coordinate Reference System",
+ name, epsg, area, scope, remarks, deprecated);
+ if (baseCRS instanceof GeographicCRS) {
+ crs = crsFactory.createProjectedCRS(properties, (GeographicCRS) baseCRS, op, cs);
+ } else {
+ crs = crsFactory.createDerivedCRS(properties, baseCRS, op, cs);
+ }
+ } finally {
+ if (resumeParamChecks) {
+ Semaphores.clear(Semaphores.SUSPEND_PARAMETER_CHECK);
+ }
}
} finally {
endOfRecursivity(ProjectedCRS.class, epsg);
@@ -1556,6 +1605,10 @@ addURIs: for (int i=0; ; i++) {
} catch (NumberFormatException exception) {
unexpectedException("createDatum", exception); // Not a fatal error.
}
+ /*
+ * The following switch statement should have a case for all "epsg_datum_kind" values enumerated
+ * in the "EPSG_Prepare.sql" file, except that the values in this Java code are in lower cases.
+ */
final DatumFactory datumFactory = owner.datumFactory;
final Datum datum;
switch (type.toLowerCase(Locale.US)) {
@@ -2007,6 +2060,10 @@ addURIs: for (int i=0; ; i++) {
final boolean deprecated = getOptionalBoolean(result, 6);
final CoordinateSystemAxis[] axes = createCoordinateSystemAxes(epsg, dimension);
final Map<String,Object> properties = createProperties("Coordinate System", name, epsg, remarks, deprecated); // Must be after axes.
+ /*
+ * The following switch statement should have a case for all "epsg_cs_kind" values enumerated
+ * in the "EPSG_Prepare.sql" file, except that the values in this Java code are in lower cases.
+ */
final CSFactory csFactory = owner.csFactory;
CoordinateSystem cs = null;
switch (type.toLowerCase(Locale.US)) {
@@ -2037,8 +2094,8 @@ addURIs: for (int i=0; ; i++) {
}
break;
}
- case "time": // Was used in older ISO-19111 versions.
- case "temporal": {
+ case "time":
+ case "temporal": { // Was used in older ISO-19111 versions.
switch (dimension) {
case 1: cs = csFactory.createTimeCS(properties, axes[0]); break;
}
@@ -2503,14 +2560,14 @@ next: while (r.next()) {
param = parameters.parameter(name);
} catch (ParameterNotFoundException exception) {
/*
- * Wraps the unchecked ParameterNotFoundException into the checked NoSuchIdentifierException,
+ * Wrap the unchecked ParameterNotFoundException into the checked NoSuchIdentifierException,
* which is a FactoryException subclass. Note that in principle, NoSuchIdentifierException is for
* MathTransforms rather than parameters. However we are close in spirit here since we are setting
* up MathTransform's parameters. Using NoSuchIdentifierException allows CoordinateOperationSet to
- * know that the failure is probably caused by a MathTransform not yet supported in Apache SIS (or
- * only partially supported) rather than some more serious failure in the database side. Callers
- * can use this information in order to determine if they should try the next coordinate operation
- * or propagate the exception.
+ * know that the failure is probably caused by a MathTransform not yet supported in Apache SIS
+ * (or only partially supported) rather than some more serious failure in the database side.
+ * Callers can use this information in order to determine if they should try the next coordinate
+ * operation or propagate the exception.
*/
final NoSuchIdentifierException e = new NoSuchIdentifierException(error()
.getString(Errors.Keys.CanNotSetParameterValue_1, name), name);
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=1731655&r1=1731654&r2=1731655&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] Mon Feb 22 15:01:37 2016
@@ -44,6 +44,8 @@ import org.apache.sis.internal.jdk8.BiFu
/**
* Runs the SQL scripts for creating an EPSG database.
*
+ * See {@code EPSGDataFormatter} in the test directory for more information about how the scripts are formatted.
+ *
* @author Martin Desruisseaux (Geomatys)
* @since 0.7
* @version 0.7
@@ -147,8 +149,20 @@ final class EPSGInstaller extends Script
addReplacement(SQLTranslator.TABLE_PREFIX + "supersession", "Supersession");
addReplacement(SQLTranslator.TABLE_PREFIX + "unitofmeasure", "Unit of Measure");
addReplacement(SQLTranslator.TABLE_PREFIX + "versionhistory", "Version History");
+ if (isEnumTypeSupported) {
+ addReplacement(SQLTranslator.TABLE_PREFIX + "datum_kind", "Datum Kind");
+ addReplacement(SQLTranslator.TABLE_PREFIX + "crs_kind", "CRS Kind");
+ addReplacement(SQLTranslator.TABLE_PREFIX + "cs_kind", "CS Kind");
+ addReplacement(SQLTranslator.TABLE_PREFIX + "table_name", "Table Name");
+ }
prependNamespace(schema);
}
+ if (!isEnumTypeSupported) {
+ addReplacement(SQLTranslator.TABLE_PREFIX + "datum_kind", "VARCHAR(24)");
+ addReplacement(SQLTranslator.TABLE_PREFIX + "crs_kind", "VARCHAR(24)");
+ addReplacement(SQLTranslator.TABLE_PREFIX + "cs_kind", "VARCHAR(24)");
+ addReplacement(SQLTranslator.TABLE_PREFIX + "table_name", "VARCHAR(80)");
+ }
}
/**
@@ -210,6 +224,12 @@ final class EPSGInstaller extends Script
if (!isGrantOnTableSupported && CharSequences.regionMatches(sql, 0, "GRANT")) {
return 0;
}
+ if (!isEnumTypeSupported && CharSequences.regionMatches(sql, 0, "CREATE")) {
+ final String t = CharSequences.trimWhitespaces(sql, 6, 12).toString();
+ if (t.equals("TYPE") || t.equals("CAST")) {
+ return 0;
+ }
+ }
if (statementToSkip != null && statementToSkip.reset(sql).matches()) {
return 0;
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -69,12 +69,20 @@ import java.nio.file.Path;
*/
public abstract class InstallationScriptProvider {
/**
+ * A sentinel value for the content of the script to execute before the official EPSG scripts.
+ * This is an Apache SIS build-in script for constraining the values of some {@code VARCHAR} columns
+ * to enumerations of values recognized by {@link EPSGDataAccess}. Those enumerations are not required
+ * for proper working of {@link EPSGFactory}, but can improve data integrity.
+ */
+ protected static final String PREPARE = "Prepare";
+
+ /**
* A sentinel value for the content of the script to execute after the official EPSG scripts.
* This is an Apache SIS build-in script for creating indexes or performing any other manipulation
* that help SIS to use the EPSG dataset. Those indexes are not required for proper working of
* {@link EPSGFactory}, but can significantly improve performances.
*/
- protected static final String POST_CREATE = "(post create)";
+ protected static final String FINISH = "Finish";
/**
* The names of the SQL scripts to read.
@@ -90,7 +98,7 @@ public abstract class InstallationScript
* (potentially completed with EPSG dataset version and database software name):</p>
*
* <blockquote><code>
- * "EPSG_Tables.sql", "EPSG_Data.sql", "EPSG_FKeys.sql", {@linkplain #POST_CREATE}
+ * {@linkplain #PREPARE}, "EPSG_Tables.sql", "EPSG_Data.sql", "EPSG_FKeys.sql", {@linkplain #FINISH}
* </code></blockquote>
*
* @param names Names of the SQL scripts to read.
@@ -176,8 +184,8 @@ public abstract class InstallationScript
String name = names[index];
final Charset charset;
final InputStream in;
- if (POST_CREATE.equals(name)) {
- name = authority.concat(".sql");
+ if (PREPARE.equals(name) || FINISH.equals(name)) {
+ name = authority + '_' + name + ".sql";
in = InstallationScriptProvider.class.getResourceAsStream(name);
charset = StandardCharsets.UTF_8;
} else {
@@ -193,7 +201,7 @@ public abstract class InstallationScript
/**
* Opens the input stream for the SQL script of the given name.
* This method is invoked by the default implementation of {@link #getScriptContent(int)}
- * for all scripts except {@link #POST_CREATE}.
+ * for all scripts except {@link #PREPARE} and {@link #FINISH}.
*
* <div class="note"><b>Examples:</b>
* If this {@code InstallationScriptProvider} instance gets the SQL scripts from files in a well-known directory
@@ -250,10 +258,11 @@ public abstract class InstallationScript
* Creates a default provider.
*/
public Default() {
- super("EPSG_Tables.sql",
+ super(PREPARE,
+ "EPSG_Tables.sql",
"EPSG_Data.sql",
"EPSG_FKeys.sql",
- POST_CREATE);
+ FINISH);
Path dir = DataDirectory.DATABASES.getDirectory();
if (dir != null) {
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -227,21 +227,27 @@ final class Initializer {
*/
final double getAndStore(final ParameterDescriptor<? extends Number> descriptor) {
if (descriptor == null) {
- return 0; // Default value for all parameters except scale factor.
+ return 0; // Default value for all parameters except scale factor.
}
+ /*
+ * Get the parameter value, or its default value if the parameter was not set. That default value
+ * (which is specified by the descriptor of the user-supplied parameters) is not necessarily the
+ * same than the default value of the map projection implementation (which is specified by the
+ * descriptor given in argument to this method).
+ */
final double value = parameters.doubleValue(descriptor); // Apply a unit conversion if needed.
final Number defaultValue = descriptor.getDefaultValue();
if (defaultValue == null || !defaultValue.equals(value)) {
MapProjection.validate(descriptor, value);
- context.getOrCreate(descriptor).setValue(value);
+ context.parameter(descriptor.getName().getCode()).setValue(value);
}
return value;
}
/**
- * Same as {@link #getAndStore(Parameters, ParameterDescriptor)}, but returns the given default value
- * if the parameter is not specified. This method shall be used only for parameters having a default
- * value more complex than what we can represent in {@link ParameterDescriptor#getDefaultValue()}.
+ * Same as {@link #getAndStore(ParameterDescriptor)}, but returns the given default value if the parameter
+ * is not specified. This method shall be used only for parameters having a default value more complex than
+ * what we can represent in {@link ParameterDescriptor#getDefaultValue()}.
*/
final double getAndStore(final ParameterDescriptor<Double> descriptor, final double defaultValue) {
final Double value = parameters.getValue(descriptor); // Apply a unit conversion if needed.
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -603,19 +603,18 @@ public class ContextualParameters extend
throw parameterNotFound(name);
}
/*
- * Search for existing parameter instance. This implementation does not scale,
- * but should be okay since the amount of parameters is typically very small
- * (rarely more than 6 parameters in map projections).
+ * Search for existing parameter instance. This implementation does not scale, but should be okay since
+ * the amount of parameters is typically very small (rarely more than 6 parameters in map projections).
*/
for (int i=0; i < values.length; i++) {
ParameterValue<?> p = values[i];
if (p == null) {
- p = ((ParameterDescriptor<?>) desc).createValue();
- values[i] = p;
- } else if (p.getDescriptor() != desc) { // Identity comparison should be okay here.
- continue;
+ values[i] = p = new ContextualParameter<>((ParameterDescriptor<?>) desc);
+ return p;
+ }
+ if (p.getDescriptor() == desc) { // Identity comparison should be okay here.
+ return p;
}
- return p; // Found or created a parameter.
}
/*
* We may reach this point if map projection construction is completed (i.e. 'completeTransform(…)' has
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -36,6 +36,8 @@ import org.opengis.parameter.ParameterVa
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.parameter.ParameterNotFoundException;
+import org.opengis.parameter.InvalidParameterNameException;
+import org.opengis.parameter.InvalidParameterValueException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.EllipsoidalCS;
@@ -627,11 +629,17 @@ public class DefaultMathTransformFactory
* The intend is to make sure that we have room for the parameters that {@code setEllipsoids(…)}
* may write.
*
+ * <p>A side effect of this method is that the copy operation may perform a check of
+ * parameter value validity. This may result in an {@link InvalidParameterNameException}
+ * or {@link InvalidParameterValueException} to be thrown.</p>
+ *
* @param writable {@code true} if this method should also check that the parameters group is not
* an instance of {@link UnmodifiableParameterValueGroup}. Current implementation assumes
* that modifiable parameters are instances of {@link DefaultParameterValueGroup}.
+ * @throws IllegalArgumentException if the copy can not be performed because a parameter has
+ * a unrecognized name or an illegal value.
*/
- private void ensureCompatibleParameters(final boolean writable) {
+ private void ensureCompatibleParameters(final boolean writable) throws IllegalArgumentException {
final ParameterDescriptorGroup expected = provider.getParameters();
if (parameters.getDescriptor() != expected ||
(writable && (parameters instanceof Parameters)
@@ -784,8 +792,10 @@ public class DefaultMathTransformFactory
* @return The exception if the operation failed, or {@code null} if none. This exception is not thrown now
* because the caller may succeed in creating the transform anyway, or otherwise may produce a more
* informative exception.
+ * @throws IllegalArgumentException if the operation fails because a parameter has a unrecognized name or an
+ * illegal value.
*/
- final RuntimeException setEllipsoids(final OperationMethod method) {
+ final RuntimeException setEllipsoids(final OperationMethod method) throws IllegalArgumentException {
ensureCompatibleParameters(false);
int n;
if (method instanceof AbstractProvider) {
@@ -908,21 +918,21 @@ public class DefaultMathTransformFactory
Errors.Keys.UnsupportedImplementation_1, Classes.getClass(method)), methodName);
}
/*
- * If the user's parameters do not contain semi-major and semi-minor axis lengths, infer
- * them from the ellipsoid. We have to do that because those parameters are often omitted,
- * since the standard place where to provide this information is in the ellipsoid object.
- */
- if (context != null) {
- context.provider = method;
- context.parameters = parameters;
- failure = context.setEllipsoids(method);
- parameters = context.parameters;
- }
- /*
- * Catch only exceptions which may be the result of improper parameter usage (e.g. a value out of range).
- * Do not catch exception caused by programming errors (e.g. null pointer exception).
+ * Will catch only exceptions that may be the result of improper parameter usage (e.g. a value out
+ * of range). Do not catch exceptions caused by programming errors (e.g. null pointer exception).
*/
try {
+ /*
+ * If the user's parameters do not contain semi-major and semi-minor axis lengths, infer
+ * them from the ellipsoid. We have to do that because those parameters are often omitted,
+ * since the standard place where to provide this information is in the ellipsoid object.
+ */
+ if (context != null) {
+ context.provider = method;
+ context.parameters = parameters;
+ failure = context.setEllipsoids(method);
+ parameters = context.parameters;
+ }
transform = ((MathTransformProvider) method).createMathTransform(this, parameters);
} catch (IllegalArgumentException | IllegalStateException exception) {
throw new InvalidGeodeticParameterException(exception.getLocalizedMessage(), exception);
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=1731655&r1=1731654&r2=1731655&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] Mon Feb 22 15:01:37 2016
@@ -87,6 +87,8 @@ public final strictfp class EPSGFactoryF
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");
Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -32,6 +32,7 @@ import java.sql.SQLException;
import javax.sql.DataSource;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.sis.util.Workaround;
import org.apache.sis.util.CharSequences;
import org.apache.sis.internal.metadata.sql.ScriptRunner;
import org.apache.sis.internal.metadata.sql.TestDatabase;
@@ -76,6 +77,7 @@ import java.nio.charset.StandardCharsets
*
* <li><p>Open the {@code Tables.sql} file for edition:</p>
* <ul>
+ * <li>Keep the header comments that existed in the overwritten file.</li>
* <li>In the statement creating the {@code coordinateaxis} table,
* add the {@code NOT NULL} constraint to the {@code coord_axis_code} column.</li>
* <li>In the statement creating the {@code change} table,
@@ -85,6 +87,10 @@ import java.nio.charset.StandardCharsets
* change the type of the {@code realization_epoch} column to {@code SMALLINT}.</li>
* <li>Change the type of {@code show_crs}, {@code show_operation} and all {@code deprecated} fields
* from {@code SMALLINT} to {@code BOOLEAN}.</li>
+ * <li>Change the type of every {@code table_name} columns from {@code VARCHAR(80)} to {@code epsg_table_name}.</li>
+ * <li>Change the type of {@code coord_ref_sys_kind} column from {@code VARCHAR(24)} to {@code epsg_crs_kind}.</li>
+ * <li>Change the type of {@code coord_sys_type} column from {@code VARCHAR(24)} to {@code epsg_cs_kind}.</li>
+ * <li>Change the type of {@code datum_type} column from {@code VARCHAR(24)} to {@code epsg_datum_kind}.</li>
* <li>Suppress trailing spaces and save.</li>
* </ul>
* <p>Usually this results in no change at all compared to the previous script (ignoring white spaces),
@@ -239,6 +245,14 @@ public final class EPSGDataFormatter ext
try (final LineNumberReader in = new LineNumberReader(
new InputStreamReader(new FileInputStream(inputFile), StandardCharsets.ISO_8859_1)))
{
+ out.write("---\n" +
+ "--- Copyright International Association of Oil and Gas Producers (IOGP)\n" +
+ "--- See http://www.epsg.org/TermsOfUse (a copy is in ./LICENSE.txt).\n" +
+ "---\n" +
+ "--- This file has been reformatted (without any change in the data) for the needs of Apache SIS project.\n" +
+ "--- See org.apache.sis.referencing.factory.sql.EPSGDataFormatter.\n" +
+ "---\n" +
+ "\n");
run(inputFile.getName(), in);
} finally {
out.close();
@@ -247,6 +261,18 @@ public final class EPSGDataFormatter ext
}
/**
+ * EPSG scripts version 8.9 seems to have 2 errors where the {@code OBJECT_TABLE_NAME} column contains
+ * {@code "AxisName"} instead of {@code "Coordinate Axis Name"}.
+ */
+ @Override
+ @Workaround(library="EPSG", version="8.9")
+ protected void editText(final StringBuilder sql, int lower, final int upper) {
+ if (upper - lower == 10 && CharSequences.regionMatches(sql, ++lower, "AxisName")) {
+ sql.replace(lower, upper-1, "Coordinate Axis Name");
+ }
+ }
+
+ /**
* "Executes" the given SQL statement. In the context of this {@code EPSGDataWriter} class,
* executing a SQL statement means compacting it and writing it to the output file.
*
@@ -259,6 +285,35 @@ public final class EPSGDataFormatter ext
protected int execute(final StringBuilder sql) throws IOException, SQLException {
removeLF(sql);
String line = CharSequences.trimWhitespaces(sql).toString();
+ if (line.startsWith("UPDATE ")) {
+ /*
+ * Some EPSG tables have a "table_name" field which will contain the names of other EPSG tables.
+ * In the EPSG scripts, the values are initially the table names used in the MS-Access database.
+ * Then the MS-Access table names are replaced by statements like below:
+ *
+ * UPDATE epsg_alias SET object_table_name = 'epsg_coordinateaxis' WHERE object_table_name = 'Coordinate Axis';
+ * UPDATE epsg_deprecation SET object_table_name = 'epsg_alias' WHERE object_table_name = 'Alias';
+ * etc.
+ *
+ * For Apache SIS, we keep the original table names as defined in MS-Access database,
+ * for consistency with the table names that we actually use in our EPSG schema.
+ */
+ if (line.contains("object_table_name")) {
+ return 0;
+ }
+ /*
+ * Following statements do not make sense anymore on enumerated values:
+ *
+ * UPDATE epsg_coordinatereferencesystem SET coord_ref_sys_kind = replace(coord_ref_sys_kind, CHR(182), CHR(10));
+ * UPDATE epsg_coordinatesystem SET coord_sys_type = replace(coord_sys_type, CHR(182), CHR(10));
+ * UPDATE epsg_datum SET datum_type = replace(datum_type, CHR(182), CHR(10));
+ */
+ if (line.contains("replace")) {
+ if (line.contains("coord_ref_sys_kind") || line.contains("coord_sys_type") || line.contains("datum_type")) {
+ return 0;
+ }
+ }
+ }
if (insertStatement != null) {
if (line.startsWith(insertStatement)) {
// The previous instruction was already an INSERT INTO the same table.
Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -288,7 +288,6 @@ public final strictfp class CoordinateRe
rd("Nivellement General du Luxembourg", "Nivellement Général Corse / France / Nouvelle-Calédonie / Polynésie Française / Luxembourd / Guyanais");
rd("Nivellement General Guyanais 1977", "Nivellement Général Corse / France / Nouvelle-Calédonie / Polynésie Française / Luxembourd / Guyanais");
rd("NGO 1948 (Oslo)", "NGO 1948");
- rd("NAD27 Michigan", "North American Datum 1927 — Michigan");
rd("NAD83 (High Accuracy Reference Network)", "North American Datum 1983 — High Accuracy Reference Network");
rd("NAD83 (National Spatial Reference System 2007)", "North American Datum 1983 — National Spatial Reference System 2007");
rd("NAD83 Canadian Spatial Reference System", "North American Datum 1983 — Canadian Spatial Reference System");
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -24,7 +24,7 @@ package org.apache.sis.internal.system;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.5
- * @version 0.6
+ * @version 0.7
* @module
*/
public final class Semaphores {
@@ -53,6 +53,16 @@ public final class Semaphores {
public static final byte NULL_COLLECTION = 4;
/**
+ * A flag to indicate that a parameter value outside its domain of validity should not cause an exception
+ * to be thrown. This flag is set only when creating a deprecated operation from the EPSG database.
+ * Typically the operation is deprecated precisely because it used invalid parameter values,
+ * but SIS should still be able to create those deprecated objects if a user request them.
+ *
+ * <p><b>Example:</b> EPSG:3752 was a Mercator (variant A) projection but set the latitude of origin to 41°S.</p>
+ */
+ public static final byte SUSPEND_PARAMETER_CHECK = 8;
+
+ /**
* The flags per running thread.
*/
private static final ThreadLocal<Semaphores> FLAGS = new ThreadLocal<>();
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -83,9 +83,9 @@ public final class Supervisor extends St
*/
public static synchronized void register() {
if (name == null) {
- name = ObjectName.WILDCARD; // In case of failure.
- final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ name = ObjectName.WILDCARD; // In case of failure.
try {
+ final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
final ObjectName n = new ObjectName(NAME);
server.registerMBean(new Supervisor(), n);
name = n; // Store only on success.
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java?rev=1731655&r1=1731654&r2=1731655&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java [UTF-8] Mon Feb 22 15:01:37 2016
@@ -91,7 +91,7 @@ public class UnmodifiableArrayList<E> ex
*
* @param array The array to wrap.
*/
- protected UnmodifiableArrayList(final E[] array) { // NOT "E..." - see javadoc.
+ protected UnmodifiableArrayList(final E[] array) { // NOT "E..." - see javadoc.
this.array = Objects.requireNonNull(array);
}
@@ -115,7 +115,7 @@ public class UnmodifiableArrayList<E> ex
* @return The given array wrapped in an unmodifiable list, or {@code null} if the given
* array was null.
*/
- public static <E> UnmodifiableArrayList<E> wrap(final E[] array) { // NOT "E..." - see javadoc.
+ public static <E> UnmodifiableArrayList<E> wrap(final E[] array) { // NOT "E..." - see javadoc.
return (array != null) ? new UnmodifiableArrayList<>(array) : null;
}