001/*
002 *    GeoAPI - Java interfaces for OGC/ISO standards
003 *    Copyright © 2004-2023 Open Geospatial Consortium, Inc.
004 *    http://www.geoapi.org
005 *
006 *    Licensed under the Apache License, Version 2.0 (the "License");
007 *    you may not use this file except in compliance with the License.
008 *    You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *    Unless required by applicable law or agreed to in writing, software
013 *    distributed under the License is distributed on an "AS IS" BASIS,
014 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 *    See the License for the specific language governing permissions and
016 *    limitations under the License.
017 */
018package org.opengis.util;
019
020import org.opengis.metadata.Identifier;
021import org.opengis.parameter.ParameterValueGroup;  // For javadoc
022
023
024/**
025 * Thrown when an identifier provided to a factory method cannot be found.
026 * The identifier may be provided by {@link org.opengis.referencing.IdentifiedObject#getName()}.
027 * In the common case where the identifier is an "authority:code" pair,
028 * the {@link org.opengis.referencing.NoSuchAuthorityCodeException} specialization should be used.
029 *
030 * <p><b>Example:</b> This exception is thrown when a
031 * {@linkplain org.opengis.referencing.operation.MathTransform math transform} has been requested
032 * with an unknown {@linkplain org.opengis.referencing.operation.OperationMethod operation method}
033 * name.</p>
034 *
035 * @author  Martin Desruisseaux (IRD)
036 * @version 3.1
037 * @since   1.0
038 *
039 * @see org.opengis.referencing.operation.MathTransformFactory#createParameterizedTransform(ParameterValueGroup)
040 */
041public class NoSuchIdentifierException extends FactoryException {
042    /**
043     * Serial number for inter-operability with different versions.
044     */
045    private static final long serialVersionUID = -6846799994429345902L;
046
047    /**
048     * The identifier code.
049     */
050    private final String identifier;
051
052    /**
053     * Constructs an exception with the specified detail message and identifier.
054     *
055     * @param message     the detail message, saved for later retrieval by the {@link #getMessage()} method.
056     * @param identifier  the {@linkplain Identifier#getCode() identifier code} which was not found.
057     */
058    public NoSuchIdentifierException(final String message, final String identifier) {
059        super(message);
060        this.identifier = identifier;
061    }
062
063    /**
064     * Constructs an exception with the specified detail message, identifier and cause.
065     *
066     * @param message     the detail message, saved for later retrieval by the {@link #getMessage()} method.
067     * @param identifier  the {@linkplain Identifier#getCode() identifier code} which was not found.
068     * @param cause       the cause, saved for later retrieval by the {@link #getCause()} method.
069     *
070     * @since 3.1
071     */
072    public NoSuchIdentifierException(final String message, final String identifier, final Throwable cause) {
073        super(message, cause);
074        this.identifier = identifier;
075    }
076
077    /**
078     * Returns the {@linkplain Identifier#getCode identifier code}.
079     *
080     * @return the identifier code.
081     */
082    public String getIdentifierCode() {
083        return identifier;
084    }
085}