1 12 13 package org.eclipse.update.core.model; 14 15 16 import java.net.MalformedURLException ; 17 import java.net.URL ; 18 import java.util.ArrayList ; 19 import java.util.Arrays ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.eclipse.update.core.IIncludedFeatureReference; 24 import org.eclipse.update.core.IncludedFeatureReference; 25 import org.eclipse.update.core.VersionedIdentifier; 26 import org.eclipse.update.internal.core.UpdateCore; 27 28 44 public class FeatureModel extends ModelObject { 45 46 private String featureId; 47 private String featureVersion; 48 private String label; 49 private String localizedLabel; 50 private String provider; 51 private String localizedProvider; 52 private String imageURLString; 53 private URL imageURL; 54 private String os; 55 private String ws; 56 private String nl; 57 private String arch; 58 private boolean primary = false; 59 private boolean exclusive=false; 60 private String primaryPluginID; 61 private String application; 62 private String affinity; 63 private InstallHandlerEntryModel installHandler; 64 private URLEntryModel description; 65 private URLEntryModel copyright; 66 private URLEntryModel license; 67 private URLEntryModel updateSiteInfo; 68 private List discoverySiteInfo; 69 private List imports; 70 private List pluginEntries; 71 private List featureIncludes; 72 private List nonPluginEntries; 73 74 private URL bundleURL; 76 private URL base; 77 private boolean resolved = false; 78 79 84 public FeatureModel() { 85 super(); 86 } 87 88 96 public boolean equals(Object obj) { 97 if (!(obj instanceof FeatureModel)) 98 return false; 99 FeatureModel model = (FeatureModel) obj; 100 101 return (featureId.toLowerCase().equals(model.getFeatureIdentifier()) && featureVersion.toLowerCase().equals(model.getFeatureVersion())); 102 } 103 104 111 public String getFeatureIdentifier() { 112 return featureId; 114 } 115 116 123 public String getFeatureVersion() { 124 return featureVersion; 126 } 127 128 135 public String getLabel() { 136 delayedResolve(); 137 if (localizedLabel != null) 138 return localizedLabel; 139 else 140 return label; 141 } 142 143 149 public String getLabelNonLocalized() { 150 return label; 151 } 152 153 160 public String getProvider() { 161 delayedResolve(); 162 if (localizedProvider != null) 163 return localizedProvider; 164 else 165 return provider; 166 } 167 168 174 public String getProviderNonLocalized() { 175 return provider; 176 } 177 178 184 public String getImageURLString() { 185 delayedResolve(); 186 return imageURLString; 187 } 188 189 195 public URL getImageURL() { 196 delayedResolve(); 197 return imageURL; 198 } 199 200 206 public String getOS() { 207 return os; 208 } 209 210 215 public String getWS() { 216 return ws; 217 } 218 219 225 public String getOSArch() { 226 return arch; 227 } 228 229 235 public String getNL() { 236 return nl; 237 } 238 239 246 public boolean isPrimary() { 247 return primary; 248 } 249 250 259 public boolean isExclusive() { 260 return exclusive; 261 } 262 263 269 public String getApplication() { 270 return application; 271 } 272 273 279 public String getAffinityFeature() { 280 return affinity; 281 } 282 283 290 public InstallHandlerEntryModel getInstallHandlerModel() { 291 return installHandler; 293 } 294 295 301 public URLEntryModel getDescriptionModel() { 302 return description; 304 } 305 306 312 public URLEntryModel getCopyrightModel() { 313 return copyright; 315 } 316 317 323 public URLEntryModel getLicenseModel() { 324 return license; 326 } 327 328 335 public URLEntryModel getUpdateSiteEntryModel() { 336 return updateSiteInfo; 338 } 339 340 348 public URLEntryModel[] getDiscoverySiteEntryModels() { 349 if (discoverySiteInfo == null || discoverySiteInfo.size() == 0) 351 return new URLEntryModel[0]; 352 353 return (URLEntryModel[]) discoverySiteInfo.toArray(arrayTypeFor(discoverySiteInfo)); 354 } 355 356 362 public ImportModel[] getImportModels() { 363 if (imports == null || imports.size() == 0) 365 return new ImportModel[0]; 366 367 return (ImportModel[]) imports.toArray(arrayTypeFor(imports)); 368 } 369 370 376 public PluginEntryModel[] getPluginEntryModels() { 377 if (pluginEntries == null || pluginEntries.size() == 0) 378 return new PluginEntryModel[0]; 379 380 return (PluginEntryModel[]) pluginEntries.toArray(arrayTypeFor(pluginEntries)); 381 } 382 383 390 public VersionedIdentifier[] getFeatureIncludeVersionedIdentifier() { 391 if (featureIncludes == null) 393 return new VersionedIdentifier[0]; 394 395 Iterator iter = featureIncludes.iterator(); 397 VersionedIdentifier[] versionIncluded = new VersionedIdentifier[featureIncludes.size()]; 398 int index = 0; 399 while (iter.hasNext()) { 400 IncludedFeatureReferenceModel model = (IncludedFeatureReferenceModel) iter.next(); 401 versionIncluded[index] = model.getVersionedIdentifier(); 402 index++; 403 } 404 return versionIncluded; 405 } 406 407 413 public IIncludedFeatureReference[] getFeatureIncluded() { 414 if (featureIncludes == null || featureIncludes.size() == 0) 416 return new IIncludedFeatureReference[0]; 417 return (IIncludedFeatureReference[]) featureIncludes.toArray(arrayTypeFor(featureIncludes)); 418 } 419 420 426 public NonPluginEntryModel[] getNonPluginEntryModels() { 427 if (nonPluginEntries == null || nonPluginEntries.size() == 0) 428 return new NonPluginEntryModel[0]; 429 430 return (NonPluginEntryModel[]) nonPluginEntries.toArray(arrayTypeFor(nonPluginEntries)); 431 } 432 433 440 public void setFeatureIdentifier(String featureId) { 441 assertIsWriteable(); 442 this.featureId = featureId; 443 } 444 445 452 public void setFeatureVersion(String featureVersion) { 453 assertIsWriteable(); 454 this.featureVersion = featureVersion; 455 } 456 457 464 public void setLabel(String label) { 465 assertIsWriteable(); 466 this.label = label; 467 this.localizedLabel = null; 468 } 469 470 477 public void setProvider(String provider) { 478 assertIsWriteable(); 479 this.provider = provider; 480 this.localizedProvider = null; 481 } 482 483 490 public void setImageURLString(String imageURLString) { 491 assertIsWriteable(); 492 this.imageURLString = imageURLString; 493 this.imageURL = null; 494 } 495 496 503 public void setOS(String os) { 504 assertIsWriteable(); 505 this.os = os; 506 } 507 508 515 public void setWS(String ws) { 516 assertIsWriteable(); 517 this.ws = ws; 518 } 519 520 527 public void setNL(String nl) { 528 assertIsWriteable(); 529 this.nl = nl; 530 } 531 532 539 public void setArch(String arch) { 540 assertIsWriteable(); 541 this.arch = arch; 542 } 543 544 553 public void setPrimary(boolean primary) { 554 assertIsWriteable(); 555 this.primary = primary; 556 } 557 558 568 public void setExclusive(boolean exclusive) { 569 assertIsWriteable(); 570 this.exclusive = exclusive; 571 } 572 573 580 public void setApplication(String application) { 581 assertIsWriteable(); 582 this.application = application; 583 } 584 585 593 public void setAffinityFeature(String affinity) { 594 assertIsWriteable(); 595 this.affinity = affinity; 596 } 597 598 605 public void setInstallHandlerModel(InstallHandlerEntryModel installHandler) { 606 assertIsWriteable(); 607 this.installHandler = installHandler; 608 } 609 610 617 public void setDescriptionModel(URLEntryModel description) { 618 assertIsWriteable(); 619 this.description = description; 620 } 621 622 629 public void setCopyrightModel(URLEntryModel copyright) { 630 assertIsWriteable(); 631 this.copyright = copyright; 632 } 633 634 641 public void setLicenseModel(URLEntryModel license) { 642 assertIsWriteable(); 643 this.license = license; 644 } 645 646 653 public void setUpdateSiteEntryModel(URLEntryModel updateSiteInfo) { 654 assertIsWriteable(); 655 this.updateSiteInfo = updateSiteInfo; 656 } 657 658 665 public void setDiscoverySiteEntryModels(URLEntryModel[] discoverySiteInfo) { 666 assertIsWriteable(); 667 if (discoverySiteInfo == null) 668 this.discoverySiteInfo = null; 669 else 670 this.discoverySiteInfo = new ArrayList (Arrays.asList(discoverySiteInfo)); 671 } 672 673 680 public void setImportModels(ImportModel[] imports) { 681 assertIsWriteable(); 682 if (imports == null) 683 this.imports = null; 684 else 685 this.imports = new ArrayList (Arrays.asList(imports)); 686 } 687 688 695 public void setPluginEntryModels(PluginEntryModel[] pluginEntries) { 696 assertIsWriteable(); 697 if (pluginEntries == null) 698 this.pluginEntries = null; 699 else 700 this.pluginEntries = new ArrayList (Arrays.asList(pluginEntries)); 701 } 702 703 710 public void setNonPluginEntryModels(NonPluginEntryModel[] nonPluginEntries) { 711 assertIsWriteable(); 712 if (nonPluginEntries == null) 713 this.nonPluginEntries = null; 714 else 715 this.nonPluginEntries = new ArrayList (Arrays.asList(nonPluginEntries)); 716 } 717 718 725 public void addDiscoverySiteEntryModel(URLEntryModel discoverySiteInfo) { 726 assertIsWriteable(); 727 if (this.discoverySiteInfo == null) 728 this.discoverySiteInfo = new ArrayList (); 729 if (!this.discoverySiteInfo.contains(discoverySiteInfo)) 730 this.discoverySiteInfo.add(discoverySiteInfo); 731 } 732 733 740 public void addImportModel(ImportModel importEntry) { 741 assertIsWriteable(); 742 if (this.imports == null) 743 this.imports = new ArrayList (); 744 if (!this.imports.contains(importEntry)) 745 this.imports.add(importEntry); 746 } 747 748 755 public void addPluginEntryModel(PluginEntryModel pluginEntry) { 756 assertIsWriteable(); 757 if (this.pluginEntries == null) 758 this.pluginEntries = new ArrayList (); 759 this.pluginEntries.add(pluginEntry); 762 } 763 764 770 public void addIncludedFeatureReferenceModel(IncludedFeatureReferenceModel include) { 771 assertIsWriteable(); 772 if (this.featureIncludes == null) 773 this.featureIncludes = new ArrayList (); 774 this.featureIncludes.add(new IncludedFeatureReference(include)); 777 } 778 779 786 public void addNonPluginEntryModel(NonPluginEntryModel nonPluginEntry) { 787 assertIsWriteable(); 788 if (this.nonPluginEntries == null) 789 this.nonPluginEntries = new ArrayList (); 790 this.nonPluginEntries.add(nonPluginEntry); 793 } 794 795 802 public void removeDiscoverySiteEntryModel(URLEntryModel discoverySiteInfo) { 803 assertIsWriteable(); 804 if (this.discoverySiteInfo != null) 805 this.discoverySiteInfo.remove(discoverySiteInfo); 806 } 807 808 815 public void removeImportModel(ImportModel importEntry) { 816 assertIsWriteable(); 817 if (this.imports != null) 818 this.imports.remove(importEntry); 819 } 820 821 828 public void removePluginEntryModel(PluginEntryModel pluginEntry) { 829 assertIsWriteable(); 830 if (this.pluginEntries != null) 831 this.pluginEntries.remove(pluginEntry); 832 } 833 834 841 public void removeNonPluginEntryModel(NonPluginEntryModel nonPluginEntry) { 842 assertIsWriteable(); 843 if (this.nonPluginEntries != null) 844 this.nonPluginEntries.remove(nonPluginEntry); 845 } 846 847 852 public void markReadOnly() { 853 super.markReadOnly(); 854 markReferenceReadOnly(getDescriptionModel()); 855 markReferenceReadOnly(getCopyrightModel()); 856 markReferenceReadOnly(getLicenseModel()); 857 markReferenceReadOnly(getUpdateSiteEntryModel()); 858 markListReferenceReadOnly(getDiscoverySiteEntryModels()); 859 markListReferenceReadOnly(getImportModels()); 860 markListReferenceReadOnly(getPluginEntryModels()); 861 markListReferenceReadOnly(getNonPluginEntryModels()); 862 } 863 864 876 public void resolve(URL base,URL bundleURL) throws MalformedURLException { 877 this.bundleURL = bundleURL; 878 this.base = base; 879 880 resolveListReference(getPluginEntryModels(), base, bundleURL); 882 resolveListReference(getNonPluginEntryModels(), base, bundleURL); 883 884 resolveReference(getDescriptionModel(),base, bundleURL); 886 resolveReference(getCopyrightModel(),base, bundleURL); 887 resolveReference(getLicenseModel(),base, bundleURL); 888 resolveReference(getUpdateSiteEntryModel(),base, bundleURL); 889 resolveListReference(getDiscoverySiteEntryModels(),base, bundleURL); 890 891 resolveListReference(getImportModels(),base, bundleURL); 893 } 894 895 private void delayedResolve() { 896 897 if (resolved) 899 return; 900 901 localizedLabel = resolveNLString(bundleURL, label); 903 localizedProvider = resolveNLString(bundleURL, provider); 904 try { 905 imageURL = resolveURL(base,bundleURL, imageURLString); 906 resolved = true; 907 } catch (MalformedURLException e){ 908 UpdateCore.warn("",e); } 910 } 911 912 916 public void setPrimaryPluginID(String plugin) { 917 if (primary && primaryPluginID == null) { 918 primaryPluginID = featureId; 919 } 920 primaryPluginID = plugin; 921 } 922 926 public String getPrimaryPluginID() { 927 return primaryPluginID; 928 } 929 930 935 public boolean isPatch() { 936 ImportModel[] imports = getImportModels(); 937 938 for (int i = 0; i < imports.length; i++) { 939 if (imports[i].isPatch()) 940 return true; 941 } 942 return false; 943 } 944 } | Popular Tags |