View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.transfer;
20  
21  import org.eclipse.aether.RepositoryException;
22  import org.eclipse.aether.repository.RemoteRepository;
23  
24  /**
25   * Thrown in case of an unsupported transport protocol.
26   */
27  public class NoTransporterException extends RepositoryException {
28  
29      private final transient RemoteRepository repository;
30  
31      /**
32       * Creates a new exception with the specified repository.
33       *
34       * @param repository The remote repository whose transport layout is not supported, may be {@code null}.
35       */
36      public NoTransporterException(RemoteRepository repository) {
37          this(repository, toMessage(repository));
38      }
39  
40      /**
41       * Creates a new exception with the specified repository and detail message.
42       *
43       * @param repository The remote repository whose transport layout is not supported, may be {@code null}.
44       * @param message The detail message, may be {@code null}.
45       */
46      public NoTransporterException(RemoteRepository repository, String message) {
47          super(message);
48          this.repository = repository;
49      }
50  
51      /**
52       * Creates a new exception with the specified repository and cause.
53       *
54       * @param repository The remote repository whose transport layout is not supported, may be {@code null}.
55       * @param cause The exception that caused this one, may be {@code null}.
56       */
57      public NoTransporterException(RemoteRepository repository, Throwable cause) {
58          this(repository, toMessage(repository), cause);
59      }
60  
61      /**
62       * Creates a new exception with the specified repository, detail message and cause.
63       *
64       * @param repository The remote repository whose transport layout is not supported, may be {@code null}.
65       * @param message The detail message, may be {@code null}.
66       * @param cause The exception that caused this one, may be {@code null}.
67       */
68      public NoTransporterException(RemoteRepository repository, String message, Throwable cause) {
69          super(message, cause);
70          this.repository = repository;
71      }
72  
73      private static String toMessage(RemoteRepository repository) {
74          if (repository != null) {
75              return "Unsupported transport protocol " + repository.getProtocol();
76          } else {
77              return "Unsupported transport protocol";
78          }
79      }
80  
81      /**
82       * Gets the remote repository whose transport protocol is not supported.
83       *
84       * @return The unsupported remote repository or {@code null} if unknown.
85       */
86      public RemoteRepository getRepository() {
87          return repository;
88      }
89  }