1 11 package org.eclipse.pde.internal.core.site; 12 13 import java.io.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.pde.internal.core.*; 17 import org.eclipse.pde.internal.core.ifeature.*; 18 import org.eclipse.pde.internal.core.isite.*; 19 import org.w3c.dom.*; 20 21 29 public class SiteBuildFeature 30 extends SiteBuildObject 31 implements ISiteBuildFeature { 32 private String id; 33 private String version; 34 private IFeature feature; 35 36 39 public String getId() { 40 return id; 41 } 42 43 46 public String getVersion() { 47 return version; 48 } 49 50 53 public void setId(String id) throws CoreException { 54 ensureModelEditable(); 55 Object oldValue = this.id; 56 this.id = id; 57 firePropertyChanged(P_ID, oldValue, id); 58 } 59 60 public void setVersion(String version) throws CoreException { 61 ensureModelEditable(); 62 Object oldValue = this.version; 63 this.version = version; 64 firePropertyChanged(P_VERSION, oldValue, version); 65 } 66 67 protected void parse(Node node) { 68 id = getNodeAttribute(node, "id"); version = getNodeAttribute(node, "version"); } 71 72 public IFeature getReferencedFeature() { 73 if (feature == null) { 74 WorkspaceModelManager manager = 75 PDECore.getDefault().getWorkspaceModelManager(); 76 IFeatureModel[] models = manager.getFeatureModels(); 77 for (int i = 0; i < models.length; i++) { 78 IFeatureModel model = models[i]; 79 IFeature feature = model.getFeature(); 80 if (feature.getId().equals(id) 81 && feature.getVersion().equals(version)) { 82 this.feature = feature; 83 break; 84 } 85 } 86 } 88 return feature; 89 } 90 91 public void setReferencedFeature(IFeature feature) { 92 this.feature = feature; 93 if (feature != null) { 94 id = feature.getId(); 95 version = feature.getVersion(); 96 } 97 } 98 99 protected void reset() { 100 id = null; 101 version = null; 102 feature = null; 103 } 104 105 public void restoreProperty(String name, Object oldValue, Object newValue) 106 throws CoreException { 107 if (name.equals(P_ID)) { 108 setId(newValue != null ? newValue.toString() : null); 109 } else if (name.equals(P_VERSION)) { 110 setVersion(newValue != null ? newValue.toString() : null); 111 } else 112 super.restoreProperty(name, oldValue, newValue); 113 } 114 115 118 public void write(String indent, PrintWriter writer) { 119 writer.print(indent); 120 writer.print("<feature"); if (id != null) 122 writer.print(" id=\"" + id + "\""); if (version != null) 124 writer.print(" version=\"" + version + "\""); writer.println("/>"); } 127 128 public String getTargetURL() { 129 ISiteBuild siteBuild = getSiteBuild(); 130 IPath featureLocation = siteBuild.getFeatureLocation(); 131 String jar = id + "_"+version+".jar"; return featureLocation.append(jar).toString(); 133 } 134 } 135 | Popular Tags |