KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > bundlehandlers > gui > Controller


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 package org.mmbase.applications.packaging.bundlehandlers.gui;
11
12 import java.util.ArrayList JavaDoc;
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.mmbase.applications.packaging.BundleManager;
18 import org.mmbase.applications.packaging.InstallManager;
19 import org.mmbase.applications.packaging.PackageManager;
20 import org.mmbase.applications.packaging.Person;
21 import org.mmbase.applications.packaging.ProviderManager;
22 import org.mmbase.applications.packaging.bundlehandlers.BundleInterface;
23 import org.mmbase.applications.packaging.bundlehandlers.BundleVersionContainer;
24 import org.mmbase.applications.packaging.packagehandlers.PackageInterface;
25 import org.mmbase.applications.packaging.providerhandlers.ProviderInterface;
26 import org.mmbase.bridge.Cloud;
27 import org.mmbase.bridge.CloudContext;
28 import org.mmbase.bridge.LocalContext;
29 import org.mmbase.bridge.NodeManager;
30 import org.mmbase.module.core.MMBase;
31 import org.mmbase.module.core.MMObjectNode;
32 import org.mmbase.module.core.VirtualBuilder;
33 import org.mmbase.util.logging.Logger;
34 import org.mmbase.util.logging.Logging;
35
36
37 /**
38  * @author Daniel Ockeloen
39  * @version $Id: guiController.java
40  */

41 public class Controller {
42
43     private static Logger log = Logging.getLoggerInstance(Controller.class);
44     private static Cloud cloud;
45     NodeManager manager;
46     CloudContext context;
47
48
49     public Controller() {
50         cloud = LocalContext.getCloudContext().getCloud("mmbase");
51
52         // hack needs to be solved
53
manager = cloud.getNodeManager("typedef");
54         if (manager == null) log.error("Can't access builder typedef");
55         context = LocalContext.getCloudContext();
56         if (!InstallManager.isRunning()) InstallManager.init();
57     }
58
59
60     public List JavaDoc getBundles() {
61         // signal action to for package discovery
62
ProviderManager.resetSleepCounter();
63
64         // get the current best bundles
65
Iterator JavaDoc bundles = BundleManager.getBundles();
66
67         List JavaDoc list = new ArrayList JavaDoc();
68         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
69
70         while (bundles.hasNext()) {
71             BundleInterface b = (BundleInterface)bundles.next();
72             MMObjectNode virtual = builder.getNewNode("admin");
73             virtual.setValue("id",b.getId());
74             virtual.setValue("name",b.getName());
75             virtual.setValue("type",b.getType());
76             virtual.setValue("maintainer",b.getMaintainer());
77             virtual.setValue("version",b.getVersion());
78             virtual.setValue("creation-date",b.getCreationDate());
79             virtual.setValue("state",b.getState());
80             list.add(virtual);
81         }
82         return list;
83     }
84
85
86     public List JavaDoc getBundleVersions(String JavaDoc id) {
87         // get the bundles of one id (all versions)
88
Iterator JavaDoc bundleversions = BundleManager.getBundleVersions(id);
89
90         List JavaDoc list = new ArrayList JavaDoc();
91         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
92
93         while (bundleversions.hasNext()) {
94             BundleVersionContainer bvc = (BundleVersionContainer)bundleversions.next();
95
96             Iterator JavaDoc bundles = bvc.getBundles();
97             while (bundles.hasNext()) {
98                 BundleInterface b = (BundleInterface)bundles.next();
99                 MMObjectNode virtual = builder.getNewNode("admin");
100                 virtual.setValue("id",b.getId());
101                 virtual.setValue("name",b.getName());
102                 virtual.setValue("type",b.getType());
103                 virtual.setValue("maintainer",b.getMaintainer());
104                 virtual.setValue("version",b.getVersion());
105                 virtual.setValue("state",b.getState());
106                 virtual.setValue("creation-date",b.getCreationDate());
107                 ProviderInterface provider=b.getProvider();
108                 if (provider != null) {
109                     virtual.setValue("provider",provider.getName());
110                 }
111                 list.add(virtual);
112             }
113         }
114         return list;
115     }
116
117
118     public List JavaDoc getBundleNeededPackages(String JavaDoc id,String JavaDoc wv,String JavaDoc newuser) {
119         // get the bundles of one id (all versions)
120
BundleInterface bundle = BundleManager.getBundle(id);
121         Iterator JavaDoc neededpackages = bundle.getNeededPackages();
122         List JavaDoc list = new ArrayList JavaDoc();
123         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
124
125         while (neededpackages.hasNext()) {
126             HashMap JavaDoc np = (HashMap JavaDoc)neededpackages.next();
127
128             MMObjectNode virtual = builder.getNewNode("admin");
129             virtual.setValue("name",(String JavaDoc)np.get("name"));
130             virtual.setValue("id",(String JavaDoc)np.get("id"));
131             virtual.setValue("type",(String JavaDoc)np.get("type"));
132             virtual.setValue("maintainer",(String JavaDoc)np.get("maintainer"));
133             virtual.setValue("version",(String JavaDoc)np.get("version"));
134             PackageInterface fp = PackageManager.getPackage((String JavaDoc)np.get("id"));
135             if (fp != null) {
136                 String JavaDoc state = fp.getState();
137                 String JavaDoc provider = (fp.getProvider()).getName();
138                 virtual.setValue("state",state);
139                 virtual.setValue("provider",provider);
140                 virtual.setValue("creation-date",fp.getCreationDate());
141                 virtual.setValue("description",fp.getDescription());
142                 virtual.setValue("releasenotes",fp.getReleaseNotes());
143                 virtual.setValue("installationnotes",fp.getInstallationNotes());
144                 virtual.setValue("licensename",fp.getLicenseName());
145                 virtual.setValue("licensetype",fp.getLicenseType());
146                 virtual.setValue("licenseversion",fp.getLicenseVersion());
147                 virtual.setValue("licensebody",fp.getLicenseBody());
148                 List JavaDoc l = fp.getRelatedPeople("initiators");
149                 if (l != null) virtual.setValue("initiators",getRelatedPeopleString(l,"initiators"));
150                 l = fp.getRelatedPeople("supporters");
151                 if (l != null) virtual.setValue("supporters",getRelatedPeopleString(l,"supporters"));
152                 l = fp.getRelatedPeople("developers");
153                 if (l != null) virtual.setValue("developers",getRelatedPeopleString(l,"developers"));
154                 l = fp.getRelatedPeople("contacts");
155                 if (l != null) virtual.setValue("contacts",getRelatedPeopleString(l,"contacts"));
156             } else {
157                 virtual.setValue("state","missing");
158                 virtual.setValue("provider","");
159             }
160             list.add(virtual);
161         }
162         return list;
163     }
164
165
166     public String JavaDoc getRelatedPeopleString(List JavaDoc people,String JavaDoc type) {
167         String JavaDoc body = "";
168         if (people != null) {
169             for (Iterator JavaDoc i = people.iterator(); i.hasNext();) {
170             Person pr = (Person)i.next();
171                 if (type.equals("initiators")) {
172                     body += "\t\t\t<initiator name=\""+pr.getName()+"\" company=\""+pr.getCompany()+"\" />\n";
173                 } else if (type.equals("developers")) {
174                     body += "\t\t\t<developer name=\""+pr.getName()+"\" company=\""+pr.getCompany()+"\" mailto=\""+pr.getMailto()+"\" />\n";
175                 } else if (type.equals("contacts")) {
176                     body += "\t\t\t<contact reason=\""+pr.getReason()+"\" name=\""+pr.getName()+"\" mailto=\""+pr.getMailto()+"\" />\n";
177                 } else if (type.equals("supporters")) {
178                     body += "\t\t\t<supporter company=\""+pr.getCompany()+"\" />\n";
179                 }
180             }
181         }
182         return body;
183     }
184
185 }
186
Popular Tags