sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1718286 [1/2] - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/referencing/factory/ sis-utility/src/main/java/org/apache/sis/util/resources/
Date Mon, 07 Dec 2015 10:06:31 GMT
Author: desruisseaux
Date: Mon Dec  7 10:06:31 2015
New Revision: 1718286

URL: http://svn.apache.org/viewvc?rev=1718286&view=rev
Log:
Base class of authority factories.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java   (with props)
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java   (with props)
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java   (with props)
Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java?rev=1718286&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java (added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java [UTF-8] Mon Dec  7 10:06:31 2015
@@ -0,0 +1,560 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.factory;
+
+import javax.measure.unit.Unit;
+import org.opengis.referencing.cs.*;
+import org.opengis.referencing.crs.*;
+import org.opengis.referencing.datum.*;
+import org.opengis.referencing.operation.*;
+import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.AuthorityFactory;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.util.FactoryException;
+import org.apache.sis.util.resources.Errors;
+
+
+/**
+ * Delegates object creations to one of the {@code create} methods in a backing {@code AuthorityFactory}.
+ * It is possible to use the generic {@link AuthorityFactory#createObject(String)} method instead of this class,
+ * but some factories are more efficient when we use the most specific {@code create} method.
+ * For example when using a {@linkplain org.apache.sis.referencing.factory.epsg.EPSGFactory},
+ * invoking {@link CRSAuthorityFactory#createProjectedCRS(String)} instead of
+ * {@code AuthorityFactory.createObject(String)} method reduce the amount of tables to be queried.
+ *
+ * <p>This class is useful when the same {@code create} method need to be invoked often, but is unknown at compile time.
+ * It may also be used as a workaround for authority factories that do not implement the {@code createObject(String)}
+ * method.</p>
+ *
+ * <div class="note"><b>Example:</b>
+ * the following code creates a proxy which will delegates its work to the
+ * {@link CRSAuthorityFactory#createGeographicCRS createGeographicCRS} method.
+ *
+ * {@preformat java
+ *     String code = ...;
+ *     AuthorityFactory factory = ...;
+ *     AuthorityFactoryProxy proxy = AuthorityFactoryProxy.getInstance(GeographicCRS.class);
+ *     GeographicCRS crs = proxy.create(factory, code); // Invokes factory.createGeographicCRS(code);
+ * }</div>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+abstract class AuthorityFactoryProxy<T> {
+    /**
+     * The type of objects to be created.
+     */
+    final Class<T> type;
+
+    /**
+     * Creates a new proxy for objects of the given type.
+     */
+    AuthorityFactoryProxy(final Class<T> type) {
+        this.type = type;
+    }
+
+    /**
+     * Returns a string representation for debugging purpose.
+     */
+    @Override
+    public String toString() {
+        return "AuthorityFactoryProxy[" + type.getSimpleName() + ']';
+    }
+
+    /**
+     * Casts the given factory into a datum authority factory, or throws a {@code FactoryException}
+     * if the given factory is not of the expected type.
+     */
+    final DatumAuthorityFactory datumFactory(final AuthorityFactory factory) throws FactoryException {
+        if (factory instanceof DatumAuthorityFactory) {
+            return (DatumAuthorityFactory) factory;
+        }
+        throw factoryNotFound(DatumAuthorityFactory.class);
+    }
+
+    /**
+     * Casts the given factory into a CS authority factory, or throws a {@code FactoryException}
+     * if the given factory is not of the expected type.
+     */
+    final CSAuthorityFactory csFactory(final AuthorityFactory factory) throws FactoryException {
+        if (factory instanceof CSAuthorityFactory) {
+            return (CSAuthorityFactory) factory;
+        }
+        throw factoryNotFound(CSAuthorityFactory.class);
+    }
+
+    /**
+     * Casts the given factory into a CRS authority factory, or throws a {@code FactoryException}
+     * if the given factory is not of the expected type.
+     */
+    final CRSAuthorityFactory crsFactory(final AuthorityFactory factory) throws FactoryException {
+        if (factory instanceof CRSAuthorityFactory) {
+            return (CRSAuthorityFactory) factory;
+        }
+        throw factoryNotFound(CRSAuthorityFactory.class);
+    }
+
+    /**
+     * Casts the given factory into an operation authority factory, or throws a {@code FactoryException}
+     * if the given factory is not of the expected type.
+     */
+    final CoordinateOperationAuthorityFactory opFactory(final AuthorityFactory factory) throws FactoryException {
+        if (factory instanceof CoordinateOperationAuthorityFactory) {
+            return (CoordinateOperationAuthorityFactory) factory;
+        }
+        throw factoryNotFound(CoordinateOperationAuthorityFactory.class);
+    }
+
+    /**
+     * Casts the given factory into a geodetic authority factory, or throws a {@code FactoryException}
+     * if the given factory is not of the expected type.
+     */
+    final GeodeticAuthorityFactory geodeticFactory(final AuthorityFactory factory) throws FactoryException {
+        if (factory instanceof CRSAuthorityFactory) {
+            return (GeodeticAuthorityFactory) factory;
+        }
+        throw factoryNotFound(GeodeticAuthorityFactory.class);
+    }
+
+    /**
+     * Returns the exception to be thrown when a factory is not found.
+     */
+    private static FactoryException factoryNotFound(final Class<? extends AuthorityFactory> type) {
+        return new FactoryException(Errors.format(Errors.Keys.FactoryNotFound_1, type));
+    }
+
+    /**
+     * Creates the object for the given code.
+     *
+     * @param  factory The factory to use for creating the object.
+     * @param  code    The code for which to create an object.
+     * @return The object created from the given code.
+     * @throws FactoryException If an error occurred while creating the object.
+     */
+    abstract T create(GeodeticAuthorityFactory factory, String code) throws FactoryException;
+
+    /**
+     * Creates the object for the given code using only GeoAPI interfaces.
+     * This method is slightly less efficient than the above {@link #create} method.
+     *
+     * @param  factory The factory to use for creating the object.
+     * @param  code    The code for which to create an object.
+     * @return The object created from the given code.
+     * @throws FactoryException If an error occurred while creating the object.
+     */
+    abstract T createFromAPI(AuthorityFactory factory, String code) throws FactoryException;
+
+    /**
+     * The proxy for the {@link GeodeticAuthorityFactory#createObject} method.
+     */
+    static final AuthorityFactoryProxy<IdentifiedObject> OBJECT =
+        new AuthorityFactoryProxy<IdentifiedObject>(IdentifiedObject.class) {
+            @Override IdentifiedObject create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createObject(code);
+            }
+            @Override IdentifiedObject createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return factory.createObject(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<Datum> DATUM =
+        new AuthorityFactoryProxy<Datum>(Datum.class) {
+            @Override Datum create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createDatum(code);
+            }
+            @Override Datum createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return datumFactory(factory).createDatum(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<EngineeringDatum> ENGINEERING_DATUM =
+        new AuthorityFactoryProxy<EngineeringDatum>(EngineeringDatum.class) {
+            @Override EngineeringDatum create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createEngineeringDatum(code);
+            }
+            @Override EngineeringDatum createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return datumFactory(factory).createEngineeringDatum(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<ImageDatum> IMAGE_DATUM =
+        new AuthorityFactoryProxy<ImageDatum>(ImageDatum.class) {
+            @Override ImageDatum create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createImageDatum(code);
+            }
+            @Override ImageDatum createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return datumFactory(factory).createImageDatum(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<VerticalDatum> VERTICAL_DATUM =
+        new AuthorityFactoryProxy<VerticalDatum>(VerticalDatum.class) {
+            @Override VerticalDatum create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createVerticalDatum(code);
+            }
+            @Override VerticalDatum createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return datumFactory(factory).createVerticalDatum(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<TemporalDatum> TEMPORAL_DATUM =
+        new AuthorityFactoryProxy<TemporalDatum>(TemporalDatum.class) {
+            @Override TemporalDatum create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createTemporalDatum(code);
+            }
+            @Override TemporalDatum createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return datumFactory(factory).createTemporalDatum(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<GeodeticDatum> GEODETIC_DATUM =
+        new AuthorityFactoryProxy<GeodeticDatum>(GeodeticDatum.class) {
+            @Override GeodeticDatum create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createGeodeticDatum(code);
+            }
+            @Override GeodeticDatum createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return datumFactory(factory).createGeodeticDatum(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<Ellipsoid> ELLIPSOID =
+        new AuthorityFactoryProxy<Ellipsoid>(Ellipsoid.class) {
+            @Override Ellipsoid create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createEllipsoid(code);
+            }
+            @Override Ellipsoid createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return datumFactory(factory).createEllipsoid(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<PrimeMeridian> PRIME_MERIDIAN =
+        new AuthorityFactoryProxy<PrimeMeridian>(PrimeMeridian.class) {
+            @Override PrimeMeridian create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createPrimeMeridian(code);
+            }
+            @Override PrimeMeridian createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return datumFactory(factory).createPrimeMeridian(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<Extent> EXTENT =
+        new AuthorityFactoryProxy<Extent>(Extent.class) {
+            @Override Extent create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createExtent(code);
+            }
+            @Override Extent createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return geodeticFactory(factory).createExtent(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<CoordinateSystem> COORDINATE_SYSTEM =
+        new AuthorityFactoryProxy<CoordinateSystem>(CoordinateSystem.class) {
+            @Override CoordinateSystem create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createCoordinateSystem(code);
+            }
+            @Override CoordinateSystem createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createCoordinateSystem(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<CartesianCS> CARTESIAN_CS =
+        new AuthorityFactoryProxy<CartesianCS>(CartesianCS.class) {
+            @Override CartesianCS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createCartesianCS(code);
+            }
+            @Override CartesianCS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createCartesianCS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<PolarCS> POLAR_CS =
+        new AuthorityFactoryProxy<PolarCS>(PolarCS.class) {
+            @Override PolarCS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createPolarCS(code);
+            }
+            @Override PolarCS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createPolarCS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<CylindricalCS> CYLINDRICAL_CS =
+        new AuthorityFactoryProxy<CylindricalCS>(CylindricalCS.class) {
+            @Override CylindricalCS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createCylindricalCS(code);
+            }
+            @Override CylindricalCS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createCylindricalCS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<SphericalCS> SPHERICAL_CS =
+        new AuthorityFactoryProxy<SphericalCS>(SphericalCS.class) {
+            @Override SphericalCS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createSphericalCS(code);
+            }
+            @Override SphericalCS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createSphericalCS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<EllipsoidalCS> ELLIPSOIDAL_CS =
+        new AuthorityFactoryProxy<EllipsoidalCS>(EllipsoidalCS.class) {
+            @Override EllipsoidalCS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createEllipsoidalCS(code);
+            }
+            @Override EllipsoidalCS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createEllipsoidalCS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<VerticalCS> VERTICAL_CS =
+        new AuthorityFactoryProxy<VerticalCS>(VerticalCS.class) {
+            @Override VerticalCS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createVerticalCS(code);
+            }
+            @Override VerticalCS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createVerticalCS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<TimeCS> TIME_CS =
+        new AuthorityFactoryProxy<TimeCS>(TimeCS.class) {
+            @Override TimeCS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createTimeCS(code);
+            }
+            @Override TimeCS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createTimeCS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<CoordinateSystemAxis> AXIS =
+        new AuthorityFactoryProxy<CoordinateSystemAxis>(CoordinateSystemAxis.class) {
+            @Override CoordinateSystemAxis create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createCoordinateSystemAxis(code);
+            }
+            @Override CoordinateSystemAxis createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createCoordinateSystemAxis(code);
+            }
+    };
+
+    @SuppressWarnings({"rawtypes","unchecked"})
+    static final AuthorityFactoryProxy<Unit<?>> UNIT =
+        new AuthorityFactoryProxy<Unit<?>>((Class) Unit.class) {
+            @Override Unit<?> create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createUnit(code);
+            }
+            @Override Unit<?> createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return csFactory(factory).createUnit(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<CoordinateReferenceSystem> CRS =
+        new AuthorityFactoryProxy<CoordinateReferenceSystem>(CoordinateReferenceSystem.class) {
+            @Override CoordinateReferenceSystem create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createCoordinateReferenceSystem(code);
+            }
+            @Override CoordinateReferenceSystem createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createCoordinateReferenceSystem(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<CompoundCRS> COMPOUND_CRS =
+        new AuthorityFactoryProxy<CompoundCRS>(CompoundCRS.class) {
+            @Override CompoundCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createCompoundCRS(code);
+            }
+            @Override CompoundCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createCompoundCRS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<DerivedCRS> DERIVED_CRS =
+        new AuthorityFactoryProxy<DerivedCRS>(DerivedCRS.class) {
+            @Override DerivedCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createDerivedCRS(code);
+            }
+            @Override DerivedCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createDerivedCRS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<EngineeringCRS> ENGINEERING_CRS =
+        new AuthorityFactoryProxy<EngineeringCRS>(EngineeringCRS.class) {
+            @Override EngineeringCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createEngineeringCRS(code);
+            }
+            @Override EngineeringCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createEngineeringCRS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<GeographicCRS> GEOGRAPHIC_CRS =
+        new AuthorityFactoryProxy<GeographicCRS>(GeographicCRS.class) {
+            @Override GeographicCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createGeographicCRS(code);
+            }
+            @Override GeographicCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createGeographicCRS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<GeocentricCRS> GEOCENTRIC_CRS =
+        new AuthorityFactoryProxy<GeocentricCRS>(GeocentricCRS.class) {
+            @Override GeocentricCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createGeocentricCRS(code);
+            }
+            @Override GeocentricCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createGeocentricCRS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<ImageCRS> IMAGE_CRS =
+        new AuthorityFactoryProxy<ImageCRS>(ImageCRS.class) {
+            @Override ImageCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createImageCRS(code);
+            }
+            @Override ImageCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createImageCRS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<ProjectedCRS> PROJECTED_CRS =
+        new AuthorityFactoryProxy<ProjectedCRS>(ProjectedCRS.class) {
+            @Override ProjectedCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createProjectedCRS(code);
+            }
+            @Override ProjectedCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createProjectedCRS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<TemporalCRS> TEMPORAL_CRS =
+        new AuthorityFactoryProxy<TemporalCRS>(TemporalCRS.class) {
+            @Override TemporalCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createTemporalCRS(code);
+            }
+            @Override TemporalCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createTemporalCRS(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<VerticalCRS> VERTICAL_CRS =
+        new AuthorityFactoryProxy<VerticalCRS>(VerticalCRS.class) {
+            @Override VerticalCRS create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createVerticalCRS(code);
+            }
+            @Override VerticalCRS createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return crsFactory(factory).createVerticalCRS(code);
+            }
+    };
+
+    @SuppressWarnings("rawtypes")
+    static final AuthorityFactoryProxy<ParameterDescriptor> PARAMETER =
+        new AuthorityFactoryProxy<ParameterDescriptor>(ParameterDescriptor.class) {
+            @Override ParameterDescriptor<?> create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createParameterDescriptor(code);
+            }
+            @Override ParameterDescriptor createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return geodeticFactory(factory).createParameterDescriptor(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<OperationMethod> METHOD =
+        new AuthorityFactoryProxy<OperationMethod>(OperationMethod.class) {
+            @Override OperationMethod create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createOperationMethod(code);
+            }
+            @Override OperationMethod createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return opFactory(factory).createOperationMethod(code);
+            }
+    };
+
+    static final AuthorityFactoryProxy<CoordinateOperation> OPERATION =
+        new AuthorityFactoryProxy<CoordinateOperation>(CoordinateOperation.class) {
+            @Override CoordinateOperation create(GeodeticAuthorityFactory factory, String code) throws FactoryException {
+                return factory.createCoordinateOperation(code);
+            }
+            @Override CoordinateOperation createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
+                return opFactory(factory).createCoordinateOperation(code);
+            }
+    };
+
+    /**
+     * Returns the instance for the given type. The {@code type} argument can be a GeoAPI interface
+     * or some implementation class like {@link org.apache.sis.referencing.crs.DefaultProjectedCRS}.
+     * This method returns the most specific proxy for the given type.
+     *
+     * @param  type The GeoAPI or implementation class.
+     * @return The most specific proxy for the given {@code type}.
+     * @throws IllegalArgumentException if the type does not implement a valid interface.
+     */
+    @SuppressWarnings("unchecked")
+    static <T> AuthorityFactoryProxy<? super T> getInstance(final Class<T> type)
+            throws IllegalArgumentException
+    {
+        for (final AuthorityFactoryProxy<?> proxy : PROXIES) {
+            if (proxy.type.isAssignableFrom(type)) {
+                return (AuthorityFactoryProxy<? super T>) proxy;
+            }
+        }
+        throw new IllegalArgumentException(Errors.format(
+                Errors.Keys.IllegalClass_2, IdentifiedObject.class, type));
+    }
+
+    /**
+     * The types of proxies. The most specific types must appear first in this list.
+     * This field must be declared after all the above constants.
+     */
+    static final AuthorityFactoryProxy<?>[] PROXIES = new AuthorityFactoryProxy<?>[] {
+        OPERATION,
+        METHOD,
+        PARAMETER,
+        PROJECTED_CRS,
+        GEOGRAPHIC_CRS,
+        GEOCENTRIC_CRS,
+        IMAGE_CRS,
+        DERIVED_CRS,
+        VERTICAL_CRS,
+        TEMPORAL_CRS,
+        ENGINEERING_CRS,
+        COMPOUND_CRS,
+        CRS,
+        AXIS,
+        CARTESIAN_CS,
+        ELLIPSOIDAL_CS,
+        SPHERICAL_CS,
+        CYLINDRICAL_CS,
+        POLAR_CS,
+        VERTICAL_CS,
+        TIME_CS,
+        COORDINATE_SYSTEM,
+        PRIME_MERIDIAN,
+        ELLIPSOID,
+        GEODETIC_DATUM,
+        IMAGE_DATUM,
+        VERTICAL_DATUM,
+        TEMPORAL_DATUM,
+        ENGINEERING_DATUM,
+        DATUM,
+        EXTENT,
+        UNIT,
+        OBJECT
+    };
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java?rev=1718286&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java (added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java [UTF-8] Mon Dec  7 10:06:31 2015
@@ -0,0 +1,767 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.factory;
+
+import java.util.Set;
+import java.util.Collections;
+import javax.measure.unit.Unit;
+import org.opengis.referencing.*;
+import org.opengis.referencing.cs.*;
+import org.opengis.referencing.crs.*;
+import org.opengis.referencing.datum.*;
+import org.opengis.referencing.operation.*;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.util.ScopedName;
+import org.opengis.util.GenericName;
+import org.opengis.util.NameFactory;
+import org.opengis.util.FactoryException;
+import org.opengis.util.InternationalString;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.referencing.AbstractIdentifiedObject;
+import org.apache.sis.util.iso.AbstractFactory;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.ArgumentChecks;
+
+
+/**
+ * Creates geodetic objects from codes defined by an authority.
+ * An <cite>authority</cite> is an organization that maintains definitions of authority codes.
+ * An <cite>authority code</cite> is a compact string defined by an authority to reference a particular
+ * spatial reference object. For example the <a href="http://www.epsg.org">EPSG geodetic dataset</a> maintains
+ * a database of coordinate systems, and other spatial referencing objects, where each object has a code number ID.
+ * For example, the EPSG code for a WGS84 Lat/Lon coordinate system is {@code "4326"}.
+ *
+ * <p>This class defines a default implementation for most methods defined in the {@link DatumAuthorityFactory},
+ * {@link CSAuthorityFactory} and {@link CRSAuthorityFactory} interfaces. However, those interfaces do not appear
+ * in the {@code implements} clause of this class declaration. This is up to subclasses to decide which interfaces
+ * they declare to implement.</p>
+ *
+ * <p>The default implementation for all {@code createFoo(String)} methods ultimately invokes
+ * {@link #createObject(String)}, which may be the only method that a subclass need to override.
+ * However, other methods may be overridden as well for better performances.</p>
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+public abstract class GeodeticAuthorityFactory extends AbstractFactory implements AuthorityFactory {
+    /**
+     * The factory to use for creating {@link GenericName} instances.
+     */
+    protected final NameFactory nameFactory;
+
+    /**
+     * Creates a new authority factory for geodetic objects.
+     *
+     * @param nameFactory The factory to use for creating {@link GenericName} instances.
+     */
+    protected GeodeticAuthorityFactory(final NameFactory nameFactory) {
+        ArgumentChecks.ensureNonNull("nameFactory", nameFactory);
+        this.nameFactory = nameFactory;
+    }
+
+    /**
+     * Returns the organization or party responsible for definition and maintenance of the database.
+     *
+     * @return The organization responsible for definition of the database.
+     */
+    @Override
+    public abstract Citation getAuthority();
+
+    /**
+     * Returns a description of the underlying backing store, or {@code null} if unknown.
+     * This is for example the database software used for storing the data.
+     *
+     * <p>The default implementation returns always {@code null}.</p>
+     *
+     * @return A description of the underlying backing store, or {@code null} if none.
+     * @throws FactoryException if a failure occurs while fetching the backing store description.
+     */
+    public InternationalString getBackingStoreDescription() throws FactoryException {
+        return null;
+    }
+
+    /**
+     * Returns an arbitrary object from a code. The returned object will typically be an instance of {@link Datum},
+     * {@link CoordinateSystem}, {@link CoordinateReferenceSystem} or {@link CoordinateOperation}.
+     *
+     * <p>In default {@code GeodeticAuthorityFactory} implementation, all {@code createFoo(String)} methods
+     * ultimately delegate to this {@code createObject(String)} method. However subclasses are encouraged
+     * to override more specific methods for efficiency.</p>
+     *
+     * <p>The default implementation always throw an exception. Subclasses should override this method
+     * if they are capable to automatically detect the object type from its code.</p>
+     *
+     * @param  code Value allocated by authority.
+     * @return The object for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createCoordinateReferenceSystem(String)
+     * @see #createDatum(String)
+     * @see #createCoordinateSystem(String)
+     */
+    @Override
+    public IdentifiedObject createObject(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        ArgumentChecks.ensureNonNull("code", code);
+        throw noSuchAuthorityCode(IdentifiedObject.class, code);
+    }
+
+    /**
+     * Creates an arbitrary coordinate reference system from a code.
+     * If the coordinate reference system type is known at compile time,
+     * it is recommended to invoke the most precise method instead of this one (for example
+     * {@link #createGeographicCRS createGeographicCRS(String)} instead of
+     * <code>createCoordinateReferenceSystem(code)</code> if the caller know he is asking for a
+     * {@linkplain org.apache.sis.referencing.crs.DefaultGeographicCRS geographic coordinate reference system}).
+     *
+     * <p>The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.</p>
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createGeographicCRS(String)
+     * @see #createProjectedCRS(String)
+     * @see #createVerticalCRS(String)
+     * @see #createTemporalCRS(String)
+     */
+    public CoordinateReferenceSystem createCoordinateReferenceSystem(final String code)
+            throws NoSuchAuthorityCodeException, FactoryException
+    {
+        return cast(CoordinateReferenceSystem.class, createObject(code), code);
+    }
+
+    /**
+     * Creates a geographic coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createGeodeticDatum(String)
+     * @see #createEllipsoidalCS(String)
+     */
+    public GeographicCRS createGeographicCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(GeographicCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Creates a geocentric coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed.
+     *
+     * @see #createGeodeticDatum(String)
+     * @see #createCartesianCS(String)
+     * @see #createSphericalCS(String)
+     */
+    public GeocentricCRS createGeocentricCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(GeocentricCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Creates a projected coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createGeographicCRS(String)
+     * @see #createCartesianCS(String)
+     */
+    public ProjectedCRS createProjectedCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(ProjectedCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Creates a vertical coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createVerticalDatum(String)
+     * @see #createVerticalCS(String)
+     */
+    public VerticalCRS createVerticalCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(VerticalCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Creates a temporal coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createTemporalDatum(String)
+     * @see #createTimeCS(String)
+     */
+    public TemporalCRS createTemporalCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(TemporalCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Creates a 3D or 4D coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createVerticalCRS(String)
+     * @see #createTemporalCRS(String)
+     */
+    public CompoundCRS createCompoundCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(CompoundCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Creates a derived coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     */
+    public DerivedCRS createDerivedCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(DerivedCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Creates an engineering coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createEngineeringDatum(String)
+     */
+    public EngineeringCRS createEngineeringCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(EngineeringCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Creates an image coordinate reference system from a code.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate reference system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createImageDatum(String)
+     */
+    public ImageCRS createImageCRS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(ImageCRS.class, createCoordinateReferenceSystem(code), code);
+    }
+
+    /**
+     * Returns an arbitrary datum from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The datum for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createGeodeticDatum(String)
+     * @see #createVerticalDatum(String)
+     * @see #createTemporalDatum(String)
+     */
+    public Datum createDatum(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(Datum.class, createObject(code), code);
+    }
+
+    /**
+     * Creates a geodetic datum from a code.
+     * The default implementation delegates to {@link #createDatum(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The datum for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createEllipsoid(String)
+     * @see #createPrimeMeridian(String)
+     * @see #createGeographicCRS(String)
+     * @see #createGeocentricCRS(String)
+     */
+    public GeodeticDatum createGeodeticDatum(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(GeodeticDatum.class, createDatum(code), code);
+    }
+
+    /**
+     * Creates a vertical datum from a code.
+     * The default implementation delegates to {@link #createDatum(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The datum for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createVerticalCRS(String)
+     */
+    public VerticalDatum createVerticalDatum(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(VerticalDatum.class, createDatum(code), code);
+    }
+
+    /**
+     * Creates a temporal datum from a code.
+     * The default implementation delegates to {@link #createDatum(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The datum for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createTemporalCRS(String)
+     */
+    public TemporalDatum createTemporalDatum(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(TemporalDatum.class, createDatum(code), code);
+    }
+
+    /**
+     * Creates a engineering datum from a code.
+     * The default implementation delegates to {@link #createDatum(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The datum for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createEngineeringCRS(String)
+     */
+    public EngineeringDatum createEngineeringDatum(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(EngineeringDatum.class, createDatum(code), code);
+    }
+
+    /**
+     * Creates a image datum from a code.
+     * The default implementation delegates to {@link #createDatum(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The datum for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createImageCRS(String)
+     */
+    public ImageDatum createImageDatum(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(ImageDatum.class, createDatum(code), code);
+    }
+
+    /**
+     * Creates an ellipsoid from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The ellipsoid for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createGeodeticDatum(String)
+     * @see #createEllipsoidalCS(String)
+     */
+    public Ellipsoid createEllipsoid(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(Ellipsoid.class, createObject(code), code);
+    }
+
+    /**
+     * Creates a prime meridian from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The prime meridian for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createGeodeticDatum(String)
+     */
+    public PrimeMeridian createPrimeMeridian(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(PrimeMeridian.class, createObject(code), code);
+    }
+
+    /**
+     * Creates an extent (usually an domain of validity) from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The extent for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createCoordinateReferenceSystem(String)
+     * @see #createDatum(String)
+     */
+    public Extent createExtent(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(Extent.class, createObject(code), code);
+    }
+
+    /**
+     * Creates an arbitrary coordinate system from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createCoordinateSystemAxis(String)
+     * @see #createEllipsoidalCS(String)
+     * @see #createCartesianCS(String)
+     */
+    public CoordinateSystem createCoordinateSystem(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(CoordinateSystem.class, createObject(code), code);
+    }
+
+    /**
+     * Creates an ellipsoidal coordinate system from a code.
+     * The default implementation delegates to {@link #createCoordinateSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createEllipsoid(String)
+     * @see #createGeodeticDatum(String)
+     * @see #createGeographicCRS(String)
+     */
+    public EllipsoidalCS createEllipsoidalCS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(EllipsoidalCS.class, createCoordinateSystem(code), code);
+    }
+
+    /**
+     * Creates a vertical coordinate system from a code.
+     * The default implementation delegates to {@link #createCoordinateSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createVerticalDatum(String)
+     * @see #createVerticalCRS(String)
+     */
+    public VerticalCS createVerticalCS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(VerticalCS.class, createCoordinateSystem(code), code);
+    }
+
+    /**
+     * Creates a temporal coordinate system from a code.
+     * The default implementation delegates to {@link #createCoordinateSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createTemporalDatum(String)
+     * @see #createTemporalCRS(String)
+     */
+    public TimeCS createTimeCS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(TimeCS.class, createCoordinateSystem(code), code);
+    }
+
+    /**
+     * Creates a Cartesian coordinate system from a code.
+     * The default implementation delegates to {@link #createCoordinateSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createProjectedCRS(String)
+     * @see #createGeocentricCRS(String)
+     */
+    public CartesianCS createCartesianCS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(CartesianCS.class, createCoordinateSystem(code), code);
+    }
+
+    /**
+     * Creates a spherical coordinate system from a code.
+     * The default implementation delegates to {@link #createCoordinateSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createGeocentricCRS(String)
+     */
+    public SphericalCS createSphericalCS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(SphericalCS.class, createCoordinateSystem(code), code);
+    }
+
+    /**
+     * Creates a cylindrical coordinate system from a code.
+     * The default implementation delegates to {@link #createCoordinateSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     */
+    public CylindricalCS createCylindricalCS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(CylindricalCS.class, createCoordinateSystem(code), code);
+    }
+
+    /**
+     * Creates a polar coordinate system from a code.
+     * The default implementation delegates to {@link #createCoordinateSystem(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The coordinate system for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     */
+    public PolarCS createPolarCS(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(PolarCS.class, createCoordinateSystem(code), code);
+    }
+
+    /**
+     * Creates a coordinate system axis from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The axis for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     *
+     * @see #createCoordinateSystem(String)
+     */
+    public CoordinateSystemAxis createCoordinateSystemAxis(final String code)
+            throws NoSuchAuthorityCodeException, FactoryException
+    {
+        return cast(CoordinateSystemAxis.class, createObject(code), code);
+    }
+
+    /**
+     * Creates an unit of measurement from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The unit of measurement for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     */
+    public Unit<?> createUnit(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(Unit.class, createObject(code), code);
+    }
+
+    /**
+     * Creates a parameter descriptor from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The parameter descriptor for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     */
+    public ParameterDescriptor<?> createParameterDescriptor(final String code)
+            throws NoSuchAuthorityCodeException, FactoryException
+    {
+        return cast(ParameterDescriptor.class, createObject(code), code);
+    }
+
+    /**
+     * Creates an operation method from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The operation method for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     */
+    public OperationMethod createOperationMethod(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+        return cast(OperationMethod.class, createObject(code), code);
+    }
+
+    /**
+     * Creates an operation from a code.
+     * The default implementation delegates to {@link #createObject(String)} and casts the result.
+     * If the result can not be casted, then a {@link NoSuchAuthorityCodeException} is thrown.
+     *
+     * @param  code Value allocated by authority.
+     * @return The operation for the given code.
+     * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     */
+    public CoordinateOperation createCoordinateOperation(final String code)
+            throws NoSuchAuthorityCodeException, FactoryException
+    {
+        return cast(CoordinateOperation.class, createObject(code), code);
+    }
+
+    /**
+     * Creates operations from source and target coordinate reference system codes.
+     * This method should only extract the information explicitely declared in a database like EPSG.
+     * This method should not attempt to infer by itself operations that are not explicitely recorded in the database.
+     *
+     * <p>The default implementation returns an empty set.</p>
+     *
+     * @param  sourceCRS  Coded value of source coordinate reference system.
+     * @param  targetCRS  Coded value of target coordinate reference system.
+     * @return The operations from {@code sourceCRS} to {@code targetCRS}.
+     * @throws NoSuchAuthorityCodeException if a specified code was not found.
+     * @throws FactoryException if the object creation failed for some other reason.
+     */
+    public Set<CoordinateOperation> createFromCoordinateReferenceSystemCodes(String sourceCRS, String targetCRS)
+            throws NoSuchAuthorityCodeException, FactoryException
+    {
+        return Collections.emptySet();
+    }
+
+    /**
+     * Returns a finder which can be used for looking up unidentified objects.
+     * The finder tries to fetch a fully {@linkplain AbstractIdentifiedObject identified object}
+     * from an incomplete one, for example from an object without "{@code ID[…]}" or
+     * "{@code AUTHORITY[…]}" element in <cite>Well Known Text</cite>.
+     *
+     * <p>The {@code type} argument is a hint for optimizing the searches.
+     * The specified type should be a GeoAPI interface like {@code GeographicCRS.class},
+     * but this method accepts also implementation classes.
+     * If the type is unknown, one can use {@code IdentifiedObject.class}.
+     * However a more accurate type may help to speed up the search since it reduces the amount
+     * of tables to scan in some implementations (for example the factories backed by EPSG databases).</p>
+     *
+     * @param  type The type of objects to look for.
+     * @return A finder to use for looking up unidentified objects.
+     * @throws FactoryException if the finder can not be created.
+     */
+    public IdentifiedObjectFinder createIdentifiedObjectFinder(Class<? extends IdentifiedObject> type) throws FactoryException {
+        return new IdentifiedObjectFinder(this, type);
+    }
+
+    /**
+     * Trims the authority scope, if presents. For example if this factory is an EPSG authority factory
+     * and the specified code start with the {@code "EPSG:"} prefix, then the prefix is removed.
+     * Otherwise, the string is returned unchanged (except for leading and trailing spaces).
+     *
+     * @param  code The code to trim.
+     * @return The code without the authority scope.
+     */
+    protected String trimAuthority(String code) {
+        /*
+         * IMPLEMENTATION NOTE: This method is overridden in PropertyAuthorityFactory.
+         * If implementation below is modified, it is probably worth to revisit the overridden method as well.
+         */
+        code = code.trim();
+        final GenericName name  = nameFactory.parseGenericName(null, code);
+        if (name instanceof ScopedName) {
+            final GenericName scope = ((ScopedName) name).path();
+            if (Citations.identifierMatches(getAuthority(), scope.toString())) {
+                return name.tip().toString().trim();
+            }
+        }
+        return code;
+    }
+
+    /**
+     * Creates an exception for an unknown authority code.
+     * This convenience method is provided for implementation of {@code createXXX} methods.
+     *
+     * @param  type  The GeoAPI interface that was to be created (e.g. {@code CoordinateReferenceSystem.class}).
+     * @param  code  The unknown authority code.
+     * @return An exception initialized with an error message built from the specified informations.
+     */
+    protected final NoSuchAuthorityCodeException noSuchAuthorityCode(final Class<?> type, final String code) {
+        final InternationalString authority = getAuthority().getTitle();
+        return new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.NoSuchAuthorityCode_3,
+                   authority, type, code), authority.toString(), trimAuthority(code), code);
+    }
+
+    /**
+     * Casts the given object to the given type, or throws an exception if the object can not be casted.
+     * This convenience method is provided for implementation of {@code createXXX} methods.
+     *
+     * @param  type   The type to return (e.g. {@code CoordinateReferenceSystem.class}).
+     * @param  object The object to cast.
+     * @param  code   The authority code, used only for formatting an error message.
+     * @return The object casted to the given type.
+     * @throws NoSuchAuthorityCodeException if the given object is not an instance of the given type.
+     */
+    @SuppressWarnings("unchecked")
+    private <B, T extends B> T cast(final Class<T> type, final B object, final String code)
+            throws NoSuchAuthorityCodeException
+    {
+        if (type.isInstance(object)) {
+            return (T) object;
+        }
+        final Class<?> actual;
+        if (object instanceof AbstractIdentifiedObject) {
+            actual = ((AbstractIdentifiedObject) object).getInterface();
+        } else {
+            actual = object.getClass();
+        }
+        throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.UnexpectedTypeForReference_3,
+                code, type, actual), getAuthority().getTitle().toString(), trimAuthority(code), code);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

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



Mime
View raw message