1 11 package org.eclipse.update.core.model; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 import java.util.ArrayList ; 16 import java.util.Arrays ; 17 import java.util.List ; 18 import java.util.Set ; 19 import java.util.TreeSet ; 20 21 import org.eclipse.update.core.Site; 22 import org.eclipse.update.core.SiteFeatureReferenceModel; 23 import org.eclipse.update.internal.core.ExtendedSite; 24 import org.eclipse.update.internal.core.SiteURLFactory; 25 import org.eclipse.update.internal.core.UpdateManagerUtils; 26 import org.eclipse.update.internal.model.ConfiguredSiteModel; 27 28 44 public class SiteModel extends ModelObject { 45 46 private String type; 47 private URLEntryModel description; 48 private List featureReferences; 49 private List archiveReferences; 50 private Set categories; 51 private List mirrors; 52 private String locationURLString; 53 private URL locationURL; 54 private String mirrorsURLString; 55 private ConfiguredSiteModel configuredSiteModel; 56 57 62 public SiteModel() { 63 super(); 64 } 65 66 72 public String getType() { 73 return type; 74 } 75 76 82 public URLEntryModel getDescriptionModel() { 83 return description; 84 } 85 86 92 public SiteFeatureReferenceModel[] getFeatureReferenceModels() { 93 if (featureReferences == null || featureReferences.size() == 0) 94 return new SiteFeatureReferenceModel[0]; 95 96 return (SiteFeatureReferenceModel[]) featureReferences.toArray(arrayTypeFor(featureReferences)); 97 } 98 99 107 public ArchiveReferenceModel[] getArchiveReferenceModels() { 108 if (archiveReferences == null || archiveReferences.size() == 0) 109 return new ArchiveReferenceModel[0]; 110 111 return (ArchiveReferenceModel[]) archiveReferences.toArray(arrayTypeFor(archiveReferences)); 112 } 113 114 120 public CategoryModel[] getCategoryModels() { 121 if (categories == null || categories.size()==0) 122 return new CategoryModel[0]; 123 124 return (CategoryModel[]) categories.toArray(arrayTypeFor(categories)); 125 } 126 127 133 public String getLocationURLString() { 134 return locationURLString; 135 } 136 137 143 public URL getLocationURL() { 144 return locationURL; 145 } 146 147 154 public void setType(String type) { 155 assertIsWriteable(); 156 this.type = type; 157 } 158 159 166 public void setDescriptionModel(URLEntryModel description) { 167 assertIsWriteable(); 168 this.description = description; 169 } 170 171 178 public void setFeatureReferenceModels(FeatureReferenceModel[] featureReferences) { 179 assertIsWriteable(); 180 if (featureReferences == null) 181 this.featureReferences = null; 182 else 183 this.featureReferences = new ArrayList (Arrays.asList(featureReferences)); 184 } 185 186 193 public void setArchiveReferenceModels(ArchiveReferenceModel[] archiveReferences) { 194 assertIsWriteable(); 195 if (archiveReferences == null) 196 this.archiveReferences = null; 197 else 198 this.archiveReferences = new ArrayList (Arrays.asList(archiveReferences)); 199 } 200 201 208 public void setCategoryModels(CategoryModel[] categories) { 209 assertIsWriteable(); 210 if (categories == null) 211 this.categories = null; 212 else { 213 this.categories = new TreeSet (CategoryModel.getComparator()); 214 this.categories.addAll(Arrays.asList(categories)); 215 } 216 } 217 218 225 public void setLocationURLString(String locationURLString) { 226 assertIsWriteable(); 227 this.locationURLString = locationURLString; 228 } 229 230 237 public void addFeatureReferenceModel(SiteFeatureReferenceModel featureReference) { 238 assertIsWriteable(); 239 if (this.featureReferences == null) 240 this.featureReferences = new ArrayList (); 241 this.featureReferences.add(featureReference); 244 } 245 246 253 public void addArchiveReferenceModel(ArchiveReferenceModel archiveReference) { 254 assertIsWriteable(); 255 if (this.archiveReferences == null) 256 this.archiveReferences = new ArrayList (); 257 if (!this.archiveReferences.contains(archiveReference)) 258 this.archiveReferences.add(archiveReference); 259 } 260 261 268 public void addCategoryModel(CategoryModel category) { 269 assertIsWriteable(); 270 if (this.categories == null) 271 this.categories = new TreeSet (CategoryModel.getComparator()); 272 if (!this.categories.contains(category)) 273 this.categories.add(category); 274 } 275 276 283 public void addMirrorModel(URLEntryModel mirror) { 284 assertIsWriteable(); 285 if (this.mirrors == null) 286 this.mirrors = new ArrayList (); 287 if (!this.mirrors.contains(mirror)) 288 this.mirrors.add(mirror); 289 } 290 291 298 public void removeFeatureReferenceModel(FeatureReferenceModel featureReference) { 299 assertIsWriteable(); 300 if (this.featureReferences != null) 301 this.featureReferences.remove(featureReference); 302 } 303 304 311 public void removeArchiveReferenceModel(ArchiveReferenceModel archiveReference) { 312 assertIsWriteable(); 313 if (this.archiveReferences != null) 314 this.archiveReferences.remove(archiveReference); 315 } 316 317 324 public void removeCategoryModel(CategoryModel category) { 325 assertIsWriteable(); 326 if (this.categories != null) 327 this.categories.remove(category); 328 } 329 330 337 public void removeMirror(URLEntryModel mirror) { 338 assertIsWriteable(); 339 if (this.mirrors != null) 340 this.mirrors.remove(mirror); 341 } 342 343 348 public void markReadOnly() { 349 super.markReadOnly(); 350 markReferenceReadOnly(getDescriptionModel()); 351 markListReferenceReadOnly(getFeatureReferenceModels()); 352 markListReferenceReadOnly(getArchiveReferenceModels()); 353 markListReferenceReadOnly(getCategoryModels()); 354 } 355 356 368 public void resolve(URL base, URL bundleURL) throws MalformedURLException { 369 370 locationURL = resolveURL(base, bundleURL, getLocationURLString()); 373 if (locationURL == null) 374 locationURL = base; 375 resolveListReference(getFeatureReferenceModels(), locationURL, bundleURL); 376 resolveListReference(getArchiveReferenceModels(), locationURL, bundleURL); 377 378 resolveReference(getDescriptionModel(), base, bundleURL); 379 resolveListReference(getCategoryModels(), base, bundleURL); 380 381 URL url = resolveURL(base, bundleURL, mirrorsURLString); 382 if (url != null) 383 mirrorsURLString = url.toString(); 384 385 if ( (this instanceof ExtendedSite) && ((ExtendedSite)this).isDigestExist()) { 386 ExtendedSite extendedSite = (ExtendedSite)this; 387 extendedSite.setLiteFeatures(UpdateManagerUtils.getLightFeatures(extendedSite)); 388 } 389 } 390 391 394 public ConfiguredSiteModel getConfiguredSiteModel() { 395 return this.configuredSiteModel; 396 } 397 398 401 public void setConfiguredSiteModel(ConfiguredSiteModel configuredSiteModel) { 402 this.configuredSiteModel = configuredSiteModel; 403 } 404 405 408 protected String getPropertyName() { 409 return Site.SITE_FILE; 410 } 411 412 418 public URLEntryModel[] getMirrorSiteEntryModels() { 419 if ( mirrors == null || mirrors.size() == 0) 421 if (mirrorsURLString != null) 423 doSetMirrorSiteEntryModels(DefaultSiteParser.getMirrors(mirrorsURLString, new SiteURLFactory())); 424 425 if (mirrors == null || mirrors.size() == 0) 426 return new URLEntryModel[0]; 427 else 428 return (URLEntryModel[]) mirrors.toArray(arrayTypeFor(mirrors)); 429 } 430 431 438 public void setMirrorSiteEntryModels(URLEntryModel[] mirrors) { 439 assertIsWriteable(); 440 doSetMirrorSiteEntryModels(mirrors); 441 } 442 443 private void doSetMirrorSiteEntryModels(URLEntryModel[] mirrors) { 444 if (mirrors == null || mirrors.length == 0) 445 this.mirrors = null; 446 else 447 this.mirrors = new ArrayList (Arrays.asList(mirrors)); 448 } 449 450 459 public void setMirrorsURLString(String mirrorsURL) { 460 assertIsWriteable(); 461 this.mirrorsURLString = mirrorsURL; 462 } 463 } 464 | Popular Tags |