1 6 package fr.jayasoft.ivy.repository; 7 8 import java.io.File ; 9 10 import fr.jayasoft.ivy.Ivy; 11 import fr.jayasoft.ivy.event.IvyEvent; 12 13 41 public class TransferEvent extends IvyEvent { 42 45 public static final int TRANSFER_INITIATED = 0; 46 47 50 public final static int TRANSFER_STARTED = 1; 51 52 55 public final static int TRANSFER_COMPLETED = 2; 56 57 60 public final static int TRANSFER_PROGRESS = 3; 61 62 65 public final static int TRANSFER_ERROR = 4; 66 67 70 public final static int REQUEST_GET = 5; 71 72 75 public final static int REQUEST_PUT = 6; 76 77 78 public static final String TRANSFER_INITIATED_NAME = "transfer-initiated"; 79 80 public static final String TRANSFER_STARTED_NAME = "transfer-started"; 81 82 public static final String TRANSFER_PROGRESS_NAME = "transfer-progress"; 83 84 public static final String TRANSFER_COMPLETED_NAME = "transfer-completed"; 85 86 public static final String TRANSFER_ERROR_NAME = "transfer-error"; 87 88 private Resource _resource; 89 90 private int _eventType; 91 92 private int _requestType; 93 94 private Exception _exception; 95 96 private File _localFile; 97 98 private Repository _repository; 99 private long _length; 100 101 private long _totalLength; 102 private boolean _isTotalLengthSet = false; 103 104 public TransferEvent(Ivy ivy, final Repository repository, final Resource resource, final int eventType, final int requestType) { 105 super(ivy, getName(eventType)); 106 107 _repository = repository; 108 addAttribute("repository", _repository.getName()); 109 _resource = resource; 110 addAttribute("resource", _resource.getName()); 111 112 setEventType(eventType); 113 114 setRequestType(requestType); 115 addAttribute("request-type", requestType == REQUEST_GET?"get":"put"); 116 } 117 118 public TransferEvent(Ivy ivy, final Repository repository, final Resource resource, final Exception exception, final int requestType) { 119 this(ivy, repository, resource, TRANSFER_ERROR, requestType); 120 121 _exception = exception; 122 } 123 124 public TransferEvent(Ivy ivy, final Repository repository, final Resource resource, long length, final int requestType) { 125 this(ivy, repository, resource, TRANSFER_PROGRESS, requestType); 126 127 _length = length; 128 _totalLength = length; 129 } 130 131 private static String getName(int eventType) { 132 switch (eventType) { 133 case TRANSFER_INITIATED: 134 return TRANSFER_INITIATED_NAME; 135 case TRANSFER_STARTED: 136 return TRANSFER_STARTED_NAME; 137 case TRANSFER_PROGRESS: 138 return TRANSFER_PROGRESS_NAME; 139 case TRANSFER_COMPLETED: 140 return TRANSFER_COMPLETED_NAME; 141 case TRANSFER_ERROR: 142 return TRANSFER_ERROR_NAME; 143 } 144 return null; 145 } 146 147 148 151 public Resource getResource() { 152 return _resource; 153 } 154 155 158 public Exception getException() { 159 return _exception; 160 } 161 162 168 public int getRequestType() { 169 return _requestType; 170 } 171 172 181 protected void setRequestType(final int requestType) { 182 switch (requestType) { 183 184 case REQUEST_PUT: 185 break; 186 case REQUEST_GET: 187 break; 188 189 default: 190 throw new IllegalArgumentException ("Illegal request type: " + requestType); 191 } 192 193 _requestType = requestType; 194 } 195 196 199 public int getEventType() { 200 return _eventType; 201 } 202 203 207 protected void setEventType(final int eventType) { 208 switch (eventType) { 209 210 case TRANSFER_INITIATED: 211 break; 212 case TRANSFER_STARTED: 213 break; 214 case TRANSFER_COMPLETED: 215 break; 216 case TRANSFER_PROGRESS: 217 break; 218 case TRANSFER_ERROR: 219 break; 220 default: 221 throw new IllegalArgumentException ("Illegal event type: " + eventType); 222 } 223 224 this._eventType = eventType; 225 } 226 227 231 protected void setResource(final Resource resource) { 232 _resource = resource; 233 } 234 235 238 public File getLocalFile() { 239 return _localFile; 240 } 241 242 246 protected void setLocalFile(File localFile) { 247 _localFile = localFile; 248 } 249 250 251 public long getLength() { 252 return _length; 253 } 254 255 256 protected void setLength(long length) { 257 _length = length; 258 } 259 260 public long getTotalLength() { 261 return _totalLength; 262 } 263 264 protected void setTotalLength(long totalLength) { 265 _totalLength = totalLength; 266 } 267 268 public void setException(Exception exception) { 269 _exception = exception; 270 } 271 272 public boolean isTotalLengthSet() { 273 return _isTotalLengthSet; 274 } 275 276 public void setTotalLengthSet(boolean isTotalLengthSet) { 277 _isTotalLengthSet = isTotalLengthSet; 278 } 279 280 281 282 } 283 | Popular Tags |