Search in sources :

Example 1 with ReferencingServices

use of org.apache.sis.internal.metadata.ReferencingServices in project sis by apache.

the class DefaultMathTransformFactory method getOperationMethod.

/**
 * Returns the operation method for the specified name or identifier. The given argument shall be either
 * a method {@linkplain DefaultOperationMethod#getName() name} (e.g. <cite>"Transverse Mercator"</cite>)
 * or one of its {@linkplain DefaultOperationMethod#getIdentifiers() identifiers} (e.g. {@code "EPSG:9807"}).
 *
 * <p>The search is case-insensitive. Comparisons against method names can be
 * {@linkplain DefaultOperationMethod#isHeuristicMatchForName(String) heuristic}.</p>
 *
 * <p>If more than one method match the given identifier, then the first (according iteration order)
 * non-{@linkplain org.apache.sis.util.Deprecable#isDeprecated() deprecated} matching method is returned.
 * If all matching methods are deprecated, the first one is returned.</p>
 *
 * @param  identifier  the name or identifier of the operation method to search.
 * @return the coordinate operation method for the given name or identifier.
 * @throws NoSuchIdentifierException if there is no operation method registered for the specified identifier.
 *
 * @see org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory#getOperationMethod(String)
 */
public OperationMethod getOperationMethod(String identifier) throws NoSuchIdentifierException {
    identifier = CharSequences.trimWhitespaces(identifier);
    ArgumentChecks.ensureNonEmpty("identifier", identifier);
    OperationMethod method = methodsByName.get(identifier);
    if (method == null) {
        final ReferencingServices services = ReferencingServices.getInstance();
        synchronized (methods) {
            method = services.getOperationMethod(methods, identifier);
        }
        if (method == null) {
            throw new NoSuchIdentifierException(Resources.format(Resources.Keys.NoSuchOperationMethod_1, identifier), identifier);
        }
        /*
             * Remember the method we just found, for faster check next time.
             */
        final OperationMethod previous = methodsByName.putIfAbsent(identifier.intern(), method);
        if (previous != null) {
            method = previous;
        }
    }
    return method;
}
Also used : ReferencingServices(org.apache.sis.internal.metadata.ReferencingServices) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) DefaultOperationMethod(org.apache.sis.referencing.operation.DefaultOperationMethod) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Aggregations

ReferencingServices (org.apache.sis.internal.metadata.ReferencingServices)1 DefaultOperationMethod (org.apache.sis.referencing.operation.DefaultOperationMethod)1 OperationMethod (org.opengis.referencing.operation.OperationMethod)1 NoSuchIdentifierException (org.opengis.util.NoSuchIdentifierException)1