KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dwr > SessionCreatorManager


1 /*
2  * Copyright (c) 2005 Your Corporation. All Rights Reserved.
3  */

4 package dwr;
5
6 import uk.ltd.getahead.dwr.CreatorManager;
7 import uk.ltd.getahead.dwr.Creator;
8 import uk.ltd.getahead.dwr.ExecutionContext;
9 import org.w3c.dom.Element JavaDoc;
10
11 import javax.servlet.http.HttpSession JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.Map JavaDoc;
14 import java.util.HashMap JavaDoc;
15
16 /**
17  * @author hengels
18  * @version $Revision: 1.2 $
19  */

20 public class SessionCreatorManager
21     implements CreatorManager
22 {
23     static ThreadLocal JavaDoc sessions = new ThreadLocal JavaDoc();
24     boolean debug;
25
26     public SessionCreatorManager() {
27     }
28
29     public boolean isDebug() {
30         return debug;
31     }
32
33     public void setDebug(boolean debug) {
34         this.debug = debug;
35     }
36
37     public void addCreatorType(String JavaDoc typename, Class JavaDoc clazz) {
38     }
39
40     public void addCreator(String JavaDoc type, String JavaDoc javascript, Element JavaDoc allower) {
41     }
42
43     public Collection JavaDoc getCreatorNames() {
44         Map JavaDoc map = getCreatorMap();
45         return map.keySet();
46     }
47
48     public Creator getCreator(String JavaDoc name) {
49         Map JavaDoc map = getCreatorMap();
50         return (Creator)map.get(name);
51     }
52
53     public void addCreator(String JavaDoc s, Object JavaDoc callable) {
54         Map JavaDoc map = getCreatorMap();
55         map.put(s, new SessionCreator(callable));
56     }
57
58     public void removeCreator(String JavaDoc scriptName) {
59         Map JavaDoc map = getCreatorMap();
60         map.remove(scriptName);
61     }
62
63     private Map JavaDoc getCreatorMap() {
64         HttpSession JavaDoc session = ExecutionContext.get().getSession();
65         Map JavaDoc map = (Map JavaDoc) session.getAttribute("CreatorMap");
66         if (map == null) {
67             map = new HashMap JavaDoc();
68             session.setAttribute("CreatorMap", map);
69         }
70         return map;
71     }
72 }
73
Popular Tags