KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > feature > FeatureData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.feature;
12
13 import java.io.File JavaDoc;
14 import java.io.PrintWriter JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.pde.internal.core.ifeature.IFeatureData;
18 import org.w3c.dom.Node JavaDoc;
19
20 public class FeatureData
21     extends IdentifiableObject
22     implements IFeatureData {
23     private static final long serialVersionUID = 1L;
24     private String JavaDoc os;
25     private String JavaDoc ws;
26     private String JavaDoc nl;
27     private String JavaDoc 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 JavaDoc location = getModel().getInstallLocation();
46         if (location.startsWith("file:")) //$NON-NLS-1$
47
location = location.substring(5);
48         File JavaDoc file = new File JavaDoc(location + File.separator+getId());
49         return file.exists();
50     }
51
52     protected void parse(Node JavaDoc node) {
53         super.parse(node);
54         os = getNodeAttribute(node, "os"); //$NON-NLS-1$
55
ws = getNodeAttribute(node, "ws"); //$NON-NLS-1$
56
nl = getNodeAttribute(node, "nl"); //$NON-NLS-1$
57
arch = getNodeAttribute(node, "arch"); //$NON-NLS-1$
58
downloadSize = getIntegerAttribute(node, "download-size"); //$NON-NLS-1$
59
installSize = getIntegerAttribute(node, "install-size"); //$NON-NLS-1$
60
}
61     protected void writeAttributes(String JavaDoc indent2, PrintWriter JavaDoc writer) {
62         if (getId() != null) {
63             writer.println();
64             writer.print(indent2 + "id=\"" + getId() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
65
}
66         if (getOS() != null) {
67             writer.println();
68             writer.print(indent2 + "os=\"" + getOS() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
69
}
70         if (getWS() != null) {
71             writer.println();
72             writer.print(indent2 + "ws=\"" + getWS() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
73
}
74         if (getNL() != null) {
75             writer.println();
76             writer.print(indent2 + "nl=\"" + getNL() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
77
}
78         if (getArch() != null) {
79             writer.println();
80             writer.print(indent2 + "arch=\"" + getArch() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
81
}
82         writer.println();
83         writer.print(indent2 + "download-size=\"" + getDownloadSize() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
84
writer.println();
85         writer.print(indent2 + "install-size=\"" + getInstallSize() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
86
}
87
88     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
89         writer.print(indent + "<data"); //$NON-NLS-1$
90
String JavaDoc indent2 = indent + Feature.INDENT + Feature.INDENT;
91         writeAttributes(indent2, writer);
92         writer.println("/>"); //$NON-NLS-1$
93
//writer.println(indent + "</data>");
94
}
95
96     /**
97      * Gets the os.
98      * @return Returns a String
99      */

100     public String JavaDoc getOS() {
101         return os;
102     }
103
104     /**
105      * Sets the os.
106      * @param os The os to set
107      */

108     public void setOS(String JavaDoc os) throws CoreException {
109         ensureModelEditable();
110         Object JavaDoc oldValue = this.os;
111         this.os = os;
112         firePropertyChanged(P_OS, oldValue, os);
113     }
114
115     /**
116      * Gets the ws.
117      * @return Returns a String
118      */

119     public String JavaDoc getWS() {
120         return ws;
121     }
122
123     /**
124      * Sets the ws.
125      * @param ws The ws to set
126      */

127     public void setWS(String JavaDoc ws) throws CoreException {
128         ensureModelEditable();
129         Object JavaDoc oldValue = this.ws;
130         this.ws = ws;
131         firePropertyChanged(P_WS, oldValue, ws);
132     }
133
134     /**
135      * Gets the nl.
136      * @return Returns a String
137      */

138     public String JavaDoc getNL() {
139         return nl;
140     }
141
142     /**
143      * Sets the nl.
144      * @param nl The nl to set
145      */

146     public void setNL(String JavaDoc nl) throws CoreException {
147         ensureModelEditable();
148         Object JavaDoc oldValue = this.nl;
149         this.nl = nl;
150         firePropertyChanged(P_NL, oldValue, nl);
151     }
152
153     /**
154      * Gets the arch.
155      * @return Returns a String
156      */

157     public String JavaDoc getArch() {
158         return arch;
159     }
160
161     /**
162      * Sets the arch.
163      * @param arch The arch to set
164      */

165     public void setArch(String JavaDoc arch) throws CoreException {
166         ensureModelEditable();
167         Object JavaDoc oldValue = this.arch;
168         this.arch = arch;
169         firePropertyChanged(P_ARCH, oldValue, arch);
170     }
171
172     /**
173      * Gets the downloadSize.
174      * @return Returns a int
175      */

176     public long getDownloadSize() {
177         return downloadSize;
178     }
179
180     /**
181      * Sets the downloadSize.
182      * @param downloadSize The downloadSize to set
183      */

184     public void setDownloadSize(long downloadSize) throws CoreException {
185         ensureModelEditable();
186         Object JavaDoc oldValue = new Long JavaDoc(this.downloadSize);
187         this.downloadSize = downloadSize;
188         firePropertyChanged(P_DOWNLOAD_SIZE, oldValue, new Long JavaDoc(downloadSize));
189     }
190
191     /**
192      * Gets the installSize.
193      * @return Returns a int
194      */

195     public long getInstallSize() {
196         return installSize;
197     }
198
199     /**
200      * Sets the installSize.
201      * @param installSize The installSize to set
202      */

203     public void setInstallSize(long installSize) throws CoreException {
204         ensureModelEditable();
205         Object JavaDoc oldValue = new Long JavaDoc(this.installSize);
206         this.installSize = installSize;
207         firePropertyChanged(P_INSTALL_SIZE, oldValue, new Long JavaDoc(installSize));
208     }
209     
210     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue) throws CoreException {
211         if (name.equals(P_OS)) {
212             setOS((String JavaDoc)newValue);
213         }
214         else if (name.equals(P_WS)) {
215             setWS((String JavaDoc)newValue);
216         }
217         else if (name.equals(P_NL)) {
218             setNL((String JavaDoc)newValue);
219         }
220         else if (name.equals(P_ARCH)) {
221             setArch((String JavaDoc)newValue);
222         }
223         else if (name.equals(P_DOWNLOAD_SIZE)) {
224             setDownloadSize(newValue!=null?((Integer JavaDoc)newValue).intValue():0);
225         }
226         else if (name.equals(P_INSTALL_SIZE)) {
227             setInstallSize(newValue!=null?((Integer JavaDoc)newValue).intValue():0);
228         }
229         else super.restoreProperty(name, oldValue, newValue);
230     }
231
232     public String JavaDoc getLabel() {
233         return getId();
234     }
235     
236     public String JavaDoc toString() {
237         return getLabel();
238     }
239 }
240
Popular Tags