1 11 package org.eclipse.update.internal.model; 12 13 import java.net.*; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import org.eclipse.update.core.*; 19 import org.eclipse.update.core.model.*; 20 import org.eclipse.update.internal.core.*; 21 22 25 public class ConfigurationPolicyModel extends ModelObject { 26 27 28 29 30 private int policy; 31 private Map configuredFeatureReferences; 32 private Map unconfiguredFeatureReferences; 33 34 private ConfiguredSiteModel configuredSiteModel; 36 37 private boolean enable; 39 40 43 public ConfigurationPolicyModel() { 44 super(); 45 enable = true; 46 configuredFeatureReferences = new HashMap (); 47 } 49 50 53 public int getPolicy() { 54 return policy; 55 } 56 57 61 public void setPolicy(int policy) { 62 assertIsWriteable(); 63 this.policy = policy; 64 } 65 66 69 public FeatureReferenceModel[] getConfiguredFeaturesModel() { 70 if (configuredFeatureReferences==null || configuredFeatureReferences.isEmpty()) 71 return new FeatureReferenceModel[0]; 72 return (FeatureReferenceModel[]) configuredFeatureReferences.keySet().toArray(arrayTypeFor(configuredFeatureReferences.keySet())); 73 } 74 75 78 public FeatureReferenceModel[] getUnconfiguredFeaturesModel() { 79 if (unconfiguredFeatureReferences == null 81 && configuredSiteModel != null 82 && configuredSiteModel.getSiteModel() != null) { 83 ISite site = (ISite) configuredSiteModel.getSiteModel(); 84 ISiteFeatureReference[] siteFeatures = site.getFeatureReferences(); 85 if (siteFeatures.length > getConfiguredFeaturesModel().length) { 86 for (int i=0; i<siteFeatures.length; i++) { 87 if (!(siteFeatures[i] instanceof SiteFeatureReference)) 88 continue; 89 Iterator iterator = configuredFeatureReferences.keySet().iterator(); 90 boolean found = false; 91 while(!found && iterator.hasNext()) { 92 FeatureReferenceModel f = (FeatureReferenceModel)iterator.next(); 93 if (UpdateManagerUtils.sameURL(f.getURL(), siteFeatures[i].getURL())) 94 found = true; 95 } 96 if (!found) 97 addUnconfiguredFeatureReference((SiteFeatureReference)siteFeatures[i]); 98 } 99 } 100 } 101 if (unconfiguredFeatureReferences == null 102 || unconfiguredFeatureReferences.isEmpty()) 103 return new FeatureReferenceModel[0]; 104 return (FeatureReferenceModel[]) unconfiguredFeatureReferences.keySet() 105 .toArray(arrayTypeFor(unconfiguredFeatureReferences.keySet())); 106 } 107 108 113 public ConfiguredSiteModel getConfiguredSiteModel() { 114 return configuredSiteModel; 115 } 116 117 122 public void setConfiguredSiteModel(ConfiguredSiteModel configuredSiteModel) { 123 this.configuredSiteModel = configuredSiteModel; 124 } 125 126 129 private boolean remove(FeatureReferenceModel feature, Map list) { 130 URL featureURL = feature.getURL(); 131 boolean found = false; 132 Iterator iter = list.keySet().iterator(); 133 while (iter.hasNext() && !found) { 134 FeatureReferenceModel element = (FeatureReferenceModel) iter.next(); 135 if (UpdateManagerUtils.sameURL(element.getURL(),featureURL)) { 136 list.remove(element); 137 found = true; 138 } 139 } 140 return found; 141 } 142 143 146 147 148 149 152 private void add(FeatureReferenceModel feature, Map list) { 153 URL featureURL = feature.getURL(); 154 boolean found = false; 155 Iterator iter = list.keySet().iterator(); 156 while (iter.hasNext() && !found) { 157 FeatureReferenceModel element = (FeatureReferenceModel) iter.next(); 158 if (UpdateManagerUtils.sameURL(element.getURL(),featureURL)) { 159 found = true; 160 } 161 } 162 163 if (!found) { 164 list.put(feature,null); 165 } else { 166 UpdateCore.warn("Feature Reference :"+feature+" already part of the list."); } 168 } 169 170 174 public void addConfiguredFeatureReference(FeatureReferenceModel feature) { 175 assertIsWriteable(); 176 177 if (configuredFeatureReferences == null) 178 this.configuredFeatureReferences = new HashMap (); 179 if (!configuredFeatureReferences.containsKey(feature)){ 180 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_CONFIGURATION){ 182 UpdateCore.debug("Configuring "+feature.getURLString()); } 184 this.add(feature, configuredFeatureReferences); 185 } 186 187 if (unconfiguredFeatureReferences != null) { 191 boolean success = remove(feature, unconfiguredFeatureReferences); 192 if (!success) 193 UpdateCore.warn("Feature not part of Unconfigured list: "+feature.getURLString()); } 195 196 } 197 198 202 public void addUnconfiguredFeatureReference(FeatureReferenceModel feature) { 203 assertIsWriteable(); 204 if (unconfiguredFeatureReferences == null) 205 this.unconfiguredFeatureReferences = new HashMap (); 206 if (!unconfiguredFeatureReferences.containsKey(feature)){ 207 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_CONFIGURATION){ 208 UpdateCore.debug("Unconfiguring "+feature.getURLString()); } 210 this.add(feature, unconfiguredFeatureReferences); 211 } 212 213 if (configuredFeatureReferences != null) { 216 boolean success = remove(feature, configuredFeatureReferences); 217 if (!success) 218 UpdateCore.warn("Feature not part of Configured list: "+feature.getURLString()); } 220 } 221 222 225 public void removeFeatureReference(FeatureReferenceModel feature) { 226 assertIsWriteable(); 227 if (unconfiguredFeatureReferences!=null){ 228 boolean success = remove(feature, unconfiguredFeatureReferences); 229 if (!success) 230 UpdateCore.warn(feature.getURLString()+" not part of unconfigured list."); } 232 233 if (configuredFeatureReferences != null) { 234 boolean success = remove(feature, configuredFeatureReferences); 235 if (!success) 236 UpdateCore.warn(feature.getURLString()+" not part of configured list."); } 238 } 239 240 244 protected void setUnconfiguredFeatureReferences(IFeatureReference[] featureReferences) { 245 unconfiguredFeatureReferences = new HashMap (); 246 for (int i = 0; i < featureReferences.length; i++) { 247 unconfiguredFeatureReferences.put(featureReferences[i],null); 248 } 249 } 250 251 252 256 protected void setConfiguredFeatureReferences(IFeatureReference[] featureReferences) { 257 configuredFeatureReferences = new HashMap (); 258 for (int i = 0; i < featureReferences.length; i++) { 259 configuredFeatureReferences.put(featureReferences[i],null); 260 } 261 262 } 263 264 267 public boolean isEnabled() { 268 return enable; 269 } 270 271 274 public void setEnabled(boolean value) { 275 enable = value; 276 } 277 278 279 280 } 281 | Popular Tags |