KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > bundlehandlers > BundleContainer


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

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

34 public class BundleContainer implements BundleInterface {
35
36     private ShareInfo shareinfo;
37
38     private BundleInterface activeBundle;
39
40     private HashMap JavaDoc versions = new HashMap JavaDoc();
41     
42     public BundleContainer(BundleInterface b) {
43         // its the first one so it has to be the best
44
this.activeBundle = b;
45
46         // also the first version so add it
47
BundleVersionContainer bvc=new BundleVersionContainer(b);
48         versions.put(b.getVersion(),bvc);
49     }
50
51
52     public boolean contains(String JavaDoc version,ProviderInterface provider) {
53         BundleVersionContainer vc=(BundleVersionContainer)versions.get(version);
54         if (vc!=null) {
55             return vc.contains(provider);
56         }
57         return false;
58     }
59
60
61     public boolean removeBundle(BundleInterface b) {
62         versions.remove(b.getVersion());
63         return true;
64     }
65
66     public int getBundleCount() {
67         return versions.size();
68     }
69
70     public boolean addBundle(BundleInterface b) {
71         BundleVersionContainer vc = (BundleVersionContainer)versions.get(b.getVersion());
72         // we allready have this verion, so maybe its a different provider
73
if (vc != null) {
74             vc.addBundle(b);
75         } else {
76             BundleVersionContainer bvc = new BundleVersionContainer(b);
77             versions.put(b.getVersion(),bvc);
78         }
79
80         // figure out if we have a new best version of this bundle
81
try {
82             int oldversion = Integer.parseInt(activeBundle.getVersion());
83             int newversion = Integer.parseInt(b.getVersion());
84             if (newversion > oldversion) {
85                 // so we have a newer version, make that the active one
86
activeBundle = b;
87             } else if (newversion == oldversion) {
88                 int oldbaseScore = activeBundle.getProvider().getBaseScore();
89                 int newbaseScore = b.getProvider().getBaseScore();
90                 if (newbaseScore > oldbaseScore) {
91                     activeBundle = b;
92                 }
93             }
94         } catch(Exception JavaDoc e) {};
95         return true;
96     }
97
98     public Iterator JavaDoc getNeededPackages() {
99         return activeBundle.getNeededPackages();
100     }
101
102     public List JavaDoc getRelatedPeople(String JavaDoc type) {
103         return activeBundle.getRelatedPeople(type);
104     }
105
106     public List JavaDoc getScreenshots() {
107         return activeBundle.getScreenshots();
108     }
109
110     public List JavaDoc getStarturls() {
111         return activeBundle.getStarturls();
112     }
113
114     public String JavaDoc getName() {
115         return activeBundle.getName();
116     }
117     
118     public String JavaDoc getVersion() {
119         return activeBundle.getVersion();
120     }
121
122     public String JavaDoc getState() {
123         return activeBundle.getState();
124     }
125
126     public boolean setState(String JavaDoc state) {
127         return activeBundle.setState(state);
128     }
129
130     public boolean install() {
131         return activeBundle.install();
132     }
133
134     public boolean uninstall() {
135         return activeBundle.uninstall();
136     }
137
138     public String JavaDoc getCreationDate() {
139         return activeBundle.getCreationDate();
140     }
141
142     public String JavaDoc getMaintainer() {
143         return activeBundle.getMaintainer();
144     }
145
146     public String JavaDoc getType() {
147         return activeBundle.getType();
148     }
149
150     public String JavaDoc getId() {
151         return activeBundle.getId();
152     }
153
154     public String JavaDoc getPath() {
155         return activeBundle.getPath();
156     }
157
158     public ProviderInterface getProvider() {
159         return activeBundle.getProvider();
160     }
161
162     public Iterator JavaDoc getVersions() {
163         return ((HashMap JavaDoc)versions.clone()).values().iterator();
164     }
165
166     public BundleInterface getVersion(String JavaDoc version,ProviderInterface provider) {
167         BundleVersionContainer bvc = (BundleVersionContainer)versions.get(version);
168         if (bvc != null) {
169             BundleInterface b = (BundleInterface)bvc.get(provider);
170             if (b != null) {
171                 return b;
172             } else {
173                 return null;
174             }
175         } else {
176             return null;
177         }
178     }
179
180
181     public BundleInterface getBundleByScore(String JavaDoc version) {
182         BundleVersionContainer bvc=(BundleVersionContainer)versions.get(version);
183         if (bvc!=null) {
184             return bvc.getBundleByScore();
185         }
186         return null;
187     }
188
189     public Iterator JavaDoc getInstallSteps() {
190         return activeBundle.getInstallSteps();
191     }
192
193     public Iterator JavaDoc getInstallSteps(int logid) {
194         return activeBundle.getInstallSteps(logid);
195     }
196
197     public void clearInstallSteps() {
198          activeBundle.clearInstallSteps();
199     }
200
201     public JarFile JavaDoc getJarFile() {
202         return activeBundle.getJarFile();
203     }
204
205     public JarFile JavaDoc getIncludedPackageJarFile(String JavaDoc packageid,String JavaDoc packageversion) {
206         return activeBundle.getIncludedPackageJarFile(packageid,packageversion);
207     }
208
209     public BufferedInputStream JavaDoc getJarStream() {
210         return activeBundle.getJarStream();
211     }
212
213     public boolean isShared() {
214         if (shareinfo != null) {
215             return true;
216         }
217         return false;
218     }
219
220     public ShareInfo getShareInfo() {
221         return shareinfo;
222     }
223
224     public void setShareInfo(ShareInfo shareinfo) {
225         this.shareinfo = shareinfo;
226     }
227
228     public void removeShare() {
229         this.shareinfo = null;
230     }
231
232
233     public String JavaDoc getDescription() {
234         return activeBundle.getDescription();
235     }
236     
237     public String JavaDoc getReleaseNotes() {
238         return activeBundle.getReleaseNotes();
239     }
240
241     public String JavaDoc getInstallationNotes() {
242         return activeBundle.getInstallationNotes();
243     }
244
245
246     public String JavaDoc getLicenseType() {
247         return activeBundle.getLicenseType();
248     }
249
250     public String JavaDoc getLicenseName() {
251         return activeBundle.getLicenseName();
252     }
253
254     public String JavaDoc getLicenseVersion() {
255         return activeBundle.getLicenseVersion();
256     }
257
258     public String JavaDoc getLicenseBody() {
259         return activeBundle.getLicenseBody();
260     }
261
262     public void setProgressBar(int stepcount) {
263         activeBundle.setProgressBar(stepcount);
264     }
265
266     public void increaseProgressBar() {
267         activeBundle.increaseProgressBar();
268     }
269
270     public void increaseProgressBar(int stepcount) {
271         activeBundle.increaseProgressBar(stepcount);
272     }
273
274    public int getProgressBarValue() {
275        return activeBundle.getProgressBarValue();
276    }
277
278    public int getPackageProgressBarValue() {
279        return activeBundle.getPackageProgressBarValue();
280    }
281
282 }
283
Popular Tags