01: /*
02: * Copyright (c) 2005 Your Corporation. All Rights Reserved.
03: */
04: package org.wings.plaf.css.dwr;
05:
06: import java.util.Collection;
07: import java.util.Map;
08: import java.util.WeakHashMap;
09:
10: import javax.servlet.http.HttpSession;
11:
12: import org.wings.session.SessionManager;
13:
14: import org.directwebremoting.extend.Creator;
15: import org.directwebremoting.extend.CreatorManager;
16: import org.directwebremoting.WebContextFactory;
17:
18: /**
19: * The callables are referenced weakly, only. Thus, most callables are destroyed as soon as there's
20: * no component's client property referencing them anymore.
21: *
22: * @author hengels
23: * @author raedler
24: */
25: public class SessionCreatorManager implements CreatorManager {
26:
27: public SessionCreatorManager() {
28: // empty
29: }
30:
31: /* (non-Javadoc)
32: * @see org.directwebremoting.CreatorManager#isDebug()
33: */
34: public boolean isDebug() {
35: return false;
36: }
37:
38: public void addCreatorType(String typename, String clazz) {
39: }
40:
41: public void addCreator(String typename, String scriptName,
42: Map params) throws InstantiationException,
43: IllegalAccessException, IllegalArgumentException {
44: }
45:
46: public Collection getCreatorNames() {
47: Map map = getCreatorMap();
48: return map.keySet();
49: }
50:
51: public Creator getCreator(String name) {
52: Map map = getCreatorMap();
53: SessionCreator creator = (SessionCreator) map.get(name);
54: if (SessionManager.getSession() == null)
55: SessionManager.setSession(creator.getSession());
56: return creator;
57: }
58:
59: public void setCreators(Map creators) {
60: }
61:
62: public void addCreator(String s, Creator creator) {
63: Map map = getCreatorMap();
64: map.put(s, creator);
65: }
66:
67: public void removeCreator(String scriptName) {
68: Map map = getCreatorMap();
69: map.remove(scriptName);
70: }
71:
72: private Map getCreatorMap() {
73: HttpSession session = WebContextFactory.get().getSession();
74: Map map = (Map) session.getAttribute("CreatorMap");
75: if (map == null) {
76: map = new WeakHashMap();
77: session.setAttribute("CreatorMap", map);
78: }
79: return map;
80: }
81: }
|