1 11 package org.eclipse.pde.internal.core.feature; 12 13 import java.io.File ; 14 import java.io.PrintWriter ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.pde.internal.core.ifeature.IFeatureData; 18 import org.w3c.dom.Node ; 19 20 public class FeatureData 21 extends IdentifiableObject 22 implements IFeatureData { 23 private static final long serialVersionUID = 1L; 24 private String os; 25 private String ws; 26 private String nl; 27 private String arch; 28 private long downloadSize; 29 private long installSize; 30 31 public FeatureData() { 32 } 33 34 protected void reset() { 35 super.reset(); 36 os = null; 37 ws = null; 38 nl = null; 39 arch = null; 40 downloadSize = 0; 41 installSize = 0; 42 } 43 44 public boolean exists() { 45 String location = getModel().getInstallLocation(); 46 if (location.startsWith("file:")) location = location.substring(5); 48 File file = new File (location + File.separator+getId()); 49 return file.exists(); 50 } 51 52 protected void parse(Node node) { 53 super.parse(node); 54 os = getNodeAttribute(node, "os"); ws = getNodeAttribute(node, "ws"); nl = getNodeAttribute(node, "nl"); arch = getNodeAttribute(node, "arch"); downloadSize = getIntegerAttribute(node, "download-size"); installSize = getIntegerAttribute(node, "install-size"); } 61 protected void writeAttributes(String indent2, PrintWriter writer) { 62 if (getId() != null) { 63 writer.println(); 64 writer.print(indent2 + "id=\"" + getId() + "\""); } 66 if (getOS() != null) { 67 writer.println(); 68 writer.print(indent2 + "os=\"" + getOS() + "\""); } 70 if (getWS() != null) { 71 writer.println(); 72 writer.print(indent2 + "ws=\"" + getWS() + "\""); } 74 if (getNL() != null) { 75 writer.println(); 76 writer.print(indent2 + "nl=\"" + getNL() + "\""); } 78 if (getArch() != null) { 79 writer.println(); 80 writer.print(indent2 + "arch=\"" + getArch() + "\""); } 82 writer.println(); 83 writer.print(indent2 + "download-size=\"" + getDownloadSize() + "\""); writer.println(); 85 writer.print(indent2 + "install-size=\"" + getInstallSize() + "\""); } 87 88 public void write(String indent, PrintWriter writer) { 89 writer.print(indent + "<data"); String indent2 = indent + Feature.INDENT + Feature.INDENT; 91 writeAttributes(indent2, writer); 92 writer.println("/>"); } 95 96 100 public String getOS() { 101 return os; 102 } 103 104 108 public void setOS(String os) throws CoreException { 109 ensureModelEditable(); 110 Object oldValue = this.os; 111 this.os = os; 112 firePropertyChanged(P_OS, oldValue, os); 113 } 114 115 119 public String getWS() { 120 return ws; 121 } 122 123 127 public void setWS(String ws) throws CoreException { 128 ensureModelEditable(); 129 Object oldValue = this.ws; 130 this.ws = ws; 131 firePropertyChanged(P_WS, oldValue, ws); 132 } 133 134 138 public String getNL() { 139 return nl; 140 } 141 142 146 public void setNL(String nl) throws CoreException { 147 ensureModelEditable(); 148 Object oldValue = this.nl; 149 this.nl = nl; 150 firePropertyChanged(P_NL, oldValue, nl); 151 } 152 153 157 public String getArch() { 158 return arch; 159 } 160 161 165 public void setArch(String arch) throws CoreException { 166 ensureModelEditable(); 167 Object oldValue = this.arch; 168 this.arch = arch; 169 firePropertyChanged(P_ARCH, oldValue, arch); 170 } 171 172 176 public long getDownloadSize() { 177 return downloadSize; 178 } 179 180 184 public void setDownloadSize(long downloadSize) throws CoreException { 185 ensureModelEditable(); 186 Object oldValue = new Long (this.downloadSize); 187 this.downloadSize = downloadSize; 188 firePropertyChanged(P_DOWNLOAD_SIZE, oldValue, new Long (downloadSize)); 189 } 190 191 195 public long getInstallSize() { 196 return installSize; 197 } 198 199 203 public void setInstallSize(long installSize) throws CoreException { 204 ensureModelEditable(); 205 Object oldValue = new Long (this.installSize); 206 this.installSize = installSize; 207 firePropertyChanged(P_INSTALL_SIZE, oldValue, new Long (installSize)); 208 } 209 210 public void restoreProperty(String name, Object oldValue, Object newValue) throws CoreException { 211 if (name.equals(P_OS)) { 212 setOS((String )newValue); 213 } 214 else if (name.equals(P_WS)) { 215 setWS((String )newValue); 216 } 217 else if (name.equals(P_NL)) { 218 setNL((String )newValue); 219 } 220 else if (name.equals(P_ARCH)) { 221 setArch((String )newValue); 222 } 223 else if (name.equals(P_DOWNLOAD_SIZE)) { 224 setDownloadSize(newValue!=null?((Integer )newValue).intValue():0); 225 } 226 else if (name.equals(P_INSTALL_SIZE)) { 227 setInstallSize(newValue!=null?((Integer )newValue).intValue():0); 228 } 229 else super.restoreProperty(name, oldValue, newValue); 230 } 231 232 public String getLabel() { 233 return getId(); 234 } 235 236 public String toString() { 237 return getLabel(); 238 } 239 } 240 | Popular Tags |