1 11 package org.eclipse.update.internal.model; 12 13 import java.io.*; 14 import java.net.*; 15 import java.util.ArrayList ; 16 import java.util.Date ; 17 import java.util.List ; 18 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.update.configurator.*; 22 import org.eclipse.update.core.*; 23 import org.eclipse.update.core.model.*; 24 import org.eclipse.update.internal.core.*; 25 26 30 31 public class InstallConfigurationModel extends ModelObject { 32 33 private URL bundleURL; 35 private URL base; 36 private boolean resolved = false; 37 38 private boolean isCurrent = false; 39 private URL locationURL; 40 private String locationURLString; 41 protected Date date; 42 private String label; 43 private List activities; 44 private List configurationSites; 45 46 protected boolean initialized = false; 47 protected boolean lightlyInitialized = false; 48 49 52 public InstallConfigurationModel() { 53 } 54 55 58 public ConfiguredSiteModel[] getConfigurationSitesModel() { 59 if (!initialized) 60 initialize(); 61 if (configurationSites == null || configurationSites.size() == 0) 62 return new ConfiguredSiteModel[0]; 63 64 return (ConfiguredSiteModel[]) configurationSites.toArray(arrayTypeFor(configurationSites)); 65 } 66 67 73 public void addConfigurationSiteModel(ConfiguredSiteModel site) { 74 if (configurationSites == null) { 75 configurationSites = new ArrayList (); 76 } 77 if (!configurationSites.contains(site)) { 78 configurationSites.add(site); 79 } 80 } 81 82 public void setConfigurationSiteModel(ConfiguredSiteModel[] sites) { 83 configurationSites = null; 84 for (int i = 0; i < sites.length; i++) { 85 addConfigurationSiteModel(sites[i]); 86 } 87 } 88 89 92 public boolean removeConfigurationSiteModel(ConfiguredSiteModel site) { 93 if (!initialized) initialize(); 94 95 if (configurationSites != null) { 96 return configurationSites.remove(site); 97 } 98 99 return false; 100 } 101 102 105 public boolean isCurrent() { 106 if (!lightlyInitialized && !initialized ) 107 doLightInitialization(); 108 109 return isCurrent; 110 } 111 112 115 public void setCurrent(boolean isCurrent) { 116 this.isCurrent = isCurrent; 119 } 120 121 124 public ConfigurationActivityModel[] getActivityModel() { 125 if (activities == null && !initialized) 126 initialize(); 127 if (activities == null || activities.size() == 0) 128 return new ConfigurationActivityModel[0]; 129 return (ConfigurationActivityModel[]) activities.toArray(arrayTypeFor(activities)); 130 } 131 132 135 public void addActivityModel(ConfigurationActivityModel activity) { 136 if (activities == null) 137 activities = new ArrayList (); 138 if (!activities.contains(activity)) { 139 activities.add(activity); 140 activity.setInstallConfigurationModel(this); 141 } 142 } 143 146 public Date getCreationDate() { 147 if (date == null) 149 doLightInitialization(); 150 return date; 151 } 152 156 public void setCreationDate(Date date) { 157 assertIsWriteable(); 158 this.date = date; 159 } 160 163 public URL getURL() { 164 delayedResolve(); 167 return locationURL; 168 } 169 170 173 public String getLabel() { 174 if (label == null) 176 doLightInitialization(); 177 return label; 178 } 179 180 183 184 public String toString() { 185 return getLabel(); 186 } 187 188 192 public void setLabel(String label) { 193 assertIsWriteable(); 194 this.label = label; 195 } 196 197 201 public String getLocationURLString() { 202 if (!initialized) delayedResolve(); 203 return locationURLString; 204 } 205 206 210 public void setLocationURLString(String locationURLString) { 211 assertIsWriteable(); 212 this.locationURLString = locationURLString; 213 this.locationURL = null; 214 } 215 216 219 public void resolve(URL base, URL bundleURL) throws MalformedURLException { 220 221 this.base = base; 222 this.bundleURL = bundleURL; 223 224 } 225 226 230 public long getTimeline() { 231 return 0; 232 } 235 236 237 240 private void initialize() { 241 242 try { 243 try { 244 IPlatformConfiguration platformConfig = getPlatformConfiguration(); 245 246 new InstallConfigurationParser(platformConfig, this, false); 247 } catch (FileNotFoundException exception) { 248 UpdateCore.warn(locationURLString + " does not exist, The local site is not in synch with the file system and is pointing to a file that doesn't exist.", exception); throw Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_ErrorDuringFileAccess, (new String [] { locationURLString })), exception); 250 } catch (IOException exception) { 251 throw Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_ErrorDuringFileAccess, (new String [] { locationURLString })), exception); 252 } 253 254 } catch (CoreException e) { 255 UpdateCore.warn("Error processing configuration history:" + locationURL.toExternalForm(), e); } finally { 257 initialized = true; 258 } 259 260 try { 263 resolveListReference(getActivityModel(), base, bundleURL); 265 resolveListReference(getConfigurationSitesModel(), base, bundleURL); 266 } catch (MalformedURLException e){} 267 } 268 269 private IPlatformConfiguration getPlatformConfiguration() throws IOException { 270 IPlatformConfiguration platformConfig; 271 if (UpdateManagerUtils.sameURL(getURL(), ConfiguratorUtils.getCurrentPlatformConfiguration().getConfigurationLocation())) 272 platformConfig = ConfiguratorUtils.getCurrentPlatformConfiguration(); 273 else 274 platformConfig = ConfiguratorUtils.getPlatformConfiguration(getURL()); 275 return platformConfig; 276 } 277 278 private void doLightInitialization() { 279 try { 280 try { 281 IPlatformConfiguration platformConfig = getPlatformConfiguration(); 282 283 new InstallConfigurationParser(platformConfig, this, true); 284 } catch (FileNotFoundException exception) { 285 UpdateCore.warn(locationURLString + " does not exist, The local site is not in synch with the file system and is pointing to a file that doesn't exist.", exception); throw Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_ErrorDuringFileAccess, (new String [] { locationURLString })), exception); 287 } catch (IOException exception) { 288 throw Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_ErrorDuringFileAccess, (new String [] { locationURLString })), exception); 289 } 290 } catch (CoreException e) { 291 UpdateCore.warn("Error processing configuration history:" + locationURL.toExternalForm(), e); } finally { 293 lightlyInitialized = true; 294 } 295 } 296 297 300 private void delayedResolve() { 301 302 if (resolved) 304 return; 305 306 resolved = true; 307 try { 309 locationURL = new URL(locationURLString); 311 } catch (MalformedURLException e){ 312 File f = new File(locationURLString); 313 try { 314 if (f.exists()) 315 locationURL = f.toURL(); 316 else 317 locationURL = base; 318 } catch (MalformedURLException e1) { 319 locationURL = base; 320 } 321 } 322 } 323 324 public void resetActivities() { 325 activities = null; 326 } 327 } 328 | Popular Tags |