01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with this
04: * work for additional information regarding copyright ownership. The ASF
05: * licenses this file to You under the Apache License, Version 2.0 (the
06: * "License"); you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14: * License for the specific language governing permissions and limitations under
15: * the License.
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: private Map portletEntityToWindow = new HashMap();
38: private Map windows = new HashMap();
39:
40: public Set getAllPortletWindows() {
41: Set windowSet = new HashSet();
42:
43: Iterator itr = windows.entrySet().iterator();
44: while (itr.hasNext()) {
45: Map.Entry entry = (Entry) itr.next();
46: windowSet.add((PortletWindow) entry.getValue());
47: }
48:
49: return windowSet;
50: }
51:
52: public PortletWindow getPortletWindow(String windowId) {
53: return (PortletWindow) windows.get(windowId);
54: }
55:
56: public PortletWindow getPortletWindowByEntityId(
57: String portletEntityId) {
58: if (portletEntityToWindow.containsKey(portletEntityId)) {
59: return (PortletWindow) windows
60: .get((String) portletEntityToWindow
61: .get(portletEntityId));
62: } else {
63: return null;
64: }
65: }
66:
67: public void putPortletWindow(PortletWindow window) {
68: windows.put(window.getId().toString(), window);
69: portletEntityToWindow.put(window.getPortletEntity().getId()
70: .toString(), window.getId().toString());
71:
72: }
73:
74: public void removePortletWindow(String windowId) {
75: PortletWindow window = (PortletWindow) windows.get(windowId);
76: if (window != null) {
77: windows.remove(windowId);
78: portletEntityToWindow.remove(window.getPortletEntity()
79: .getId().toString());
80: }
81:
82: }
83:
84: public void removePortletWindowByPortletEntityId(
85: String portletEntityId) {
86: PortletWindow window = getPortletWindowByEntityId(portletEntityId);
87: if (window != null) {
88: removePortletWindow(window.getId().toString());
89: }
90:
91: }
92: }
|