1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed;
18
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Iterator;
22 import java.util.Map;
23 import java.util.Set;
24 import java.util.Map.Entry;
25
26 import org.apache.jetspeed.cache.PortletWindowCache;
27 import org.apache.pluto.om.window.PortletWindow;
28
29 /***
30 * This implementation of {@link PortletWindowCache} is to be used ONLY for testing purposes.
31 *
32 * @author <a href="mailto:scott.t.weaver@gmail.com">Scott T. Weaver</a>
33 *
34 */
35 public class HashMapWindowCache implements PortletWindowCache
36 {
37
38
39 private Map portletEntityToWindow = new HashMap();
40 private Map windows = new HashMap();
41
42 public Set getAllPortletWindows()
43 {
44 Set windowSet = new HashSet();
45
46 Iterator itr = windows.entrySet().iterator();
47 while(itr.hasNext())
48 {
49 Map.Entry entry = (Entry) itr.next();
50 windowSet.add((PortletWindow)entry.getValue());
51 }
52
53 return windowSet;
54 }
55
56 public PortletWindow getPortletWindow(String windowId)
57 {
58 return (PortletWindow) windows.get(windowId);
59 }
60
61 public PortletWindow getPortletWindowByEntityId(String portletEntityId)
62 {
63 if(portletEntityToWindow.containsKey(portletEntityId))
64 {
65 return (PortletWindow) windows.get((String) portletEntityToWindow.get(portletEntityId));
66 }
67 else
68 {
69 return null;
70 }
71 }
72
73 public void putPortletWindow(PortletWindow window)
74 {
75 windows.put(window.getId().toString(), window);
76 portletEntityToWindow.put(window.getPortletEntity().getId().toString(), window.getId().toString());
77
78 }
79
80 public void removePortletWindow(String windowId)
81 {
82 PortletWindow window = (PortletWindow) windows.get(windowId);
83 if(window != null)
84 {
85 windows.remove(windowId);
86 portletEntityToWindow.remove(window.getPortletEntity().getId().toString());
87 }
88
89 }
90
91 public void removePortletWindowByPortletEntityId(String portletEntityId)
92 {
93 PortletWindow window = getPortletWindowByEntityId(portletEntityId);
94 if(window != null)
95 {
96 removePortletWindow(window.getId().toString());
97 }
98
99 }
100 }