KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > controller > Status


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.services.controller;
66
67 import com.jcorporate.expresso.core.cache.CacheManager;
68 import com.jcorporate.expresso.core.controller.Block;
69 import com.jcorporate.expresso.core.controller.ControllerException;
70 import com.jcorporate.expresso.core.controller.ControllerRequest;
71 import com.jcorporate.expresso.core.controller.ControllerResponse;
72 import com.jcorporate.expresso.core.controller.DBController;
73 import com.jcorporate.expresso.core.controller.NonHandleableException;
74 import com.jcorporate.expresso.core.controller.Output;
75 import com.jcorporate.expresso.core.controller.ServletControllerRequest;
76 import com.jcorporate.expresso.core.controller.State;
77 import com.jcorporate.expresso.core.controller.Transition;
78 import com.jcorporate.expresso.core.db.DBConnection;
79 import com.jcorporate.expresso.core.db.DBConnectionPool;
80 import com.jcorporate.expresso.core.db.DBException;
81 import com.jcorporate.expresso.core.db.TypeMapper;
82 import com.jcorporate.expresso.core.dbobj.CacheStatEntry;
83 import com.jcorporate.expresso.core.dbobj.DBObject;
84 import com.jcorporate.expresso.core.misc.ConfigManager;
85 import com.jcorporate.expresso.core.misc.ConfigurationException;
86 import com.jcorporate.expresso.core.misc.CurrentLogin;
87 import com.jcorporate.expresso.core.misc.DateTime;
88 import com.jcorporate.expresso.core.misc.StringUtil;
89 import com.jcorporate.expresso.core.security.User;
90 import com.jcorporate.expresso.services.dbobj.DBObjLimit;
91 import com.jcorporate.expresso.services.dbobj.GroupMembers;
92 import com.jcorporate.expresso.services.dbobj.Setup;
93
94 import javax.servlet.ServletException JavaDoc;
95 import javax.servlet.http.Cookie JavaDoc;
96 import javax.servlet.http.HttpServletRequest JavaDoc;
97 import java.text.NumberFormat JavaDoc;
98 import java.text.SimpleDateFormat JavaDoc;
99 import java.util.ArrayList JavaDoc;
100 import java.util.Calendar JavaDoc;
101 import java.util.Collections JavaDoc;
102 import java.util.Date JavaDoc;
103 import java.util.Enumeration JavaDoc;
104 import java.util.Hashtable JavaDoc;
105 import java.util.Iterator JavaDoc;
106 import java.util.Locale JavaDoc;
107 import java.util.Map JavaDoc;
108 import java.util.TreeMap JavaDoc;
109
110
111 /**
112  * Status servlet shows some current information about the servlet
113  * system and it's database connections and server-side tasks
114  *
115  * @author Michael Nash
116  * @since Expresso 2 as a servlet Expresso 4 as a controller
117  */

118 public class Status
119         extends DBController {
120
121     /**
122      * Our constructor "declares" what states we handle
123      */

124     public Status() {
125         super();
126
127         State show = new State("show", "Show Status");
128         show.addOptionalParameter("contextName");
129         addState(show);
130         setInitialState("show");
131
132         State packages = new State("showPackages", "Show Installed Packages");
133         addState(packages);
134         this.setSchema(com.jcorporate.expresso.core.ExpressoSchema.class);
135     } /* Status() */
136
137     /**
138      * Shows the currently installed packages on the system
139      *
140      * @param request The controllerRequest object
141      * @param response The controllerResponse object
142      * @throws ControllerException upon Error
143      * @throws NonHandleableException upon Fatal Error
144      */

145     protected void runShowPackagesState(ControllerRequest request,
146                                         ControllerResponse response)
147             throws ControllerException, NonHandleableException {
148
149         showPackages(request, response);
150         showTransitions(request, response);
151     }
152
153
154     /**
155      * Display the status information
156      *
157      * @param request Standard request object
158      * @param response Standard response object
159      * @throws ControllerException If an uncaught exception occurs
160      * @throws NonHandleableException upon fatal error
161      */

162     protected void runShowState(ControllerRequest request,
163                                 ControllerResponse response)
164             throws ControllerException, NonHandleableException {
165         String JavaDoc displayContext = request.getParameter("contextName");
166         if (displayContext == null || displayContext.length() == 0) {
167             displayContext = "default";
168         }
169
170         /* The code below has been modified to comply with the new
171
172 named connection release. */

173         try {
174             String JavaDoc userName = request.getUser();
175             Output t = null;
176
177             if (userName == null) {
178                 t = new Output("general",
179                         response.getString("Status_at") +
180                         DateTime.getDateTimeString() +
181                         response.getString("_Not_logged_in._Logging_level_is_") +
182                         Setup.getValue(request.getDataContext(), "LogLevel"));
183             } else {
184                 Locale JavaDoc l = request.getLocale();
185                 String JavaDoc language = l.getLanguage();
186                 String JavaDoc country = l.getCountry();
187                 String JavaDoc dbDescrip = "";
188
189                 try {
190                     dbDescrip = StringUtil.notNull(ConfigManager.getContext(request.getDataContext()).getDescription());
191                 } catch (ConfigurationException ce) {
192                     throw new ControllerException(ce);
193                 }
194                 if (dbDescrip.equals("")) {
195                     dbDescrip = request.getDataContext();
196                 }
197
198                 Object JavaDoc[] args = {
199                     userName, dbDescrip, language + "/" + country
200                 };
201                 t = new Output("general",
202                         response.getString("Status_at") +
203                         DateTime.getDateTimeString() +
204                         response.getString("Logged_in_as", args));
205             }
206
207             response.add(t);
208
209             Block oneRow = null;
210
211             /* Now show the connection info from the connection pool */
212             showContextInformation(request, response, displayContext);
213
214
215
216             /* Now show any cookies the client has */
217             Block cookieTable = new Block("cookies");
218             cookieTable.setAttribute("table", "Y");
219             cookieTable.setDescription(response.getString("Cookies"));
220             cookieTable.setAttribute("header-row",
221                     response.getString("Name|Value"));
222
223             /* Normally, accessing the HttpServletRequest/Response objects is a very bad
224
225 * idea. The fact that this controller does it means that it is non-portable
226
227 * outside the servlet environment
228
229 */

230             ServletControllerRequest sr = (ServletControllerRequest) request;
231             HttpServletRequest JavaDoc hreq = (HttpServletRequest JavaDoc) sr.getServletRequest();
232             Cookie JavaDoc[] cookies = hreq.getCookies();
233             String JavaDoc name = null;
234             String JavaDoc value = null;
235
236             if (cookies != null) {
237                 for (int i = 0; i < cookies.length; i++) {
238                     oneRow = new Block();
239                     oneRow.setAttribute("row", "Y");
240                     name = StringUtil.notNull(cookies[i].getName());
241                     value = StringUtil.notNull(cookies[i].getValue());
242                     oneRow.add(new Output(name));
243                     oneRow.add(new Output(value));
244                     cookieTable.add(oneRow);
245                 } /* for each cookie */
246
247             } /* if cookies were not null */
248
249
250             response.add(cookieTable);
251             response.add(new Output("memory1",
252                     response.getString("Total_Memory_") + Runtime.getRuntime().totalMemory()));
253             response.add(new Output("memory2",
254                     response.getString("Free_Memory_") + Runtime.getRuntime().freeMemory()));
255             CacheManager.displayStatus();
256
257             /* Now show mappings to other databases (databases other
258 than default. */

259             Hashtable JavaDoc dbMapHash = ConfigManager.getOtherDBLocations();
260
261             if (dbMapHash == null) {
262                 response.add(new Output("No mappings to databases other "
263                         + "than the default database could be found. The DBOtherMap is empty."));
264             } else {
265                 Block mapTable = new Block("dbother");
266                 mapTable.setDescription("Mappings to Other Databases");
267                 mapTable.setAttribute("table", "Y");
268                 mapTable.setAttribute("header-row",
269                         "Context|DBObject Class Name|Database Mapping");
270
271                 if (dbMapHash.size() == 0) {
272                     response.add(new Output("No entries in DBOtherMap"));
273                 } else {
274                     response.add(mapTable);
275                 }
276
277                 String JavaDoc objectName = null;
278                 String JavaDoc dbMapping = null;
279
280                 for (Enumeration JavaDoc emap = dbMapHash.keys();
281                      emap.hasMoreElements();) {
282                     objectName = (String JavaDoc) emap.nextElement();
283                     java.util.StringTokenizer JavaDoc st = new java.util.StringTokenizer JavaDoc(objectName, "|");
284                     String JavaDoc contextName = st.nextToken();
285                     String JavaDoc dbObjName = st.nextToken();
286                     dbMapping = (String JavaDoc) dbMapHash.get(objectName);
287
288                     Block aRow = new Block("new row");
289                     aRow.setAttribute("row", "Y");
290                     aRow.add(new Output(contextName));
291                     aRow.add(new Output(dbObjName));
292                     aRow.add(new Output(dbMapping));
293                     mapTable.add(aRow);
294                 }
295             } // End of mappings to other Databases table.
296

297
298             /* Now see if we can get caching status from db object */
299             Map JavaDoc cacheStats = DBObject.getCacheStatsMap();
300
301             if (cacheStats == null) {
302                 response.add(new Output("Caching statistics not " + "currently available. Edit expresso-config.xml " +
303                         "to begin collecting cache statistics"));
304             } else {
305                 Block statsTable = new Block("dbstats");
306                 statsTable.setDescription("DB Object Statistics");
307                 statsTable.setAttribute("table", "Y");
308                 statsTable.setAttribute("header-row",
309                         "Object (adjust cache)|Hit %|Reads|Cache Hits|Cache Misses|Cache Size|DB/Context");
310
311                 if (cacheStats.size() == 0) {
312                     response.add(new Output("No entries in cache stats"));
313                 } else {
314                     response.add(statsTable);
315                 }
316
317                 double hits = 0;
318                 double misses = 0;
319                 double reads = 0;
320                 double perc = 0.0;
321
322                 NumberFormat JavaDoc numFormat = NumberFormat.getInstance();
323                 numFormat.setMaximumFractionDigits(0);
324                 numFormat.setGroupingUsed(true);
325                 NumberFormat JavaDoc percentFormat = NumberFormat.getPercentInstance();
326                 percentFormat.setMaximumFractionDigits(1);
327
328                 ArrayList JavaDoc list = new ArrayList JavaDoc(cacheStats.values());
329                 Collections.sort(list); // entries sort by hit rate
330
for (Iterator JavaDoc ee = list.iterator(); ee.hasNext();) {
331                     CacheStatEntry oneEntry = (CacheStatEntry) ee.next();
332                     if (oneEntry.getDataContext().equalsIgnoreCase(displayContext)) {
333                         reads = oneEntry.getReadCount();
334                         hits = oneEntry.getCacheHits();
335                         misses = oneEntry.getCacheMisses();
336                         perc = (hits / reads);
337
338                         Block aRow = new Block("new row");
339                         aRow.setAttribute("row", "Y");
340 // aRow.add(new Output(oneEntry.getDBObjName()));
341
Transition trans = new Transition(oneEntry.getDBObjName(), DBMaint.class, DBMaint.UPDATE);
342                         trans.addParam("key", oneEntry.getDBObjName());
343                         trans.addParam("dbobj", DBObjLimit.class.getName());
344                         aRow.add(trans);
345
346                         aRow.add(new Output("" + percentFormat.format(perc)));
347                         aRow.add(new Output("" + numFormat.format(reads)));
348                         aRow.add(new Output("" + numFormat.format(hits)));
349                         aRow.add(new Output("" + numFormat.format(misses)));
350
351                         DBObject oneObj = null;
352                         try {
353                             Class JavaDoc c = Class.forName(oneEntry.getDBObjName());
354                             oneObj = (DBObject) c.newInstance();
355                         } catch (ClassNotFoundException JavaDoc cn) {
356                             throw new ServletException JavaDoc("Database object '" +
357                                     oneEntry.getDBObjName() +
358                                     "' not found", cn);
359                         } catch (InstantiationException JavaDoc ie) {
360                             throw new ServletException JavaDoc("Database object '" +
361                                     oneEntry.getDBObjName() +
362                                     "' cannot be instantiated",
363                                     ie);
364                         } catch (IllegalAccessException JavaDoc iae) {
365                             throw new ServletException JavaDoc("llegal access loading " +
366                                     "Database object '" +
367                                     oneEntry.getDBObjName() +
368                                     "'", iae);
369                         }
370
371                         oneObj.setDataContext(oneEntry.getDataContext());
372                         aRow.add(new Output("" + oneObj.getCacheSize()));
373
374                         aRow.add(new Output(oneEntry.getDataContext()));
375                         statsTable.add(aRow);
376                     }
377                 }
378             }
379
380             Hashtable JavaDoc allSessions = ConfigManager.getCurrentLogins();
381             response.add(new Output("Currently there are " + allSessions.size() +
382                     " users connected"));
383
384             if (userName.equalsIgnoreCase(User.ADMIN_USER)) {
385                 Block userTable = new Block("User_Table");
386                 userTable.setAttribute("table", "Y");
387                 userTable.setAttribute("header-row",
388                         "User|Session|IP Address|Logged In At|DB/Context");
389                 userTable.setDescription("Logged In Users");
390
391                 CurrentLogin oneLogin = null;
392                 String JavaDoc oneSessionId = null;
393
394                 for (Enumeration JavaDoc cu = allSessions.keys();
395                      cu.hasMoreElements();) {
396                     oneSessionId = (String JavaDoc) cu.nextElement();
397                     oneLogin = (CurrentLogin) allSessions.get(oneSessionId);
398
399                     if (oneLogin != null) {
400                         oneRow = new Block();
401                         oneRow.setAttribute("row", "Y");
402                         if (oneLogin.getDBName().equalsIgnoreCase(displayContext)) {
403                             oneRow.add(new Output(oneLogin.getUserName()));
404                             oneRow.add(new Output(oneSessionId));
405                             oneRow.add(new Output(oneLogin.getIPAddress()));
406                             oneRow.add(new Output(new Date JavaDoc(oneLogin.getLogInTime()).toString()));
407                             oneRow.add(new Output(oneLogin.getDBName()));
408                             userTable.add(oneRow);
409                         }
410                     }
411                 }
412
413                 response.add(userTable);
414                 showTransitions(request, response);
415             }
416
417         } catch (Exception JavaDoc he) {
418             throw new ControllerException(he);
419         }
420     } /* doGet(HttpServletRequest, HttpServletResponse) */
421
422     /**
423      * Fill out the context information as s
424      *
425      * @param request The ControllerRequest object
426      * @param response The ControllerResponse Object
427      * @param contextName The data context to show the data for
428      * @throws ControllerException upon error
429      * @throws DBException upon data access error
430      */

431     protected void showContextInformation(ControllerRequest request,
432                                           ControllerResponse response, String JavaDoc contextName) throws ControllerException,
433             DBException {
434         /* One nested block in this block for each connection pool */
435         Block oneRow = null;
436         Block poolBlock = new Block("pools");
437         response.add(poolBlock);
438         String JavaDoc userName = request.getUser();
439
440         String JavaDoc dbDescrip = "";
441
442         try {
443             dbDescrip = StringUtil.notNull(ConfigManager.getContext(contextName).getDescription());
444         } catch (ConfigurationException ce) {
445             throw new ControllerException(ce);
446         }
447         if (dbDescrip.equals("")) {
448             dbDescrip = contextName;
449         }
450
451         Block thisPoolBlock = new Block("Block for connection pool " +
452                 contextName);
453         thisPoolBlock.setDescription(dbDescrip);
454         poolBlock.add(thisPoolBlock);
455
456         //Object[] args = { oneConfigKey };
457
//response.add(new Output(getString("Connection_Pool_DB", args)));
458
Block oneTable = new Block("connection pool table " +
459                 contextName + " database");
460         oneTable.setDescription("Connections for " + dbDescrip);
461         oneTable.setAttribute("table", "Y");
462
463         if (userName == null) {
464             userName = ("");
465         }
466         if (userName.equalsIgnoreCase(User.ADMIN_USER)) {
467             oneTable.setAttribute("header-row",
468                     response.getString("Connection_Number|Description|Status|Last_Touched|Last_SQL"));
469         } else {
470             oneTable.setAttribute("header-row",
471                     response.getString("Connection_Number|Description|Status|Last_Touched"));
472         }
473
474         DBConnectionPool currPool = DBConnectionPool.getInstance(contextName);
475         DBConnection oneConnection = null;
476         int connectionNumber = 0;
477         Calendar JavaDoc c = Calendar.getInstance();
478         SimpleDateFormat JavaDoc df = new SimpleDateFormat JavaDoc("E',' MMM d yyyy 'at' hh:mm:ss a");
479
480         for (Iterator JavaDoc e = currPool.getPoolList().iterator();
481              e.hasNext();) {
482             connectionNumber++;
483             oneConnection = (DBConnection) e.next();
484             oneRow = new Block();
485             oneRow.setAttribute("row", "Y");
486             oneRow.add(new Output("" + connectionNumber));
487             oneRow.add(new Output(oneConnection.getDescription()));
488
489             if (oneConnection.isAvailable()) {
490                 oneRow.add(new Output("AVAILABLE"));
491             } else {
492                 oneRow.add(new Output("IN USE"));
493             }
494             long l = oneConnection.getLastTouched();
495             c.setTime(new Date JavaDoc(l));
496
497             df.setCalendar(c);
498             oneRow.add(new Output(df.format(c.getTime())));
499
500             if (userName.equalsIgnoreCase(User.ADMIN_USER)) {
501                 oneRow.add(new Output(oneConnection.getSQL()));
502             }
503
504             oneTable.add(oneRow);
505         } /* for each connection in the default pool */
506
507         if (oneTable.getNumContents() > 0) {
508             thisPoolBlock.add(oneTable);
509         }
510
511         GroupMembers oneGroupMembers = new GroupMembers();
512         oneGroupMembers.setDataContext(request.getDataContext());
513         TypeMapper typeMapper = TypeMapper.getInstance(contextName);
514
515         Map JavaDoc expressoToSQLTypes = typeMapper.getExpressoToSQLMap();
516
517 // Hashtable expressoToSQLTypes = Schema.getExpressoToSQLMap(
518
// request.getDBName());
519
// Hashtable SQLtoDBMap = Schema.getSQLToDBMap(
520
// request.getDBName());
521

522         /* Now display the type map */
523         Block typeMapTable = new Block("Type_Map_Table" +
524                 contextName);
525         typeMapTable.setDescription("Type Mappings for " + dbDescrip);
526         typeMapTable.setAttribute("table", "Y");
527         typeMapTable.setAttribute("header-row",
528                 response.getString("mapHeader"));
529
530         String JavaDoc oneDatabaseTypeName = null;
531         String JavaDoc oneJavaSQLTypeName = null;
532         String JavaDoc oneExpressoTypeName = null;
533
534         for (Iterator JavaDoc en = expressoToSQLTypes.keySet().iterator();
535              en.hasNext();) {
536             oneExpressoTypeName = (String JavaDoc) en.next();
537
538
539 // oneDBTypeName = (String) SQLtoDBMap.get(oneSQLTypeName);
540
// if (oneDBTypeName == null) {
541
// oneDBTypeName = "Not Mapped";
542
// }
543
// oneExpressoTypeName = oneJavaSQLTypeName;
544
Integer JavaDoc sqlType = typeMapper.getExpressoToJava(oneExpressoTypeName.toLowerCase());
545             if (sqlType == null) {
546                 oneJavaSQLTypeName = "Not Mapped";
547                 oneDatabaseTypeName = "Not Mapped";
548             } else {
549                 oneJavaSQLTypeName = typeMapper.getNameForSQL(sqlType.intValue());
550                 if (oneJavaSQLTypeName == null) {
551                     oneJavaSQLTypeName = "No Name (" + sqlType + ")";
552                 }
553
554                 Map JavaDoc sqlToDB = typeMapper.getSQLToDBMap();
555
556                 oneDatabaseTypeName = (String JavaDoc) sqlToDB.get(sqlType);
557
558                 if (oneDatabaseTypeName == null) {
559                     oneDatabaseTypeName = "Not Mapped";
560                 }
561
562             }
563
564             oneRow = new Block();
565             oneRow.setAttribute("row", "Y");
566             oneRow.add(new Output(oneExpressoTypeName));
567             oneRow.add(new Output(oneJavaSQLTypeName));
568             oneRow.add(new Output(oneDatabaseTypeName));
569             typeMapTable.add(oneRow);
570         }
571
572         thisPoolBlock.add(typeMapTable);
573
574     }
575
576
577     /**
578      * Adds the transitions to switch between 'show' states
579      *
580      * @param request The controllerRequest object
581      * @param response the ControllerResponse object
582      * @throws ControllerException upon error
583      */

584     protected void showTransitions(ControllerRequest request, ControllerResponse response) throws ControllerException {
585         String JavaDoc currentState = StringUtil.notNull(request.getParameter(STATE_PARAM_KEY));
586         if (currentState.length() == 0) {
587             currentState = "show";
588         }
589         boolean showState = (currentState.equals("show"));
590         String JavaDoc currentContextName = request.getParameter("contextName");
591         if (currentContextName == null || currentContextName.length() == 0) {
592             currentContextName = "default";
593         }
594
595
596         for (Enumeration JavaDoc e = ConfigManager.getAllConfigKeys(); e.hasMoreElements();) {
597             String JavaDoc oneKey = (String JavaDoc) e.nextElement();
598             Transition t = new Transition("show" + oneKey, "Show '" + oneKey + "' Context Status", this.getClass(),
599                     "show");
600             t.addParam("contextName", oneKey);
601             if (showState) {
602                 if (currentContextName.equals(oneKey)) {
603                     t.setAttribute("current", "y");
604                 }
605             }
606             response.add(t);
607         }
608
609         Transition t = new Transition("showPackages", this);
610         t.setLabel("Show Installed Packages");
611         if (!showState) {
612             t.setAttribute("current", "y");
613         }
614         response.add(t);
615     }
616
617     /**
618      * Show all the packages that are installed
619      *
620      * @param request the ControllerRequest object
621      * @param response the ControllerResponse object
622      * @throws ControllerException upon error
623      */

624     protected void showPackages(ControllerRequest request, ControllerResponse response) throws ControllerException {
625         Map JavaDoc sortedMap = new TreeMap JavaDoc();
626         Block packageBlock = new Block("packages");
627         response.add(packageBlock);
628         packageBlock.add(new Output("Currently installed packages"));
629         Block packageTable = new Block("packageTable");
630         packageTable.setAttribute("table", "Y");
631         packageTable.setAttribute("header-row", "Name|Impl. Title|Impl. Vendor|" +
632                 "Impl. Version|Spec. Title|Spec. Vendor|Spec. Version|Is Sealed ");
633         packageBlock.add(packageTable);
634
635         Package JavaDoc packages[] = Package.getPackages();
636         if (packages == null) {
637             return;
638         }
639
640         for (int i = 0; i < packages.length; i++) {
641             sortedMap.put(packages[i].getName(), packages[i]);
642         }
643
644         for (Iterator JavaDoc i = sortedMap.keySet().iterator(); i.hasNext();) {
645             String JavaDoc packageKey = (String JavaDoc) i.next();
646             Package JavaDoc onePackage = (Package JavaDoc) sortedMap.get(packageKey);
647             Block oneRow = new Block();
648             packageTable.add(oneRow);
649             oneRow.setAttribute("row", "Y");
650
651             oneRow.add(new Output(StringUtil.notNull(onePackage.getName())));
652             oneRow.add(new Output(StringUtil.notNull(onePackage.getImplementationTitle())));
653             oneRow.add(new Output(StringUtil.notNull(onePackage.getImplementationVendor())));
654             oneRow.add(new Output(StringUtil.notNull(onePackage.getImplementationVersion())));
655             oneRow.add(new Output(StringUtil.notNull(onePackage.getSpecificationTitle())));
656             oneRow.add(new Output(StringUtil.notNull(onePackage.getSpecificationVendor())));
657             oneRow.add(new Output(StringUtil.notNull(onePackage.getSpecificationVersion())));
658             if (onePackage.isSealed()) {
659                 oneRow.add(new Output("YES"));
660             } else {
661                 oneRow.add(new Output("no"));
662             }
663
664         }
665
666     }
667
668
669     /**
670      * @return java.lang.String The Title of the controller
671      */

672     public String JavaDoc getTitle() {
673         return ("System Status");
674     }
675 } /* Status */
676
Popular Tags