View Javadoc
1   /*******************************************************************************
2    * Copyright (c) 2012, 2014 Sonatype, Inc.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *    Sonatype, Inc. - initial API and implementation
10   *******************************************************************************/
11  package org.eclipse.aether.transfer;
12  
13  import org.eclipse.aether.RepositoryException;
14  import org.eclipse.aether.repository.RemoteRepository;
15  
16  /**
17   * Thrown when a transfer could not be performed because a remote repository is not accessible in offline mode.
18   */
19  public class RepositoryOfflineException
20      extends RepositoryException
21  {
22  
23      private final transient RemoteRepository repository;
24  
25      private static String getMessage( RemoteRepository repository )
26      {
27          if ( repository == null )
28          {
29              return "Cannot access remote repositories in offline mode";
30          }
31          else
32          {
33              return "Cannot access " + repository.getId() + " (" + repository.getUrl() + ") in offline mode";
34          }
35      }
36  
37      /**
38       * Creates a new exception with the specified repository.
39       * 
40       * @param repository The inaccessible remote repository, may be {@code null}.
41       */
42      public RepositoryOfflineException( RemoteRepository repository )
43      {
44          super( getMessage( repository ) );
45          this.repository = repository;
46      }
47  
48      /**
49       * Creates a new exception with the specified repository and detail message.
50       * 
51       * @param repository The inaccessible remote repository, may be {@code null}.
52       * @param message The detail message, may be {@code null}.
53       */
54      public RepositoryOfflineException( RemoteRepository repository, String message )
55      {
56          super( message );
57          this.repository = repository;
58      }
59  
60      /**
61       * Gets the remote repository that could not be accessed due to offline mode.
62       * 
63       * @return The inaccessible remote repository or {@code null} if unknown.
64       */
65      public RemoteRepository getRepository()
66      {
67          return repository;
68      }
69  
70  }