KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > spap > AssetVersion


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.spap;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * Represent a version of a <code>Asset</code>
26  *
27  * <p>A <code>AssetVersion</code> is constituted from:
28  * <ul>
29  * <li>a version
30  * <li>a release date
31  * <li>a release notes
32  * <li>a content file: the file to download during intallation process
33  * of this <code>AssetVersion</code>
34  * <li>a size of the content file: the dimension in bytes of the content file
35  * <li>an installation program: the name of the program to execute during
36  * the installation process
37  * <li>an uninstallation program: the name of the program to execute during
38  * the uninstallation process
39  * <li>a flag for indicate if the installation process of this version require
40  * the uninstallation process of the previous version
41  * </ul>
42  *
43  * @version $Id: AssetVersion.java,v 1.3 2005/01/19 11:18:36 fabius Exp $
44  * @author Stefano Nichele
45  */

46
47 public class AssetVersion {
48
49     // --------------------------------------------------------------- Constants
50

51     // The following contants are used for create a Map from a AssetVersion
52
// and for to represent a AssetVersion in Map
53
public static final String JavaDoc PROPERTY_VERSION = "version";
54     public static final String JavaDoc PROPERTY_RELEASE_DATE = "release_date";
55     public static final String JavaDoc PROPERTY_RELEASE_NOTES = "release_notes";
56     public static final String JavaDoc PROPERTY_URL = "url";
57     public static final String JavaDoc PROPERTY_SIZE_ASSET_FILE = "size_asset_file";
58     public static final String JavaDoc PROPERTY_INSTALL_PROGRAM = "install_program";
59     public static final String JavaDoc PROPERTY_UNINSTALL_PROGRAM = "uninstall_program";
60     public static final String JavaDoc PROPERTY_NEED_UNINSTALL_PREV = "need_uninstall_prev";
61
62     /**
63      * version of the AssetVersion
64      */

65     private String JavaDoc version;
66
67     /**
68      * Sets property
69      * @param version
70      * description: version of the AssetVersion
71      * displayName: version
72      */

73     public void setVersion(String JavaDoc version) {
74         this.version = version;
75     }
76
77     /**
78      * Returns property version
79      */

80     public String JavaDoc getVersion() {
81         return version;
82     }
83
84     /**
85      * release date of the AssetVersion
86      */

87     private String JavaDoc releaseDate;
88
89     /**
90      * Sets property
91      * @param releaseDate
92      * description: release date of the AssetVersion
93      * displayName: releaseDate
94      */

95     public void setReleaseDate(String JavaDoc releaseDate) {
96         this.releaseDate = releaseDate;
97     }
98
99     /**
100      * Returns property releaseDate
101      */

102     public String JavaDoc getReleaseDate() {
103         return releaseDate;
104     }
105
106     /**
107      * release notes of the AssetVersion
108      */

109     private String JavaDoc releaseNotes;
110
111     /**
112      * Sets property
113      * @param releaseNotes
114      * description: release notes of the AssetVersion
115      * displayName: releaseNotes
116      */

117     public void setReleaseNotes(String JavaDoc releaseNotes) {
118         this.releaseNotes = releaseNotes;
119     }
120
121     /**
122      * Returns property releaseNotes
123      */

124     public String JavaDoc getReleaseNotes() {
125         return releaseNotes;
126     }
127
128     /**
129      * Url of the file of the AssetVersion.
130      * <p>It's the url from which to download the asset file during the installation process
131      */

132     private String JavaDoc url;
133
134     /**
135      * Sets property
136      * @param url
137      * description: Url of the file of the AssetVersion
138      * displayName: url
139      */

140     public void setUrl(String JavaDoc url) {
141           this.url = url;
142     }
143
144     /**
145      * Returns property url
146      */

147     public String JavaDoc getUrl() {
148         return url;
149     }
150
151     /**
152      * Installation program of the AssetVersion.
153      * <p>Name of the program to execute during the installation process
154      */

155     private String JavaDoc installProgram;
156
157     /**
158      * Sets property BooleanProperty
159      *
160      * @param installProgram
161      * description: installation program of the AssetVersion.
162      * displayName:installProgram **/

163     public void setInstallProgram(String JavaDoc installProgram) {
164         this.installProgram = installProgram;
165     }
166
167     /**
168      * Returns property installProgram
169      */

170     public String JavaDoc getInstallProgram() {
171         return installProgram;
172     }
173
174     /**
175      * Uninstallation program of the AssetVersion.
176      * <p>Name of the program to execute during the uninstallation process
177      */

178     private String JavaDoc uninstallProgram;
179
180     /**
181      * Sets property BooleanProperty
182      *
183      * @param uninstallProgram
184      * description: installation program of the AssetVersion.
185      * displayName:iunnstallProgram **/

186     public void setUninstallProgram(String JavaDoc uninstallProgram) {
187         this.uninstallProgram = uninstallProgram;
188     }
189
190     /**
191      * Returns property uninstallProgram
192      */

193     public String JavaDoc getUninstallProgram() {
194         return uninstallProgram;
195     }
196
197     /**
198      * Flag for indicate if the installation process of this version
199      * require the uninstallation of the previous version
200      */

201     private String JavaDoc needUninstallPrev;
202
203     /**
204      * Sets property
205      * @param needUninstallPrev
206      * description: Flag for indicate if the installation process of this
207      * version require the uninstallation process of the previous version
208      * displayName: needUninstallPrev
209      */

210     public void setNeedUninstallPrev(String JavaDoc needUninstallPrev) {
211         this.needUninstallPrev = needUninstallPrev;
212     }
213
214     /**
215      * Returns property needUninstallPrev
216      */

217     public String JavaDoc getNeedUninstallPrev() {
218         return needUninstallPrev;
219     }
220
221     /**
222      * Dimension of the content file
223      */

224     private int sizeContentFile;
225
226     /**
227      * Sets property
228      * @param sizeContentFile
229      * description: dimension of the content file
230      * displayName: sizeContentFile
231      */

232     public void setSizeContentFile(int sizeContentFile) {
233         this.sizeContentFile = sizeContentFile;
234     }
235
236     /**
237      * Returns property sizeContentFile
238      */

239     public int getSizeContentFile() {
240         return sizeContentFile;
241     }
242
243
244     // ------------------------------------------------------------- Constructor
245

246     /**
247      * Constructs a AssetVersion with the values contained in the given Map
248      */

249     public AssetVersion(Map JavaDoc values) {
250
251         setVersion((String JavaDoc)values.get(PROPERTY_VERSION));
252         setReleaseDate((String JavaDoc)values.get(PROPERTY_RELEASE_DATE));
253         setReleaseNotes((String JavaDoc)values.get(PROPERTY_RELEASE_NOTES));
254         setUrl((String JavaDoc)values.get(PROPERTY_URL));
255
256         Object JavaDoc obj = values.get(PROPERTY_SIZE_ASSET_FILE);
257         if (obj!=null) {
258             try {
259                 this.sizeContentFile = Integer.parseInt(obj.toString());
260             } catch (NumberFormatException JavaDoc e) {
261                 this.sizeContentFile = 0;
262             }
263         }
264
265         this.installProgram = (String JavaDoc)values.get(PROPERTY_INSTALL_PROGRAM);
266         this.uninstallProgram = (String JavaDoc)values.get(PROPERTY_INSTALL_PROGRAM);
267         this.needUninstallPrev = (String JavaDoc)values.get(PROPERTY_NEED_UNINSTALL_PREV);
268     }
269
270
271     /**
272      * Returns a representation of a AssetVersion in Map
273      * @return the Map representation
274      */

275     public Map JavaDoc toMap() {
276         Map JavaDoc map = new HashMap JavaDoc();
277
278         map.put(PROPERTY_VERSION,getVersion());
279         map.put(PROPERTY_RELEASE_DATE,getReleaseDate());
280         map.put(PROPERTY_RELEASE_NOTES,getReleaseNotes());
281         map.put(PROPERTY_URL,getUrl());
282         map.put(PROPERTY_SIZE_ASSET_FILE,""+getSizeContentFile());
283         map.put(PROPERTY_INSTALL_PROGRAM,getInstallProgram());
284         map.put(PROPERTY_NEED_UNINSTALL_PREV,getNeedUninstallPrev());
285         return map;
286     }
287
288     //---------------------------------------------------
289
// Overrides java.lang.Object method
290
//---------------------------------------------------
291

292     public String JavaDoc toString() {
293         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("\tAsset version: \n");
294
295         sb.append("\t\tVersion: ");
296         sb.append(getVersion());
297         sb.append("\n\t\tRelease date: ");
298         sb.append( new java.util.Date JavaDoc(Long.parseLong(getReleaseDate())));
299         sb.append(" (");
300         sb.append(getReleaseDate());
301         sb.append(")");
302         sb.append("\n\t\tRelease notes: ");
303         sb.append(getReleaseNotes());
304         sb.append("\n\t\tAsset file: ");
305         sb.append(getUrl());
306         sb.append("\n\t\tSize Asset file: ");
307         sb.append(getSizeContentFile() );
308         sb.append("\n\t\tInstall program: ");
309         sb.append(getInstallProgram());
310         sb.append("\n\t\tNeed uninstall prev: ");
311         sb.append(getNeedUninstallPrev());
312
313         return sb.toString();
314     }
315
316
317 }
Popular Tags