]> git.argeo.org Git - gpl/argeo-jcr.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/transfer/MetadataTransferException.java
Move Argeo SLC JCR components to Argeo JCR
[gpl/argeo-jcr.git] / org.argeo.slc.repo / src / org / eclipse / aether / transfer / MetadataTransferException.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 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.metadata.Metadata;
15 import org.eclipse.aether.repository.RemoteRepository;
16
17 /**
18 * Thrown when metadata could not be uploaded/downloaded to/from a particular remote repository.
19 */
20 public class MetadataTransferException
21 extends RepositoryException
22 {
23
24 private final transient Metadata metadata;
25
26 private final transient RemoteRepository repository;
27
28 private final boolean fromCache;
29
30 static String getString( String prefix, RemoteRepository repository )
31 {
32 if ( repository == null )
33 {
34 return "";
35 }
36 else
37 {
38 return prefix + repository.getId() + " (" + repository.getUrl() + ")";
39 }
40 }
41
42 /**
43 * Creates a new exception with the specified metadata, repository and detail message.
44 *
45 * @param metadata The untransferable metadata, may be {@code null}.
46 * @param repository The involved remote repository, may be {@code null}.
47 * @param message The detail message, may be {@code null}.
48 */
49 public MetadataTransferException( Metadata metadata, RemoteRepository repository, String message )
50 {
51 this( metadata, repository, message, false );
52 }
53
54 /**
55 * Creates a new exception with the specified metadata, repository and detail message.
56 *
57 * @param metadata The untransferable metadata, may be {@code null}.
58 * @param repository The involved remote repository, may be {@code null}.
59 * @param message The detail message, may be {@code null}.
60 * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the
61 * exception actually just occurred.
62 */
63 public MetadataTransferException( Metadata metadata, RemoteRepository repository, String message, boolean fromCache )
64 {
65 super( message );
66 this.metadata = metadata;
67 this.repository = repository;
68 this.fromCache = fromCache;
69 }
70
71 /**
72 * Creates a new exception with the specified metadata, repository and cause.
73 *
74 * @param metadata The untransferable metadata, may be {@code null}.
75 * @param repository The involved remote repository, may be {@code null}.
76 * @param cause The exception that caused this one, may be {@code null}.
77 */
78 public MetadataTransferException( Metadata metadata, RemoteRepository repository, Throwable cause )
79 {
80 this( metadata, repository, "Could not transfer metadata " + metadata + getString( " from/to ", repository )
81 + getMessage( ": ", cause ), cause );
82 }
83
84 /**
85 * Creates a new exception with the specified metadata, repository, detail message and cause.
86 *
87 * @param metadata The untransferable metadata, may be {@code null}.
88 * @param repository The involved remote repository, may be {@code null}.
89 * @param message The detail message, may be {@code null}.
90 * @param cause The exception that caused this one, may be {@code null}.
91 */
92 public MetadataTransferException( Metadata metadata, RemoteRepository repository, String message, Throwable cause )
93 {
94 super( message, cause );
95 this.metadata = metadata;
96 this.repository = repository;
97 this.fromCache = false;
98 }
99
100 /**
101 * Gets the metadata that could not be transferred.
102 *
103 * @return The troublesome metadata or {@code null} if unknown.
104 */
105 public Metadata getMetadata()
106 {
107 return metadata;
108 }
109
110 /**
111 * Gets the remote repository involved in the transfer.
112 *
113 * @return The involved remote repository or {@code null} if unknown.
114 */
115 public RemoteRepository getRepository()
116 {
117 return repository;
118 }
119
120 /**
121 * Indicates whether this exception actually just occurred or was played back from the error cache.
122 *
123 * @return {@code true} if the exception was played back from the error cache, {@code false} if the exception
124 * actually occurred just now.
125 */
126 public boolean isFromCache()
127 {
128 return fromCache;
129 }
130
131 }