001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.feature;
011:
012: import java.io.File;
013: import java.io.PrintWriter;
014:
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.pde.internal.core.ifeature.IFeatureData;
017: import org.w3c.dom.Node;
018:
019: public class FeatureData extends IdentifiableObject implements
020: IFeatureData {
021: private static final long serialVersionUID = 1L;
022: private String os;
023: private String ws;
024: private String nl;
025: private String arch;
026: private long downloadSize;
027: private long installSize;
028:
029: public FeatureData() {
030: }
031:
032: protected void reset() {
033: super .reset();
034: os = null;
035: ws = null;
036: nl = null;
037: arch = null;
038: downloadSize = 0;
039: installSize = 0;
040: }
041:
042: public boolean exists() {
043: String location = getModel().getInstallLocation();
044: if (location.startsWith("file:")) //$NON-NLS-1$
045: location = location.substring(5);
046: File file = new File(location + File.separator + getId());
047: return file.exists();
048: }
049:
050: protected void parse(Node node) {
051: super .parse(node);
052: os = getNodeAttribute(node, "os"); //$NON-NLS-1$
053: ws = getNodeAttribute(node, "ws"); //$NON-NLS-1$
054: nl = getNodeAttribute(node, "nl"); //$NON-NLS-1$
055: arch = getNodeAttribute(node, "arch"); //$NON-NLS-1$
056: downloadSize = getIntegerAttribute(node, "download-size"); //$NON-NLS-1$
057: installSize = getIntegerAttribute(node, "install-size"); //$NON-NLS-1$
058: }
059:
060: protected void writeAttributes(String indent2, PrintWriter writer) {
061: if (getId() != null) {
062: writer.println();
063: writer.print(indent2 + "id=\"" + getId() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
064: }
065: if (getOS() != null) {
066: writer.println();
067: writer.print(indent2 + "os=\"" + getOS() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
068: }
069: if (getWS() != null) {
070: writer.println();
071: writer.print(indent2 + "ws=\"" + getWS() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
072: }
073: if (getNL() != null) {
074: writer.println();
075: writer.print(indent2 + "nl=\"" + getNL() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
076: }
077: if (getArch() != null) {
078: writer.println();
079: writer.print(indent2 + "arch=\"" + getArch() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
080: }
081: writer.println();
082: writer.print(indent2
083: + "download-size=\"" + getDownloadSize() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
084: writer.println();
085: writer.print(indent2
086: + "install-size=\"" + getInstallSize() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
087: }
088:
089: public void write(String indent, PrintWriter writer) {
090: writer.print(indent + "<data"); //$NON-NLS-1$
091: String indent2 = indent + Feature.INDENT + Feature.INDENT;
092: writeAttributes(indent2, writer);
093: writer.println("/>"); //$NON-NLS-1$
094: //writer.println(indent + "</data>");
095: }
096:
097: /**
098: * Gets the os.
099: * @return Returns a String
100: */
101: public String getOS() {
102: return os;
103: }
104:
105: /**
106: * Sets the os.
107: * @param os The os to set
108: */
109: public void setOS(String os) throws CoreException {
110: ensureModelEditable();
111: Object oldValue = this .os;
112: this .os = os;
113: firePropertyChanged(P_OS, oldValue, os);
114: }
115:
116: /**
117: * Gets the ws.
118: * @return Returns a String
119: */
120: public String getWS() {
121: return ws;
122: }
123:
124: /**
125: * Sets the ws.
126: * @param ws The ws to set
127: */
128: public void setWS(String ws) throws CoreException {
129: ensureModelEditable();
130: Object oldValue = this .ws;
131: this .ws = ws;
132: firePropertyChanged(P_WS, oldValue, ws);
133: }
134:
135: /**
136: * Gets the nl.
137: * @return Returns a String
138: */
139: public String getNL() {
140: return nl;
141: }
142:
143: /**
144: * Sets the nl.
145: * @param nl The nl to set
146: */
147: public void setNL(String nl) throws CoreException {
148: ensureModelEditable();
149: Object oldValue = this .nl;
150: this .nl = nl;
151: firePropertyChanged(P_NL, oldValue, nl);
152: }
153:
154: /**
155: * Gets the arch.
156: * @return Returns a String
157: */
158: public String getArch() {
159: return arch;
160: }
161:
162: /**
163: * Sets the arch.
164: * @param arch The arch to set
165: */
166: public void setArch(String arch) throws CoreException {
167: ensureModelEditable();
168: Object oldValue = this .arch;
169: this .arch = arch;
170: firePropertyChanged(P_ARCH, oldValue, arch);
171: }
172:
173: /**
174: * Gets the downloadSize.
175: * @return Returns a int
176: */
177: public long getDownloadSize() {
178: return downloadSize;
179: }
180:
181: /**
182: * Sets the downloadSize.
183: * @param downloadSize The downloadSize to set
184: */
185: public void setDownloadSize(long downloadSize) throws CoreException {
186: ensureModelEditable();
187: Object oldValue = new Long(this .downloadSize);
188: this .downloadSize = downloadSize;
189: firePropertyChanged(P_DOWNLOAD_SIZE, oldValue, new Long(
190: downloadSize));
191: }
192:
193: /**
194: * Gets the installSize.
195: * @return Returns a int
196: */
197: public long getInstallSize() {
198: return installSize;
199: }
200:
201: /**
202: * Sets the installSize.
203: * @param installSize The installSize to set
204: */
205: public void setInstallSize(long installSize) throws CoreException {
206: ensureModelEditable();
207: Object oldValue = new Long(this .installSize);
208: this .installSize = installSize;
209: firePropertyChanged(P_INSTALL_SIZE, oldValue, new Long(
210: installSize));
211: }
212:
213: public void restoreProperty(String name, Object oldValue,
214: Object newValue) throws CoreException {
215: if (name.equals(P_OS)) {
216: setOS((String) newValue);
217: } else if (name.equals(P_WS)) {
218: setWS((String) newValue);
219: } else if (name.equals(P_NL)) {
220: setNL((String) newValue);
221: } else if (name.equals(P_ARCH)) {
222: setArch((String) newValue);
223: } else if (name.equals(P_DOWNLOAD_SIZE)) {
224: setDownloadSize(newValue != null ? ((Integer) newValue)
225: .intValue() : 0);
226: } else if (name.equals(P_INSTALL_SIZE)) {
227: setInstallSize(newValue != null ? ((Integer) newValue)
228: .intValue() : 0);
229: } else
230: super .restoreProperty(name, oldValue, newValue);
231: }
232:
233: public String getLabel() {
234: return getId();
235: }
236:
237: public String toString() {
238: return getLabel();
239: }
240: }
|