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.referencing;
019
020import org.opengis.util.NoSuchIdentifierException;
021
022
023/**
024 * Thrown when an {@linkplain AuthorityFactory authority factory} cannot find the requested authority code.
025 * This is a specialization of {@link NoSuchIdentifierException} with the identifier separated in its authority
026 * and code components.
027 *
028 * @author  Martin Desruisseaux (IRD, Geomatys)
029 * @version 3.1
030 * @since   1.0
031 *
032 * @see org.opengis.referencing.crs.CRSAuthorityFactory
033 * @see org.opengis.referencing.cs.CSAuthorityFactory
034 * @see org.opengis.referencing.datum.DatumAuthorityFactory
035 */
036public class NoSuchAuthorityCodeException extends NoSuchIdentifierException {
037    /**
038     * Serial number for inter-operability with different versions.
039     */
040    private static final long serialVersionUID = -1573748311981746573L;
041
042    /**
043     * The authority, or {@code null} if unknown.
044     *
045     * @see #getAuthority()
046     */
047    private final String authority;
048
049    /**
050     * The invalid authority code, or {@code null} if unknown.
051     *
052     * @see #getAuthorityCode()
053     */
054    private final String code;
055
056    /**
057     * Constructs an exception with the specified detail message and authority code.
058     * All arguments accept the {@code null} value.
059     *
060     * @param  message    the detail message, saved for later retrieval by the {@link #getMessage()} method.
061     * @param  authority  the authority, saved for retrieval by the {@link #getAuthority()} method.
062     * @param  code       the invalid authority code, saved for retrieval by the {@link #getAuthorityCode()} method.
063     */
064    public NoSuchAuthorityCodeException(final String message, final String authority, final String code) {
065        this(message, authority, code, (authority == null) ? code : (code == null) ? authority : authority + ':' + code);
066    }
067
068    /**
069     * Constructs an exception with the specified detail message, authority, code and identifier.
070     * The identifier argument is optional. If omitted, then "{@code authority:code}" will be used.
071     * All arguments accept the {@code null} value.
072     *
073     * @param  message     the detail message, saved for later retrieval by the {@link #getMessage()} method.
074     * @param  authority   the authority, saved for retrieval by the {@link #getAuthority()} method.
075     * @param  code        the invalid authority code, saved for retrieval by the {@link #getAuthorityCode()} method.
076     * @param  identifier  the full identifier as a concatenation of the authority and the code,
077     *                     saved for retrieval by the {@link #getIdentifierCode()} method.
078     */
079    public NoSuchAuthorityCodeException(final String message, final String authority, final String code, final String identifier) {
080        super(message, identifier);
081        this.authority = authority;
082        this.code = code;
083    }
084
085    /**
086     * Constructs an exception with the specified detail message, authority, code, identifier and error cause.
087     * All arguments accept the {@code null} value.
088     *
089     * @param message     the detail message, saved for later retrieval by the {@link #getMessage()} method.
090     * @param authority   the authority, saved for retrieval by the {@link #getAuthority()} method.
091     * @param code        the invalid authority code, saved for retrieval by the {@link #getAuthorityCode()} method.
092     * @param identifier  the full identifier as a concatenation of the authority and the code,
093     *                    saved for retrieval by the {@link #getIdentifierCode()} method.
094     * @param cause       the cause, saved for later retrieval by the {@link #getCause()} method.
095     *
096     * @since 3.1
097     */
098    public NoSuchAuthorityCodeException(final String message, final String authority, final String code,
099                                        final String identifier, final Throwable cause)
100    {
101        super(message, identifier, cause);
102        this.authority = authority;
103        this.code = code;
104    }
105
106    /**
107     * Returns the authority.
108     *
109     * @return the authority, or {@code null} if unknown.
110     */
111    public String getAuthority() {
112        return authority;
113    }
114
115    /**
116     * Returns the invalid authority code.
117     *
118     * @return the authority code, or {@code null} if unknown.
119     */
120    public String getAuthorityCode() {
121        return code;
122    }
123}