001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  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,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.transfer;
020
021import org.eclipse.aether.RepositoryException;
022import org.eclipse.aether.repository.RemoteRepository;
023
024/**
025 * Thrown in case of an unsupported remote repository type.
026 */
027public class NoRepositoryConnectorException extends RepositoryException {
028
029    private final transient RemoteRepository repository;
030
031    /**
032     * Creates a new exception with the specified repository.
033     *
034     * @param repository The remote repository whose content type is not supported, may be {@code null}.
035     */
036    public NoRepositoryConnectorException(RemoteRepository repository) {
037        this(repository, toMessage(repository));
038    }
039
040    /**
041     * Creates a new exception with the specified repository and detail message.
042     *
043     * @param repository The remote repository whose content type is not supported, may be {@code null}.
044     * @param message The detail message, may be {@code null}.
045     */
046    public NoRepositoryConnectorException(RemoteRepository repository, String message) {
047        super(message);
048        this.repository = repository;
049    }
050
051    /**
052     * Creates a new exception with the specified repository and cause.
053     *
054     * @param repository The remote repository whose content type is not supported, may be {@code null}.
055     * @param cause The exception that caused this one, may be {@code null}.
056     */
057    public NoRepositoryConnectorException(RemoteRepository repository, Throwable cause) {
058        this(repository, toMessage(repository), cause);
059    }
060
061    /**
062     * Creates a new exception with the specified repository, detail message and cause.
063     *
064     * @param repository The remote repository whose content type is not supported, may be {@code null}.
065     * @param message The detail message, may be {@code null}.
066     * @param cause The exception that caused this one, may be {@code null}.
067     */
068    public NoRepositoryConnectorException(RemoteRepository repository, String message, Throwable cause) {
069        super(message, cause);
070        this.repository = repository;
071    }
072
073    private static String toMessage(RemoteRepository repository) {
074        if (repository != null) {
075            return "No connector available to access repository " + repository.getId() + " (" + repository.getUrl()
076                    + ") of type " + repository.getContentType();
077        } else {
078            return "No connector available to access repository";
079        }
080    }
081
082    /**
083     * Gets the remote repository whose content type is not supported.
084     *
085     * @return The unsupported remote repository or {@code null} if unknown.
086     */
087    public RemoteRepository getRepository() {
088        return repository;
089    }
090}