KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > management > http > IndexServlet


1 package org.jfox.ioc.management.http;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collections JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Map JavaDoc;
7 import java.util.TreeMap JavaDoc;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpSession JavaDoc;
10
11 import org.apache.velocity.context.Context;
12 import org.jfox.ioc.ComponentMeta;
13 import org.jfox.ioc.Registry;
14
15 /**
16  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
17  */

18
19 public class IndexServlet extends SuperServlet {
20
21     public String JavaDoc getTemplate() {
22         return "index.vm";
23     }
24
25     public void buildContext(HttpServletRequest JavaDoc request, Context ctx) throws Exception JavaDoc {
26
27         HttpSession JavaDoc session = request.getSession(true);
28         session.setAttribute("time",System.currentTimeMillis() + "");
29
30         Registry registry = getRegistry();
31
32         List JavaDoc<ComponentMeta> metas = registry.getAllComponentMetas();
33         Map JavaDoc<String JavaDoc,List JavaDoc> modules = new TreeMap JavaDoc<String JavaDoc,List JavaDoc>();
34         for(ComponentMeta meta : metas){
35             String JavaDoc module = meta.getModule();
36             String JavaDoc moduleKey = "<b>" + meta.getModuleDesc() + "</b> - "+ module;
37             if(modules.containsKey(moduleKey)){
38                 List JavaDoc list = (List JavaDoc)modules.get(moduleKey);
39                 list.add(meta);
40                 Collections.sort(list);
41             }
42             else {
43                 List JavaDoc list = new ArrayList JavaDoc();
44                 list.add(meta);
45                 modules.put(moduleKey,list);
46             }
47         }
48
49         ctx.put("title","Index View");
50         ctx.put("modules",modules);
51         ctx.put("moduleCounts",modules.size());
52         ctx.put("typeCounts",registry.countComponentTypes());
53         ctx.put("componentCounts",metas.size());
54     }
55
56     public static void main(String JavaDoc[] args) {
57
58     }
59 }
60
61
Popular Tags