1 11 package org.eclipse.pde.internal.core.feature; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.internal.core.PDECore; 17 import org.eclipse.pde.internal.core.ifeature.IFeature; 18 import org.eclipse.pde.internal.core.ifeature.IFeatureChild; 19 import org.eclipse.pde.internal.core.ifeature.IFeatureModel; 20 import org.w3c.dom.Node ; 21 22 public class FeatureChild extends IdentifiableObject implements IFeatureChild { 23 private static final long serialVersionUID = 1L; 24 private String fVersion; 25 private String fName; 26 private boolean fOptional; 27 private int fSearchLocation = ROOT; 28 private int fMatch = NONE; 29 private String fOs; 30 private String fWs; 31 private String fArch; 32 private String fNl; 33 34 protected void reset() { 35 super.reset(); 36 fVersion = null; 37 fOptional = false; 38 fName = null; 39 fSearchLocation = ROOT; 40 fMatch = NONE; 41 fOs = null; 42 fWs = null; 43 fArch = null; 44 fNl = null; 45 } 46 protected void parse(Node node) { 47 super.parse(node); 48 fVersion = getNodeAttribute(node, "version"); fName = getNodeAttribute(node, "name"); fOptional = getBooleanAttribute(node, "optional"); fOs = getNodeAttribute(node, "os"); fWs = getNodeAttribute(node, "ws"); fArch = getNodeAttribute(node, "arch"); fNl = getNodeAttribute(node, "nl"); String matchName = getNodeAttribute(node, "match"); if (matchName != null) { 57 for (int i = 0; i < RULE_NAME_TABLE.length; i++) { 58 if (matchName.equals(RULE_NAME_TABLE[i])) { 59 fMatch = i; 60 break; 61 } 62 } 63 } 64 String searchLocationName = getNodeAttribute(node, "search_location"); if (searchLocationName == null) 66 searchLocationName = getNodeAttribute(node, "search-location"); if (searchLocationName != null) { 68 if (searchLocationName.equals("root")) fSearchLocation = ROOT; 70 else if (searchLocationName.equals("self")) fSearchLocation = SELF; 72 else if (searchLocationName.equals("both")) fSearchLocation = BOTH; 74 } 75 } 77 78 public void loadFrom(IFeature feature) { 79 id = feature.getId(); 80 fVersion = feature.getVersion(); 81 fOptional = false; 82 fName = null; 83 } 84 87 public String getVersion() { 88 return fVersion; 89 } 90 91 public boolean isOptional() { 92 return fOptional; 93 } 94 95 public String getName() { 96 return fName; 97 } 98 99 public int getSearchLocation() { 100 return fSearchLocation; 101 } 102 103 public int getMatch() { 104 return fMatch; 105 } 106 107 public String getOS() { 108 return fOs; 109 } 110 111 public String getWS() { 112 return fWs; 113 } 114 115 public String getArch() { 116 return fArch; 117 } 118 119 public String getNL() { 120 return fNl; 121 } 122 123 public IFeature getReferencedFeature() { 124 IFeatureModel workspaceModel = PDECore.getDefault() 125 .getFeatureModelManager().findFeatureModel(getId(), fVersion); 126 if (workspaceModel != null) { 127 return workspaceModel.getFeature(); 128 } 129 return null; 130 } 131 132 135 public void setVersion(String version) throws CoreException { 136 ensureModelEditable(); 137 Object oldValue = this.fVersion; 138 this.fVersion = version; 139 firePropertyChanged(P_VERSION, oldValue, version); 140 } 141 142 public void setName(String name) throws CoreException { 143 ensureModelEditable(); 144 Object oldValue = this.fName; 145 this.fName = name; 146 firePropertyChanged(P_NAME, oldValue, name); 147 } 148 149 public void setMatch(int match) throws CoreException { 150 ensureModelEditable(); 151 Integer oldValue = new Integer (this.fMatch); 152 this.fMatch = match; 153 firePropertyChanged(P_MATCH, oldValue, new Integer (match)); 154 } 155 156 public void setSearchLocation(int searchLocation) throws CoreException { 157 ensureModelEditable(); 158 Integer oldValue = new Integer (this.fSearchLocation); 159 this.fSearchLocation = searchLocation; 160 firePropertyChanged( 161 P_SEARCH_LOCATION, 162 oldValue, 163 new Integer (searchLocation)); 164 } 165 166 public void setOptional(boolean optional) throws CoreException { 167 ensureModelEditable(); 168 Object oldValue = new Boolean (this.fOptional); 169 this.fOptional = optional; 170 firePropertyChanged(P_NAME, oldValue, new Boolean (optional)); 171 } 172 173 public void setOS(String os) throws CoreException { 174 ensureModelEditable(); 175 Object oldValue = this.fOs; 176 this.fOs = os; 177 firePropertyChanged(P_OS, oldValue, os); 178 } 179 180 public void setWS(String ws) throws CoreException { 181 ensureModelEditable(); 182 Object oldValue = this.fWs; 183 this.fWs = ws; 184 firePropertyChanged(P_WS, oldValue, ws); 185 } 186 187 public void setArch(String arch) throws CoreException { 188 ensureModelEditable(); 189 Object oldValue = this.fArch; 190 this.fArch = arch; 191 firePropertyChanged(P_ARCH, oldValue, arch); 192 } 193 194 public void setNL(String nl) throws CoreException { 195 ensureModelEditable(); 196 Object oldValue = this.fNl; 197 this.fNl = nl; 198 firePropertyChanged(P_NL, oldValue, nl); 199 } 200 201 public void restoreProperty(String name, Object oldValue, Object newValue) 202 throws CoreException { 203 if (name.equals(P_VERSION)) { 204 setVersion((String ) newValue); 205 } else if (name.equals(P_OPTIONAL)) { 206 setOptional(((Boolean ) newValue).booleanValue()); 207 } else if (name.equals(P_NAME)) { 208 setName((String ) newValue); 209 } else if (name.equals(P_MATCH)) { 210 setMatch(newValue != null ? ((Integer ) newValue).intValue() : NONE); 211 } else if (name.equals(P_OS)) { 212 setOS((String )newValue); 213 } else if (name.equals(P_WS)) { 214 setWS((String )newValue); 215 } else if (name.equals(P_ARCH)) { 216 setArch((String )newValue); 217 } else if (name.equals(P_NL)) { 218 setNL((String )newValue); 219 } else if (name.equals(P_SEARCH_LOCATION)) { 220 setSearchLocation( 221 newValue != null ? ((Integer ) newValue).intValue() : ROOT); 222 } else 223 super.restoreProperty(name, oldValue, newValue); 224 } 225 226 public void setId(String id) throws CoreException { 227 super.setId(id); 228 } 229 230 233 public void write(String indent, PrintWriter writer) { 234 writer.print(indent + "<includes"); String indent2 = indent + Feature.INDENT + Feature.INDENT; 236 if (getId() != null) { 237 writer.println(); 238 writer.print(indent2 + "id=\"" + getId() + "\""); } 240 if (getVersion() != null) { 241 writer.println(); 242 writer.print(indent2 + "version=\"" + getVersion() + "\""); } 244 if (getName() != null) { 245 writer.println(); 246 writer.print(indent2 + "name=\"" + getName() + "\""); } 248 if (isOptional()) { 249 writer.println(); 250 writer.print(indent2 + "optional=\"true\""); } 252 if (fMatch!=NONE) { 253 writer.println(); 254 writer.print(indent2 + "match=\""+RULE_NAME_TABLE[fMatch]+"\""); } 256 if (getOS() != null) { 257 writer.println(); 258 writer.print(indent2 + "os=\""+getOS() + "\""); } 260 if (getWS() != null) { 261 writer.println(); 262 writer.print(indent2 + "ws=\""+getWS() + "\""); } 264 if (getArch() != null) { 265 writer.println(); 266 writer.print(indent2 + "arch=\""+getArch() + "\""); } 268 if (getNL() != null) { 269 writer.println(); 270 writer.print(indent2 + "nl=\""+getNL() + "\""); } 272 if (fSearchLocation!=ROOT) { 273 writer.println(); 274 String value=fSearchLocation==SELF?"self":"both"; writer.print(indent2 + "search-location=\""+value+"\""); } 277 writer.println("/>"); } 279 } 280 | Popular Tags |