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