KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > builder > VAIProductModel


1 /*
2  * $RCSfile: VAIProductModel.java,v $
3  * @modification $Date: 2001/09/28 19:27:49 $
4  * @version $Id: VAIProductModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
5  *
6  */

7
8 package com.memoire.vainstall.builder;
9
10 import com.memoire.vainstall.builder.event.*;
11 import com.memoire.vainstall.builder.util.*;
12
13 import java.util.*;
14
15 import javax.swing.DefaultListModel JavaDoc;
16 import javax.swing.event.EventListenerList JavaDoc;
17
18 /**
19  * This is a VAIProduct data model
20  *
21  * @see javax.swing.event.EventListenerList
22  *
23  * @author Henrik Falk
24  * @version $Id: VAIProductModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
25  */

26 public class VAIProductModel {
27
28     /**
29      * The list of listenere that are interested in changes in
30      * the data model
31      */

32     EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
33
34     /**
35      * The persistance class for this model
36      */

37     ProductPersisterInterface productPersister;
38
39     /**
40      * Flag that indicated whether the data model needs to be saved
41      */

42     boolean isDirty = false;
43
44     /**
45      * Master list of required fields/attributes for a product
46      * before an installation package can be generated
47      */

48     Hashtable masterRequiredList = new Hashtable();
49
50     /**
51      * List of required fields/attributes for a product
52      * which still needs to be 'resolved'
53      * before an installation package can be generated
54      */

55     Hashtable requiredList = new Hashtable();
56
57     DefaultListModel JavaDoc requiredListModel = new DefaultListModel JavaDoc();
58
59     /**
60      * list of properties in the format <name,String value>
61      */

62     Hashtable propertyList = new Hashtable();
63
64     /**
65      *
66      */

67      LinkedList stepsList = new LinkedList();
68
69     /**
70      *
71      */

72      LinkedList targetList = new LinkedList();
73
74     /**
75      *
76      */

77      LinkedList languageList = new LinkedList();
78
79     /**
80      * Default constructor
81      */

82     public VAIProductModel() {
83         super();
84
85         try {
86             if( System.getProperty("java.version").indexOf("1.4.") != -1 ) {
87                 productPersister = (ProductPersisterInterface)Class.forName("com.memoire.vainstall.builder.util.JavaProductPersister").newInstance();
88             } else {
89                 productPersister = (ProductPersisterInterface)Class.forName("com.memoire.vainstall.builder.util.NanoProductPersister").newInstance();
90             }
91
92             productPersister.initialize(this);
93
94         // add proper exception handling
95
} catch (InstantiationException JavaDoc exc) {
96         } catch (ClassNotFoundException JavaDoc exc) {
97         } catch (IllegalAccessException JavaDoc exc) {
98         }
99
100         buildRequiredFieldsList();
101     }
102
103     /**
104      * Returns whether the data model needs to be saved or not.
105      * @return true if the datamodel needs to be saved
106      */

107     public boolean isDirty() {
108         return isDirty;
109     }
110
111     /**
112      * @param e VAIProductEvent
113      */

114     public void fireVAIProductEvent(VAIProductEvent e) {
115
116         // guaranteed to return a non-null array
117
Object JavaDoc[] listeners = listenerList.getListenerList();
118
119         // process the listeners last to first, notifying
120
// those that are interested in this event
121
for (int i = listeners.length - 2; i >= 0; i -= 2) {
122             if (listeners[i] == com.memoire.vainstall.builder.event.VAIProductListener.class) {
123                  ((com.memoire.vainstall.builder.event.VAIProductListener)listeners[i+1]).productChanged(e);
124             }
125         }
126     }
127
128     /**
129      * @param l com.memoire.vainstall.builder.event.VAIProductListener
130      */

131     public void addVAIProductListener(com.memoire.vainstall.builder.event.VAIProductListener l) {
132         listenerList.add(com.memoire.vainstall.builder.event.VAIProductListener.class,l);
133     }
134
135     /**
136      * @param l com.memoire.vainstall.builder.event.VAIProductListener
137      */

138     public void removeVAIProductListener(com.memoire.vainstall.builder.event.VAIProductListener l) {
139         listenerList.remove(com.memoire.vainstall.builder.event.VAIProductListener.class,l);
140     }
141
142     /**
143      * Load project data from datastore
144      * @throws com.memoire.vainstall.builder.util.VAIBuilderException
145      */

146     public void load() throws VAIBuilderException {
147
148         productPersister.load();
149
150         isDirty = false;
151         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_LOADED));
152     }
153
154     /**
155      * Store project data in datastore
156      * @throws com.memoire.vainstall.builder.util.VAIBuilderException
157      */

158     public void save() throws VAIBuilderException {
159         productPersister.save();
160
161         isDirty = false;
162
163         if(requiredList.size() == 0) {
164             fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_MET));
165         }
166
167         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_SAVED));
168     }
169
170     /**
171      * Returns the name of the product
172      * @return The name of the product
173      */

174     public String JavaDoc getProductName() {
175         return (String JavaDoc)getPropertyList().get("vainstall.product.name");
176     }
177
178     /**
179      * Set the product name
180      * @param productName The name of the product
181      */

182     public void setProductName(String JavaDoc value) {
183         if(value.equals(getProductName()) == true) {
184             return;
185         }
186         if (value != null) {
187             getPropertyList().put("vainstall.product.name", value);
188         } else {
189             getPropertyList().remove("vainstall.product.name");
190         }
191
192         isDirty = true;
193         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTNAME_CHANGED));
194         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
195     }
196
197     /**
198      * Returns the version of the product
199      * @return The version of the product
200      */

201     public String JavaDoc getProductVersion() {
202         return (String JavaDoc)getPropertyList().get("vainstall.product.version");
203     }
204
205     /**
206      * Set the product version
207      * @param productVersion The version of the product
208      */

209     public void setProductVersion(String JavaDoc value) {
210         if(value.equals(getProductVersion()) == true) {
211             return;
212         }
213         if (value != null) {
214             getPropertyList().put("vainstall.product.version", value);
215         } else {
216             getPropertyList().remove("vainstall.product.version");
217         }
218
219         isDirty = true;
220         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
221         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTVERSION_CHANGED));
222     }
223
224     /**
225      * Returns the the product work directory
226      * @return The product work directory
227      */

228     public String JavaDoc getProductDirectory() {
229         return (String JavaDoc)getPropertyList().get("vainstall.product.directory");
230     }
231
232     /**
233      * Set the product work directory
234      * @param productDirectory The work directory of the project
235      */

236     public void setProductDirectory(String JavaDoc value) {
237         if(value.equals(getProductDirectory()) == true) {
238             return;
239         }
240         if (value != null) {
241             getPropertyList().put("vainstall.product.directory", value);
242         } else {
243             getPropertyList().remove("vainstall.product.directory");
244         }
245
246         isDirty = true;
247         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
248         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTDIRECTORY_CHANGED));
249     }
250
251     public String JavaDoc getProductType() {
252         return (String JavaDoc)getPropertyList().get("vainstall.product.type");
253     }
254
255     public void setProductType(String JavaDoc value) {
256         if(value.equals(getProductType()) == true) {
257             return;
258         }
259         if (value != null) {
260             getPropertyList().put("vainstall.product.type", value);
261         } else {
262             getPropertyList().remove("vainstall.product.type");
263         }
264
265         isDirty = true;
266         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
267         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
268     }
269
270     private void buildRequiredFieldsList() {
271
272         ProductRequirement requirement = null;
273
274         // Name of install class
275
// vainstall.archive.installClassName
276
requirement = new ProductRequirement("Install Filename","<html><b><font color=black size=7><center>Install Filename:</center></font></b><br>The name of the install file without file extension.</html>");
277         masterRequiredList.put("Install Filename",requirement);
278         requiredList.put("Install Filename",requirement);
279         getRequiredListModel().addElement(requirement);
280
281         // Required steps for an install
282
requirement = new ProductRequirement("Required Steps","<html><b><font color=black size=7><center>Required Steps:</center></font></b><br>Required steps who needs configured for an installation package.</html>");
283         masterRequiredList.put("Required Steps",requirement);
284         requiredList.put("Required Steps",requirement);
285         getRequiredListModel().addElement(requirement);
286 /*
287         // Required steps for an install
288         requirement = new ProductRequirement("Required Steps","<html><b><font color=black size=7><center>Required Steps:</center></font></b><br>Required steps who needs configured for an installation package.</html>");
289         masterRequiredList.put("Required Steps",requirement);
290         requiredList.put("Required Steps",requirement);
291         getRequiredListModel().addElement(requirement);
292 */

293     }
294
295     public Hashtable getRequiredList() {
296         return requiredList;
297     }
298
299     public DefaultListModel JavaDoc getRequiredListModel() {
300         return requiredListModel;
301     }
302
303     public void addRequirement(String JavaDoc name) {
304         Object JavaDoc obj = masterRequiredList.get(name);
305         if (obj != null) {
306             requiredList.put(name,obj);
307             getRequiredListModel().addElement(obj);
308
309             fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_NOTMET));
310         }
311     }
312
313     public void removeRequirement(String JavaDoc name) {
314
315         ProductRequirement req = (ProductRequirement)requiredList.remove(name);
316         if (req != null) {
317             try {
318                 if(getRequiredListModel().contains(req) == true) {
319                     getRequiredListModel().removeElement(req);
320                 }
321             } catch(Exception JavaDoc exc) {
322                // Due to bug (?) in 1.4beta. OK, fixed
323
// System.out.println(exc.getMessage());
324
}
325         }
326
327         if(requiredList.size() == 0) {
328             fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_MET));
329         }
330     }
331
332     /**
333      * Convenience method to access properties directly
334      * @return a list of builder properties
335      */

336     public Hashtable getPropertyList() {
337         return propertyList;
338     }
339
340     public void putProperty(String JavaDoc name, String JavaDoc value) {
341         if (getPropertyList().containsKey(name) == false) {
342             getPropertyList().put(name,value);
343         } else {
344             if (((String JavaDoc)getPropertyList().get(name)).equals(value) == true ||
345                 value.length() == 0) {
346                 return;
347             } else {
348                 getPropertyList().put(name,value);
349             }
350         }
351         isDirty = true;
352         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
353         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,name));
354     }
355
356     public String JavaDoc getProperty(String JavaDoc name) {
357         return (String JavaDoc)getPropertyList().get(name);
358     }
359
360     public void removeProperty(String JavaDoc name) {
361         if (getPropertyList().containsKey(name) == false) {
362             return;
363         }
364         getPropertyList().remove(name);
365         isDirty = true;
366         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
367         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,name));
368     }
369
370     public LinkedList getStepsList() {
371         return stepsList;
372     }
373
374     /**
375      * Wee need to do something in the future because some
376      * new step types could be added more than once
377      */

378     public void addStep(String JavaDoc type) {
379         getStepsList().add(type);
380         isDirty = true;
381         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
382     }
383
384     public String JavaDoc getPackageName() {
385         return (String JavaDoc)getPropertyList().get("vainstall.archiver.package.name");
386     }
387
388     public void setPackageName(String JavaDoc value) {
389         if(value.equals(getPackageName()) == true) {
390             return;
391         }
392         if (value != null) {
393             getPropertyList().put("vainstall.archiver.package.name", value);
394         } else {
395             getPropertyList().remove("vainstall.archiver.package.name");
396         }
397
398         isDirty = true;
399         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
400         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
401     }
402
403     public String JavaDoc getLicenseName() {
404         return (String JavaDoc)getPropertyList().get("vainstall.archiver.license.name");
405     }
406
407     public void setLicenseName(String JavaDoc value) {
408         if(value.equals(getLicenseName()) == true) {
409             return;
410         }
411         if (value != null) {
412             getPropertyList().put("vainstall.archiver.license.name", value);
413         } else {
414             getPropertyList().remove("vainstall.archiver.license.name");
415         }
416
417         isDirty = true;
418         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
419         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
420     }
421
422     public String JavaDoc getLicenseEncoding() {
423         return (String JavaDoc)getPropertyList().get("vainstall.archiver.license.encoding");
424     }
425
426     public void setLicenseEncoding(String JavaDoc value) {
427         if(value.equals(getLicenseEncoding()) == true) {
428             return;
429         }
430         if (value != null) {
431             getPropertyList().put("vainstall.archiver.license.encoding", value);
432         } else {
433             getPropertyList().remove("vainstall.archiver.license.encoding");
434         }
435
436         isDirty = true;
437         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
438         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
439     }
440
441     public String JavaDoc getReadmeName() {
442         return (String JavaDoc)getPropertyList().get("vainstall.archiver.readme.name");
443     }
444
445     public void setReadmeName(String JavaDoc value) {
446         if(value.equals(getReadmeName()) == true) {
447             return;
448         }
449         if (value != null) {
450             getPropertyList().put("vainstall.archiver.readme.name", value);
451         } else {
452             getPropertyList().remove("vainstall.archiver.readme.name");
453         }
454
455         isDirty = true;
456         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
457         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
458     }
459
460     public String JavaDoc getReadmeEncoding() {
461         return (String JavaDoc)getPropertyList().get("vainstall.archiver.readme.encoding");
462     }
463
464     public void setReadmeEncoding(String JavaDoc value) {
465         if(value.equals(getReadmeEncoding()) == true) {
466             return;
467         }
468         if (value != null) {
469             getPropertyList().put("vainstall.archiver.readme.encoding", value);
470         } else {
471             getPropertyList().remove("vainstall.archiver.readme.encoding");
472         }
473
474         isDirty = true;
475         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
476         fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
477     }
478
479     public LinkedList getTargetList() {
480         return targetList;
481     }
482
483     public void addTarget(String JavaDoc value) {
484         if (targetList.contains(value) == false) {
485             targetList.add(value);
486             isDirty = true;
487             fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
488         }
489     }
490
491     public void removeTarget(String JavaDoc value) {
492         if (targetList.contains(value) == true) {
493             targetList.remove(value);
494             isDirty = true;
495             fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
496         }
497     }
498
499     public LinkedList getLanguageList() {
500         return languageList;
501     }
502
503     public void addLanguage(String JavaDoc value) {
504         if (languageList.contains(value) == false) {
505             languageList.add(value);
506             isDirty = true;
507             fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
508         }
509     }
510
511     public void removeLanguage(String JavaDoc value) {
512         if (languageList.contains(value) == true) {
513             languageList.remove(value);
514             isDirty = true;
515             fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
516         }
517     }
518
519 }
520
Popular Tags