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 repository layout.
027 */
028public class NoRepositoryLayoutException
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 layout is not supported, may be {@code null}.
038     */
039    public NoRepositoryLayoutException( 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 layout is not supported, may be {@code null}.
048     * @param message The detail message, may be {@code null}.
049     */
050    public NoRepositoryLayoutException( 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 layout is not supported, may be {@code null}.
060     * @param cause The exception that caused this one, may be {@code null}.
061     */
062    public NoRepositoryLayoutException( 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 layout 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 NoRepositoryLayoutException( 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 "Unsupported repository layout " + repository.getContentType();
085        }
086        else
087        {
088            return "Unsupported repository layout";
089        }
090    }
091
092    /**
093     * Gets the remote repository whose layout is not supported.
094     * 
095     * @return The unsupported remote repository or {@code null} if unknown.
096     */
097    public RemoteRepository getRepository()
098    {
099        return repository;
100    }
101
102}