1 11 package org.eclipse.update.core; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.update.core.model.FeatureReferenceModel; 20 import org.eclipse.update.core.model.SiteModel; 21 import org.eclipse.update.internal.core.FeatureTypeFactory; 22 import org.eclipse.update.internal.core.Messages; 23 import org.eclipse.update.internal.core.UpdateCore; 24 25 40 public class FeatureReference extends FeatureReferenceModel implements IFeatureReference, IPlatformEnvironment { 41 42 private VersionedIdentifier versionId; 43 44 private IFeature exactFeature; 46 47 50 public FeatureReference() { 51 super(); 52 } 53 54 58 public FeatureReference(IFeatureReference ref) { 59 super((FeatureReferenceModel) ref); 60 try { 61 setURL(ref.getURL()); 62 } catch (CoreException e) { 63 UpdateCore.warn("", e); } 65 } 66 67 71 public FeatureReference(FeatureReferenceModel ref) { 72 super(ref); 73 try { 74 setURL(ref.getURL()); 75 } catch (CoreException e) { 76 UpdateCore.warn("", e); } 78 } 79 80 85 public IFeature getFeature() throws CoreException { 86 return getFeature(null); 87 } 88 89 93 public IFeature getFeature(IProgressMonitor monitor) throws CoreException { 94 95 if (exactFeature != null) 96 return exactFeature; 97 exactFeature = getFeature(this,monitor); 98 return exactFeature; 99 } 100 101 106 protected IFeature getFeature(IFeatureReference ref,IProgressMonitor monitor) throws CoreException { 107 108 IFeature feature = null; 109 URL refURL = ref.getURL(); 110 feature = createFeature(refURL,monitor); 111 return feature; 112 } 113 114 117 private IFeature createFeature(URL url,IProgressMonitor monitor) throws CoreException { 118 String type = getType(); 119 ISite site = getSite(); 120 if (site != null) { 122 return site.createFeature(type, url, monitor); 123 } 124 125 IFeatureFactory factory = FeatureTypeFactory.getInstance().getFactory(type); 126 return factory.createFeature(url, site, monitor); 127 } 128 129 135 public ISite getSite() { 136 return (ISite) getSiteModel(); 137 } 138 139 147 public void setURL(URL url) throws CoreException { 148 if (url != null) { 149 setURLString(url.toExternalForm()); 150 try { 151 resolve(url, null); 152 } catch (MalformedURLException e) { 153 throw Utilities.newCoreException(NLS.bind(Messages.FeatureReference_UnableToResolveURL, (new String [] { url.toExternalForm() })), e); 154 } 155 } 156 } 157 158 166 public void setSite(ISite site) { 167 setSiteModel((SiteModel) site); 168 } 169 170 176 public VersionedIdentifier getVersionedIdentifier() { 177 178 if (versionId != null) 179 return versionId; 180 181 String id = getFeatureIdentifier(); 182 String ver = getFeatureVersion(); 183 if (id != null && ver != null) { 184 try { 185 versionId = new VersionedIdentifier(id, ver); 186 return versionId; 187 } catch (Exception e) { 188 UpdateCore.warn("Unable to create versioned identifier:" + id + ":" + ver); } 190 } 191 192 versionId = new VersionedIdentifier(getURL().toExternalForm(), null); 194 try { 195 versionId = getFeature(null).getVersionedIdentifier(); 196 } catch (CoreException e) { 197 UpdateCore.warn("", e); } 199 return versionId; 200 } 201 202 205 public String getName() { 206 if (super.getLabel() != null) 207 return super.getLabel(); 208 try { 209 return getFeature(null).getLabel(); 210 } catch (CoreException e) { 211 return getVersionedIdentifier().toString(); 212 } 213 } 214 215 221 public String getOS() { 222 if (super.getOS() == null && getURL()!=null) 223 try { 224 return getFeature(null).getOS(); 225 } catch (CoreException e) { 226 return null; 227 } 228 return super.getOS(); 229 } 230 231 237 public String getWS() { 238 if (super.getWS() == null && getURL()!=null) 239 try { 240 return getFeature(null).getWS(); 241 } catch (CoreException e) { 242 return null; 243 } 244 return super.getWS(); 245 } 246 247 253 public String getOSArch() { 254 if (super.getOSArch() == null && getURL()!=null) 255 try { 256 return getFeature(null).getOSArch(); 257 } catch (CoreException e) { 258 return null; 259 } 260 return super.getOSArch(); 261 } 262 263 269 public String getNL() { 270 if (super.getNL() == null && getURL()!=null) 271 try { 272 return getFeature(null).getNL(); 273 } catch (CoreException e) { 274 return null; 275 } 276 return super.getNL(); 277 } 278 279 284 public boolean isPatch() { 285 if (super.getPatch() == null) 286 try { 287 return getFeature(null).isPatch(); 288 } catch (CoreException e) { 289 return false; 290 } 291 return "true".equalsIgnoreCase(super.getPatch()); } 293 294 } 295 | Popular Tags |