1 20 21 package org.jdesktop.jdic.filetypes; 22 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import org.jdesktop.jdic.filetypes.internal.AppUtility; 28 29 30 45 public class Association { 46 47 51 private String name; 52 53 56 private String description; 57 58 61 private String mimeType; 62 63 70 private List fileExtensionList; 71 72 75 private String iconFileName; 76 77 80 private List actionList; 81 82 85 private int hashcode; 86 87 102 public String getName() { 103 return name; 104 } 105 106 112 public void setName(String name) { 113 if (name == null) { 114 throw new IllegalArgumentException ("The given MIME file name is null."); 115 } 116 117 this.name = name; 118 } 119 120 125 public String getDescription() { 126 return description; 127 } 128 129 134 public void setDescription(String description) { 135 if (description == null) { 136 throw new IllegalArgumentException ("The given description is null."); 137 } 138 139 this.description = description; 140 } 141 142 147 public String getMimeType() { 148 return mimeType; 149 } 150 151 156 public void setMimeType(String mimeType) { 157 if (mimeType == null) { 158 throw new IllegalArgumentException ("The given MIME type is null."); 159 } 160 161 this.mimeType = mimeType; 162 } 163 164 178 public boolean addFileExtension(String fileExt) { 179 if (fileExt == null) { 180 throw new IllegalArgumentException ("The given file extension is null."); 181 } 182 183 fileExt = AppUtility.addDotToFileExtension(fileExt); 185 186 if (fileExtensionList == null) { 187 fileExtensionList = new ArrayList (); 188 } 189 190 return fileExtensionList.add(fileExt); 191 } 192 193 204 public boolean removeFileExtension(String fileExt) { 205 if (fileExt == null) { 206 throw new IllegalArgumentException ("The given file extension is null."); 207 } 208 209 fileExt = AppUtility.addDotToFileExtension(fileExt); 211 if (fileExtensionList != null) { 212 return fileExtensionList.remove(fileExt); 213 } 214 215 return false; 216 } 217 218 223 public List getFileExtList() { 224 if (fileExtensionList == null) { 226 return null; 227 } else { 228 List retList = new ArrayList (); 229 230 Iterator iter = fileExtensionList.iterator(); 231 while (iter.hasNext()) { 232 retList.add(iter.next()); 233 } 234 235 return retList; 236 } 237 } 238 239 244 public String getIconFileName() { 245 return iconFileName; 246 } 247 248 256 public void setIconFileName(String fileName) { 257 if (fileName == null) { 258 throw new IllegalArgumentException ("The given icon file name is null."); 259 } 260 261 this.iconFileName = fileName; 262 } 263 264 278 public boolean addAction(Action action) { 279 if (action == null) { 280 throw new IllegalArgumentException ("The given action is null."); 281 } 282 283 if (action.getVerb() == null) { 285 throw new IllegalArgumentException ("the given action object has null verb field."); 286 } else if (action.getCommand() == null) { 287 throw new IllegalArgumentException ("the given action object has null command field."); 288 } 289 290 if (actionList == null) { 291 actionList = new ArrayList (); 292 } 293 294 return actionList.add(new Action(action.getVerb(), action.getCommand(), 295 action.getDescription())); 296 } 297 298 309 public boolean removeAction(Action action) { 310 if (action == null) { 311 throw new IllegalArgumentException ("The given action is null."); 312 } 313 314 if ((action.getVerb() == null) || (action.getCommand() == null)) { 316 throw new IllegalArgumentException ("the given action object has null verb field or command field."); 317 } 318 if (actionList != null) { 319 return actionList.remove(action); 320 } 321 322 return false; 323 } 324 325 330 public List getActionList() { 331 if (actionList == null) { 333 return null; 334 } else { 335 List retList = new ArrayList (); 336 337 Iterator iter = actionList.iterator(); 338 while (iter.hasNext()) { 339 retList.add(iter.next()); 340 } 341 342 return retList; 343 } 344 } 345 346 354 public Action getActionByVerb(String verb) { 355 Iterator iter; 356 357 if (actionList != null) { 358 iter = actionList.iterator(); 359 if (iter != null) { 360 while (iter.hasNext()) { 361 Action temAction = (Action) iter.next(); 362 String temVerb = temAction.getVerb(); 363 364 if (temVerb.equalsIgnoreCase(verb)) { 365 return temAction; 366 } 367 } 368 } 369 } 370 371 return null; 372 } 373 374 386 public boolean equals(Object other) { 387 if (!(other instanceof Association)) { 388 return false; 389 } 390 Association otherAssoc = (Association) other; 391 392 396 boolean isBasicEquals, isActionListEquals, isFileExtListEquals; 397 String otherDesc = otherAssoc.getDescription(); 398 String otherIconFileName = otherAssoc.getIconFileName(); 399 String otherMimeType = otherAssoc.getMimeType(); 400 401 isBasicEquals = ((description == null 402 ? otherDesc == null 403 : description.equals(otherDesc)) 404 && (iconFileName == null 405 ? otherIconFileName == null 406 : iconFileName.equals(otherIconFileName)) 407 && (mimeType == null 408 ? otherMimeType == null 409 : mimeType.equals(otherMimeType))); 410 411 if (!isBasicEquals) { 412 return false; 413 } 414 415 List otherFileExtList = otherAssoc.getFileExtList(); 417 isFileExtListEquals = false; 418 if ((fileExtensionList == null) && (otherFileExtList == null)) { 422 isFileExtListEquals = true; 423 } else if ((fileExtensionList != null) && (otherFileExtList != null)) { 424 if ((fileExtensionList.containsAll(otherFileExtList)) && 425 (otherFileExtList.containsAll(fileExtensionList))) { 426 isFileExtListEquals = true; 427 } 428 } 429 if (!isFileExtListEquals) { 430 return false; 431 } 432 433 List otherActionList = otherAssoc.getActionList(); 435 isActionListEquals = false; 436 if ((actionList == null) && (otherActionList != null)) { 440 isActionListEquals = true; 441 } else if ((actionList != null) && (otherActionList != null)) { 442 if ((actionList.containsAll(otherActionList)) && 443 (otherActionList.containsAll(actionList))) { 444 isActionListEquals = true; 445 } 446 } 447 448 return isActionListEquals; 449 } 450 451 458 public int hashCode() { 459 if (hashcode != 0) { 460 int result = 17; 461 if (this.name != null) { 462 result = result * 37 + this.name.hashCode(); 463 } 464 if (this.description != null) { 465 result = result * 37 + this.description.hashCode(); 466 } 467 if (this.mimeType != null) { 468 result = result * 37 + this.mimeType.hashCode(); 469 } 470 if (this.iconFileName != null) { 471 result = result * 37 + this.iconFileName.hashCode(); 472 } 473 if (this.fileExtensionList != null) { 474 result = result * 37 + this.fileExtensionList.hashCode(); 475 } 476 if (this.actionList != null) { 477 result = result * 37 + this.actionList.hashCode(); 478 } 479 hashcode = result; 480 } 481 return hashcode; 482 } 483 484 485 505 public String toString() { 506 String crlfString = "\r\n"; 507 String content = ""; 508 Iterator temIter; 509 510 content = content.concat("MIME File Name: "); 511 if (this.name != null) { 512 content = content.concat(name); 513 } 514 content = content.concat(crlfString); 515 516 content = content.concat("Description: "); 517 if (this.description != null) { 518 content = content.concat(description); 519 } 520 content = content.concat(crlfString); 521 522 content = content.concat("MIME Type: "); 523 if (this.mimeType != null) { 524 content = content.concat(mimeType); 525 } 526 content = content.concat(crlfString); 527 528 529 content = content.concat("Icon File: "); 530 if (this.iconFileName != null) { 531 content = content.concat(iconFileName); 532 } 533 content = content.concat(crlfString); 534 535 content = content.concat("File Extension: "); 536 if (fileExtensionList != null) { 537 temIter = fileExtensionList.iterator(); 538 if (temIter != null) { 539 while (temIter.hasNext()) { 540 content = content.concat((String ) temIter.next()); 541 if (temIter.hasNext()) { 542 content = content.concat(" "); 543 } 544 } 545 } 546 } 547 content = content.concat(crlfString); 548 549 content = content.concat("Action List: "); 550 if (actionList != null) { 551 temIter = actionList.iterator(); 552 if (temIter != null) { 553 content = content.concat(crlfString); 554 while (temIter.hasNext()) { 555 Action temAction = (Action) temIter.next(); 556 content = content.concat(temAction.toString()); 557 } 558 } 559 } 560 content = content.concat(crlfString); 561 562 return content; 563 } 564 } 565 | Popular Tags |