1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository;
20
21 import java.io.File;
22 import java.util.EventObject;
23
24
25
26
27
28
29
30 @Deprecated
31 public class ArtifactTransferEvent extends EventObject {
32
33
34
35 public static final int TRANSFER_INITIATED = 0;
36
37
38
39
40 public static final int TRANSFER_STARTED = 1;
41
42
43
44
45 public static final int TRANSFER_COMPLETED = 2;
46
47
48
49
50 public static final int TRANSFER_PROGRESS = 3;
51
52
53
54
55 public static final int TRANSFER_ERROR = 4;
56
57
58
59
60 public static final int REQUEST_GET = 5;
61
62
63
64
65 public static final int REQUEST_PUT = 6;
66
67 private int eventType;
68
69 private int requestType;
70
71 private Exception exception;
72
73 private File localFile;
74
75 private ArtifactTransferResource artifact;
76
77 private long transferredBytes;
78
79 private byte[] dataBuffer;
80
81 private int dataOffset;
82
83 private int dataLength;
84
85 public ArtifactTransferEvent(
86 String wagon, final int eventType, final int requestType, ArtifactTransferResource artifact) {
87 super(wagon);
88
89 setEventType(eventType);
90
91 setRequestType(requestType);
92
93 this.artifact = artifact;
94 }
95
96 public ArtifactTransferEvent(
97 String wagon, final Exception exception, final int requestType, ArtifactTransferResource artifact) {
98 this(wagon, TRANSFER_ERROR, requestType, artifact);
99
100 this.exception = exception;
101 }
102
103 public ArtifactTransferResource getResource() {
104 return artifact;
105 }
106
107
108
109
110 public Exception getException() {
111 return exception;
112 }
113
114
115
116
117
118
119
120 public int getRequestType() {
121 return requestType;
122 }
123
124
125
126
127
128
129
130
131
132 public void setRequestType(final int requestType) {
133 switch (requestType) {
134 case REQUEST_PUT:
135 break;
136 case REQUEST_GET:
137 break;
138 default:
139 throw new IllegalArgumentException("Illegal request type: " + requestType);
140 }
141
142 this.requestType = requestType;
143 }
144
145
146
147
148 public int getEventType() {
149 return eventType;
150 }
151
152
153
154
155 public void setEventType(final int eventType) {
156 switch (eventType) {
157 case TRANSFER_INITIATED:
158 break;
159 case TRANSFER_STARTED:
160 break;
161 case TRANSFER_COMPLETED:
162 break;
163 case TRANSFER_PROGRESS:
164 break;
165 case TRANSFER_ERROR:
166 break;
167 default:
168 throw new IllegalArgumentException("Illegal event type: " + eventType);
169 }
170
171 this.eventType = eventType;
172 }
173
174
175
176
177 public File getLocalFile() {
178 return localFile;
179 }
180
181
182
183
184 public void setLocalFile(File localFile) {
185 this.localFile = localFile;
186 }
187
188 public long getTransferredBytes() {
189 return transferredBytes;
190 }
191
192 public void setTransferredBytes(long transferredBytes) {
193 this.transferredBytes = transferredBytes;
194 }
195
196 public byte[] getDataBuffer() {
197 return dataBuffer;
198 }
199
200 public void setDataBuffer(byte[] dataBuffer) {
201 this.dataBuffer = dataBuffer;
202 }
203
204 public int getDataOffset() {
205 return dataOffset;
206 }
207
208 public void setDataOffset(int dataOffset) {
209 this.dataOffset = dataOffset;
210 }
211
212 public int getDataLength() {
213 return dataLength;
214 }
215
216 public void setDataLength(int dataLength) {
217 this.dataLength = dataLength;
218 }
219
220 public String toString() {
221 StringBuilder sb = new StringBuilder(64);
222
223 sb.append("TransferEvent[");
224
225 switch (this.getRequestType()) {
226 case REQUEST_GET:
227 sb.append("GET");
228 break;
229 case REQUEST_PUT:
230 sb.append("PUT");
231 break;
232 default:
233 sb.append(this.getRequestType());
234 break;
235 }
236
237 sb.append('|');
238 switch (this.getEventType()) {
239 case TRANSFER_COMPLETED:
240 sb.append("COMPLETED");
241 break;
242 case TRANSFER_ERROR:
243 sb.append("ERROR");
244 break;
245 case TRANSFER_INITIATED:
246 sb.append("INITIATED");
247 break;
248 case TRANSFER_PROGRESS:
249 sb.append("PROGRESS");
250 break;
251 case TRANSFER_STARTED:
252 sb.append("STARTED");
253 break;
254 default:
255 sb.append(this.getEventType());
256 break;
257 }
258
259 sb.append('|');
260 sb.append(this.getLocalFile()).append('|');
261 sb.append(']');
262
263 return sb.toString();
264 }
265
266 public int hashCode() {
267 final int prime = 31;
268 int result = 1;
269 result = prime * result + eventType;
270 result = prime * result + ((exception == null) ? 0 : exception.hashCode());
271 result = prime * result + ((localFile == null) ? 0 : localFile.hashCode());
272 result = prime * result + requestType;
273 return result;
274 }
275
276 public boolean equals(Object obj) {
277 if (this == obj) {
278 return true;
279 }
280 if ((obj == null) || (getClass() != obj.getClass())) {
281 return false;
282 }
283 final ArtifactTransferEvent other = (ArtifactTransferEvent) obj;
284 if (eventType != other.eventType) {
285 return false;
286 }
287 if (exception == null) {
288 if (other.exception != null) {
289 return false;
290 }
291 } else if (!exception.getClass().equals(other.exception.getClass())) {
292 return false;
293 }
294 if (requestType != other.requestType) {
295 return false;
296 } else {
297 return source.equals(other.source);
298 }
299 }
300 }