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