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 when a transfer could not be performed because a remote repository is not accessible in offline mode.
027 */
028public class RepositoryOfflineException
029    extends RepositoryException
030{
031
032    private final transient RemoteRepository repository;
033
034    private static String getMessage( RemoteRepository repository )
035    {
036        if ( repository == null )
037        {
038            return "Cannot access remote repositories in offline mode";
039        }
040        else
041        {
042            return "Cannot access " + repository.getId() + " (" + repository.getUrl() + ") in offline mode";
043        }
044    }
045
046    /**
047     * Creates a new exception with the specified repository.
048     * 
049     * @param repository The inaccessible remote repository, may be {@code null}.
050     */
051    public RepositoryOfflineException( RemoteRepository repository )
052    {
053        super( getMessage( repository ) );
054        this.repository = repository;
055    }
056
057    /**
058     * Creates a new exception with the specified repository and detail message.
059     * 
060     * @param repository The inaccessible remote repository, may be {@code null}.
061     * @param message The detail message, may be {@code null}.
062     */
063    public RepositoryOfflineException( RemoteRepository repository, String message )
064    {
065        super( message );
066        this.repository = repository;
067    }
068
069    /**
070     * Gets the remote repository that could not be accessed due to offline mode.
071     * 
072     * @return The inaccessible remote repository or {@code null} if unknown.
073     */
074    public RemoteRepository getRepository()
075    {
076        return repository;
077    }
078
079}