%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.cache.impl.EhPortletWindowCache |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * 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, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.cache.impl; |
|
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 | ||
25 | import net.sf.ehcache.Ehcache; |
|
26 | ||
27 | import org.apache.jetspeed.cache.CacheElement; |
|
28 | import org.apache.jetspeed.cache.PortletWindowCache; |
|
29 | import org.apache.pluto.om.entity.PortletEntity; |
|
30 | import org.apache.pluto.om.window.PortletWindow; |
|
31 | ||
32 | /** |
|
33 | * <p> |
|
34 | * EhPortletWindowCache |
|
35 | * </p> |
|
36 | * <p> |
|
37 | * Implementation of {@link PortletWindowCache} that is backed |
|
38 | * <a href="http://ehcache.sourceforge.net/">Ehcache</a>. |
|
39 | * </p> |
|
40 | * @author <a href="mailto:scott.t.weaver@gmail.com">Scott T. Weaver</a> |
|
41 | * |
|
42 | */ |
|
43 | 0 | public class EhPortletWindowCache extends EhCacheImpl implements PortletWindowCache { |
44 | ||
45 | /** Allows us to track {@link PortletWindow}s in cache by {@link PortletEntity#getId()}*/ |
|
46 | private Map portletEntityIdToEntityid; |
|
47 | ||
48 | ||
49 | public EhPortletWindowCache(Ehcache ehcache) |
|
50 | { |
|
51 | 0 | super(ehcache); |
52 | 0 | portletEntityIdToEntityid = new HashMap(); |
53 | 0 | } |
54 | ||
55 | /* (non-Javadoc) |
|
56 | * @see org.apache.jetspeed.cache.impl.PortletWindowCache#getPortletWindow(java.lang.String) |
|
57 | */ |
|
58 | public PortletWindow getPortletWindow(String windowId) |
|
59 | { |
|
60 | 0 | assert windowId != null; |
61 | 0 | CacheElement cacheElement = get(windowId); |
62 | 0 | if(cacheElement != null) |
63 | { |
|
64 | 0 | return (PortletWindow) cacheElement.getContent(); |
65 | } |
|
66 | else |
|
67 | { |
|
68 | 0 | return null; |
69 | } |
|
70 | } |
|
71 | ||
72 | /* (non-Javadoc) |
|
73 | * @see org.apache.jetspeed.cache.impl.PortletWindowCache#getPortletWindowByEntityId(java.lang.String) |
|
74 | */ |
|
75 | public PortletWindow getPortletWindowByEntityId(String portletEntityId) |
|
76 | { |
|
77 | 0 | assert portletEntityId != null; |
78 | 0 | if(portletEntityIdToEntityid.containsKey(portletEntityId)) |
79 | { |
|
80 | 0 | return (PortletWindow) getPortletWindow((String) portletEntityIdToEntityid.get(portletEntityId)); |
81 | } |
|
82 | else |
|
83 | { |
|
84 | 0 | return null; |
85 | } |
|
86 | } |
|
87 | ||
88 | /* (non-Javadoc) |
|
89 | * @see org.apache.jetspeed.cache.impl.PortletWindowCache#putPortletWindow(org.apache.pluto.om.window.PortletWindow) |
|
90 | */ |
|
91 | public void putPortletWindow(PortletWindow window) |
|
92 | { |
|
93 | 0 | assert window != null; |
94 | 0 | String windowId = window.getId().toString(); |
95 | 0 | portletEntityIdToEntityid.put(window.getPortletEntity().getId().toString(), windowId); |
96 | 0 | put(createElement(windowId, window)); |
97 | 0 | } |
98 | ||
99 | /* (non-Javadoc) |
|
100 | * @see org.apache.jetspeed.cache.impl.PortletWindowCache#removePortletWindow(java.lang.String) |
|
101 | */ |
|
102 | public void removePortletWindow(String portletWindowId) |
|
103 | { |
|
104 | 0 | assert portletWindowId != null; |
105 | 0 | PortletWindow window = getPortletWindow(portletWindowId); |
106 | 0 | if(window != null) |
107 | { |
|
108 | 0 | portletEntityIdToEntityid.remove(window.getPortletEntity().getId().toString()); |
109 | 0 | removeQuiet(portletWindowId); |
110 | } |
|
111 | 0 | } |
112 | ||
113 | public void removePortletWindowByPortletEntityId(String portletEntityId) |
|
114 | { |
|
115 | 0 | assert portletEntityId != null; |
116 | 0 | PortletWindow portletWindow = getPortletWindowByEntityId(portletEntityId); |
117 | 0 | if(portletWindow != null) |
118 | { |
|
119 | 0 | portletEntityIdToEntityid.remove(portletEntityId); |
120 | 0 | removeQuiet(portletWindow.getId().toString()); |
121 | } |
|
122 | 0 | } |
123 | ||
124 | public Set getAllPortletWindows() |
|
125 | { |
|
126 | 0 | Iterator keys = ehcache.getKeys().iterator(); |
127 | 0 | Set windows = new HashSet(); |
128 | 0 | while(keys.hasNext()) |
129 | { |
|
130 | 0 | String key = (String) keys.next(); |
131 | 0 | PortletWindow window = getPortletWindow(key); |
132 | 0 | if(window != null) |
133 | { |
|
134 | 0 | windows.add(window); |
135 | } |
|
136 | 0 | } |
137 | 0 | return windows; |
138 | } |
|
139 | ||
140 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |