KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > packagehandlers > PackageContainer


1 /*
2  * This software is OSI Certified Open Source Software.
3  * OSI Certified is a certification mark of the Open Source Initiative.
4  * The license (Mozilla version 1.0) can be read at the MMBase site.
5  * See http://www.MMBase.org/license
6  */

7 package org.mmbase.applications.packaging.packagehandlers;
8
9 import java.io.BufferedInputStream JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.List JavaDoc;
14 import java.util.jar.JarFile JavaDoc;
15
16 import org.mmbase.applications.packaging.bundlehandlers.BundleInterface;
17 import org.mmbase.applications.packaging.installhandlers.installStep;
18 import org.mmbase.applications.packaging.providerhandlers.ProviderInterface;
19 import org.mmbase.applications.packaging.sharehandlers.ShareInfo;
20
21 /**
22  * The package container, this is a class that might confuse you at first
23  * its goal is to be a 'alias' for the 'best' available version of a package
24  * and a access point to all other versions of the package it has access too.
25  * This is the reason why it also implements the packageInterface to users
26  * can really use it as if it was a package. The reason for also keeping track
27  * of older or dubble versions of a package is that we can use this while
28  * upgrading (generate diffs) or having multiple 'download' places for a package * when a disk is broken or a server is down.
29  *
30  * @author Daniel Ockeloen (MMBased)
31  */

32 public class PackageContainer implements PackageInterface {
33
34     private ShareInfo shareinfo;
35
36     private PackageInterface activePackage;
37
38     private HashMap JavaDoc versions = new HashMap JavaDoc();
39
40
41     /**
42      *Constructor for the PackageContainer object
43      *
44      * @param p Description of the Parameter
45      */

46     public PackageContainer(PackageInterface p) {
47         // its the first one so it has to be the best
48
this.activePackage = p;
49
50         // also the first version so add it
51
PackageVersionContainer pvc = new PackageVersionContainer(p);
52         versions.put(p.getVersion(), pvc);
53     }
54
55
56     /**
57      * Description of the Method
58      *
59      * @param version Description of the Parameter
60      * @param provider Description of the Parameter
61      * @return Description of the Return Value
62      */

63     public boolean contains(String JavaDoc version, ProviderInterface provider) {
64         PackageVersionContainer vc = (PackageVersionContainer) versions.get(version);
65         if (vc != null) {
66             return (vc.contains(provider));
67         }
68         return (false);
69     }
70
71
72     /**
73      * Description of the Method
74      *
75      * @param p Description of the Parameter
76      * @return Description of the Return Value
77      */

78     public boolean removePackage(PackageInterface p) {
79         versions.remove(p.getVersion());
80         return true;
81     }
82
83
84     /**
85      * Gets the packageCount attribute of the PackageContainer object
86      *
87      * @return The packageCount value
88      */

89     public int getPackageCount() {
90         return versions.size();
91     }
92
93
94     /**
95      * Adds a feature to the Package attribute of the PackageContainer object
96      *
97      * @param p The feature to be added to the Package attribute
98      * @return Description of the Return Value
99      */

100     public boolean addPackage(PackageInterface p) {
101         PackageVersionContainer vc = (PackageVersionContainer) versions.get(p.getVersion());
102         // we allready have this verion, so maybe its a different provider
103
if (vc != null) {
104             vc.addPackage(p);
105         } else {
106             PackageVersionContainer pvc = new PackageVersionContainer(p);
107             versions.put(p.getVersion(), pvc);
108         }
109
110         // figure out if we have a new best version of this package
111
try {
112             int oldversion = Integer.parseInt(activePackage.getVersion());
113             int newversion = Integer.parseInt(p.getVersion());
114             if (newversion > oldversion) {
115                 // so we have a newer version, make that the active one
116
activePackage = p;
117             } else if (newversion == oldversion) {
118                 int oldbaseScore = activePackage.getProvider().getBaseScore();
119                 int newbaseScore = p.getProvider().getBaseScore();
120                 if (newbaseScore > oldbaseScore) {
121                     activePackage = p;
122                 }
123             }
124         } catch (Exception JavaDoc e) {}
125         ;
126
127         return true;
128     }
129
130
131     /**
132      * Gets the relatedPeople attribute of the PackageContainer object
133      *
134      * @param type Description of the Parameter
135      * @return The relatedPeople value
136      */

137     public List JavaDoc getRelatedPeople(String JavaDoc type) {
138         return activePackage.getRelatedPeople(type);
139     }
140
141
142     /**
143      * Gets the name attribute of the PackageContainer object
144      *
145      * @return The name value
146      */

147     public String JavaDoc getName() {
148         return activePackage.getName();
149     }
150
151
152     /**
153      * Gets the description attribute of the PackageContainer object
154      *
155      * @return The description value
156      */

157     public String JavaDoc getDescription() {
158         return activePackage.getDescription();
159     }
160
161
162     /**
163      * Gets the releaseNotes attribute of the PackageContainer object
164      *
165      * @return The releaseNotes value
166      */

167     public String JavaDoc getReleaseNotes() {
168         return activePackage.getReleaseNotes();
169     }
170
171
172     /**
173      * Gets the installationNotes attribute of the PackageContainer object
174      *
175      * @return The installationNotes value
176      */

177     public String JavaDoc getInstallationNotes() {
178         return activePackage.getInstallationNotes();
179     }
180
181
182     /**
183      * Gets the licenseType attribute of the PackageContainer object
184      *
185      * @return The licenseType value
186      */

187     public String JavaDoc getLicenseType() {
188         return activePackage.getLicenseType();
189     }
190
191
192     /**
193      * Gets the licenseName attribute of the PackageContainer object
194      *
195      * @return The licenseName value
196      */

197     public String JavaDoc getLicenseName() {
198         return activePackage.getLicenseName();
199     }
200
201
202     /**
203      * Gets the licenseVersion attribute of the PackageContainer object
204      *
205      * @return The licenseVersion value
206      */

207     public String JavaDoc getLicenseVersion() {
208         return activePackage.getLicenseVersion();
209     }
210
211
212     /**
213      * Gets the licenseBody attribute of the PackageContainer object
214      *
215      * @return The licenseBody value
216      */

217     public String JavaDoc getLicenseBody() {
218         return activePackage.getLicenseBody();
219     }
220
221
222     /**
223      * Gets the version attribute of the PackageContainer object
224      *
225      * @return The version value
226      */

227     public String JavaDoc getVersion() {
228         return activePackage.getVersion();
229     }
230
231
232     /**
233      * Gets the state attribute of the PackageContainer object
234      *
235      * @return The state value
236      */

237     public String JavaDoc getState() {
238         return activePackage.getState();
239     }
240
241
242     /**
243      * Sets the state attribute of the PackageContainer object
244      *
245      * @param state The new state value
246      * @return Description of the Return Value
247      */

248     public boolean setState(String JavaDoc state) {
249         return activePackage.setState(state);
250     }
251
252
253     /**
254      * Description of the Method
255      *
256      * @return Description of the Return Value
257      */

258     public boolean install() {
259         return activePackage.install();
260     }
261
262
263     /**
264      * Description of the Method
265      *
266      * @return Description of the Return Value
267      */

268     public boolean uninstall() {
269         return activePackage.uninstall();
270     }
271
272
273     /**
274      * Description of the Method
275      *
276      * @param step Description of the Parameter
277      * @return Description of the Return Value
278      */

279     public boolean install(installStep step) {
280         return activePackage.install(step);
281     }
282
283
284     /**
285      * Description of the Method
286      *
287      * @param step Description of the Parameter
288      * @return Description of the Return Value
289      */

290     public boolean uninstall(installStep step) {
291         return activePackage.uninstall(step);
292     }
293
294
295     /**
296      * Gets the creationDate attribute of the PackageContainer object
297      *
298      * @return The creationDate value
299      */

300     public String JavaDoc getCreationDate() {
301         return activePackage.getCreationDate();
302     }
303
304
305     /**
306      * Gets the maintainer attribute of the PackageContainer object
307      *
308      * @return The maintainer value
309      */

310     public String JavaDoc getMaintainer() {
311         return activePackage.getMaintainer();
312     }
313
314
315     /**
316      * Gets the type attribute of the PackageContainer object
317      *
318      * @return The type value
319      */

320     public String JavaDoc getType() {
321         return activePackage.getType();
322     }
323
324
325     /**
326      * Gets the id attribute of the PackageContainer object
327      *
328      * @return The id value
329      */

330     public String JavaDoc getId() {
331         return activePackage.getId();
332     }
333
334
335     /**
336      * Gets the path attribute of the PackageContainer object
337      *
338      * @return The path value
339      */

340     public String JavaDoc getPath() {
341         return activePackage.getPath();
342     }
343
344
345     /**
346      * Gets the provider attribute of the PackageContainer object
347      *
348      * @return The provider value
349      */

350     public ProviderInterface getProvider() {
351         return activePackage.getProvider();
352     }
353
354
355     /**
356      * Gets the versions attribute of the PackageContainer object
357      *
358      * @return The versions value
359      */

360     public Iterator JavaDoc getVersions() {
361         return ((HashMap JavaDoc)versions.clone()).values().iterator();
362     }
363
364
365     /**
366      * Gets the versionNumbers attribute of the PackageContainer object
367      *
368      * @return The versionNumbers value
369      */

370     public Iterator JavaDoc getVersionNumbers() {
371         ArrayList JavaDoc list = new ArrayList JavaDoc();
372         // loop all versions and filter the uniq numbers
373
Iterator JavaDoc e = getVersions();
374         while (e.hasNext()) {
375             PackageVersionContainer pvc = (PackageVersionContainer) e.next();
376             String JavaDoc ver = pvc.getVersion();
377             list.add(ver);
378         }
379         return list.iterator();
380     }
381
382
383     /**
384      * Gets the version attribute of the PackageContainer object
385      *
386      * @param version Description of the Parameter
387      * @param provider Description of the Parameter
388      * @return The version value
389      */

390     public PackageInterface getVersion(String JavaDoc version, ProviderInterface provider) {
391         PackageVersionContainer pvc = (PackageVersionContainer) versions.get(version);
392         if (pvc != null) {
393             PackageInterface p = (PackageInterface) pvc.get(provider);
394             if (p != null) {
395                 return p;
396             } else {
397                 return null;
398             }
399         } else {
400             return null;
401         }
402     }
403
404
405     /**
406      * Gets the packageByScore attribute of the PackageContainer object
407      *
408      * @param version Description of the Parameter
409      * @return The packageByScore value
410      */

411     public PackageInterface getPackageByScore(String JavaDoc version) {
412         PackageVersionContainer pvc = (PackageVersionContainer) versions.get(version);
413         if (pvc != null) {
414             return pvc.getPackageByScore();
415         }
416         return null;
417     }
418
419
420     /**
421      * Gets the installSteps attribute of the PackageContainer object
422      *
423      * @return The installSteps value
424      */

425     public Iterator JavaDoc getInstallSteps() {
426         return activePackage.getInstallSteps();
427     }
428
429
430     /**
431      * Gets the installSteps attribute of the PackageContainer object
432      *
433      * @param logid Description of the Parameter
434      * @return The installSteps value
435      */

436     public Iterator JavaDoc getInstallSteps(int logid) {
437         return activePackage.getInstallSteps(logid);
438     }
439
440
441     /**
442      * Description of the Method
443      */

444     public void clearInstallSteps() {
445         activePackage.clearInstallSteps();
446     }
447
448
449     /**
450      * Gets the jarFile attribute of the PackageContainer object
451      *
452      * @return The jarFile value
453      */

454     public JarFile JavaDoc getJarFile() {
455         return activePackage.getJarFile();
456     }
457
458
459     /**
460      * Gets the jarStream attribute of the PackageContainer object
461      *
462      * @return The jarStream value
463      */

464     public BufferedInputStream JavaDoc getJarStream() {
465         return activePackage.getJarStream();
466     }
467
468
469     /**
470      * Gets the parentBundle attribute of the PackageContainer object
471      *
472      * @return The parentBundle value
473      */

474     public BundleInterface getParentBundle() {
475         return activePackage.getParentBundle();
476     }
477
478
479     /**
480      * Sets the parentBundle attribute of the PackageContainer object
481      *
482      * @param parentbundle The new parentBundle value
483      */

484     public void setParentBundle(BundleInterface parentbundle) {
485         activePackage.setParentBundle(parentbundle);
486     }
487
488
489     /**
490      * Gets the shared attribute of the PackageContainer object
491      *
492      * @return The shared value
493      */

494     public boolean isShared() {
495         if (shareinfo != null) {
496             return (true);
497         }
498         return false;
499     }
500
501
502     /**
503      * Gets the shareInfo attribute of the PackageContainer object
504      *
505      * @return The shareInfo value
506      */

507     public ShareInfo getShareInfo() {
508         return shareinfo;
509     }
510
511
512     /**
513      * Sets the shareInfo attribute of the PackageContainer object
514      *
515      * @param shareinfo The new shareInfo value
516      */

517     public void setShareInfo(ShareInfo shareinfo) {
518         this.shareinfo = shareinfo;
519     }
520
521
522     /**
523      * Description of the Method
524      */

525     public void removeShare() {
526         this.shareinfo = null;
527     }
528
529
530     /**
531      * Gets the dependsFailed attribute of the PackageContainer object
532      *
533      * @return The dependsFailed value
534      */

535     public boolean getDependsFailed() {
536         return activePackage.getDependsFailed();
537     }
538
539
540     /**
541      * Description of the Method
542      *
543      * @param n Description of the Parameter
544      * @param provider Description of the Parameter
545      * @param name Description of the Parameter
546      * @param type Description of the Parameter
547      * @param maintainer Description of the Parameter
548      * @param version Description of the Parameter
549      * @param date Description of the Parameter
550      * @param path Description of the Parameter
551      */

552     public void init(org.w3c.dom.Node JavaDoc n, ProviderInterface provider, String JavaDoc name, String JavaDoc type, String JavaDoc maintainer, String JavaDoc version, String JavaDoc date, String JavaDoc path) {
553         activePackage.init(n, provider, name, type, maintainer, version, date, path);
554     }
555
556
557     /**
558      * Sets the progressBar attribute of the PackageContainer object
559      *
560      * @param stepcount The new progressBar value
561      */

562     public void setProgressBar(int stepcount) {
563         activePackage.setProgressBar(stepcount);
564     }
565
566
567     /**
568      * Description of the Method
569      */

570     public void increaseProgressBar() {
571         activePackage.increaseProgressBar();
572     }
573
574
575     /**
576      * Description of the Method
577      *
578      * @param stepcount Description of the Parameter
579      */

580     public void increaseProgressBar(int stepcount) {
581         activePackage.increaseProgressBar(stepcount);
582     }
583
584
585     /**
586      * Gets the progressBarValue attribute of the PackageContainer object
587      *
588      * @return The progressBarValue value
589      */

590     public int getProgressBarValue() {
591         return activePackage.getProgressBarValue();
592     }
593
594 }
595
596
Popular Tags