1
16
17
20
21 package org.apache.wsrp4j.producer.provider.driver;
22
23 import java.util.HashMap;
24 import java.util.Iterator;
25
26 import org.apache.wsrp4j.exception.WSRPException;
27 import org.apache.wsrp4j.log.LogManager;
28 import org.apache.wsrp4j.log.Logger;
29 import org.apache.wsrp4j.producer.provider.PortletRegistrationFilter;
30 import org.apache.wsrp4j.producer.provider.PortletRegistrationFilterWriter;
31
32
39 public class PortletRegistrationFilterImpl implements
40 PortletRegistrationFilter, PortletRegistrationFilterWriter {
41
42 private static PortletRegistrationFilterImpl filter = null;
44
45 private static HashMap consumerPortletRegistrationMap = new HashMap();
48
49 private Logger logger = LogManager.getLogManager().getLogger(
51 this.getClass());
52
53
56 public static PortletRegistrationFilterWriter createWriter() {
57 if (filter == null) {
58 filter = new PortletRegistrationFilterImpl();
59 }
60
61 return filter;
62 }
63
64
67 public static PortletRegistrationFilter createReader() {
68 if (filter == null) {
69 filter = new PortletRegistrationFilterImpl();
70 }
71
72 return filter;
73 }
74
75
78 private PortletRegistrationFilterImpl() {
79
80 String MN = "Constructor";
81 if (logger.isLogging(Logger.TRACE_HIGH)) {
82 logger.entry(Logger.TRACE_HIGH, MN);
83 }
84
85 if (logger.isLogging(Logger.TRACE_HIGH)) {
86 logger.exit(Logger.TRACE_HIGH, MN);
87 }
88 }
89
90
99 public Iterator getAvailable(String regHandle) {
100 String MN = "getAvailable";
101 if (logger.isLogging(Logger.TRACE_HIGH)) {
102 logger.entry(Logger.TRACE_HIGH, MN);
103 }
104
105 Iterator iter = null;
106
107 if (consumerPortletRegistrationMap.containsKey(regHandle)) {
108 if (logger.isLogging(Logger.TRACE_MEDIUM)) {
109 logger.text(Logger.TRACE_MEDIUM, MN, "RegistrationHandle "
110 + regHandle + " found in Map.");
111 }
112
113 ConsumerPortletRegistrationImpl cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
114 .get(regHandle);
115 iter = cpr.getPortletHandles().iterator();
116 }
117
118 if (logger.isLogging(Logger.TRACE_HIGH)) {
119 logger.exit(Logger.TRACE_HIGH, MN);
120 }
121
122 return iter;
123 }
124
125
135 public boolean isAvailable(String regHandle, String portletHandle) {
136 String MN = "isAvailable";
137 if (logger.isLogging(Logger.TRACE_HIGH)) {
138 logger.entry(Logger.TRACE_HIGH, MN);
139 }
140
141 boolean retVal = false;
142
143 if (consumerPortletRegistrationMap.containsKey(regHandle)) {
144 if (logger.isLogging(Logger.TRACE_MEDIUM)) {
145 logger.text(Logger.TRACE_MEDIUM, MN, "RegistrationHandle "
146 + regHandle + "found in Map.");
147 }
148
149 ConsumerPortletRegistrationImpl cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
150 .get(regHandle);
151 if (cpr.containsPortletHandle(portletHandle)) {
152 retVal = true;
153
154 if (logger.isLogging(Logger.TRACE_MEDIUM)) {
155 logger.text(Logger.TRACE_MEDIUM, MN, "PortletHandle "
156 + portletHandle + "found for registration.");
157 }
158 }
159 }
160
161 if (logger.isLogging(Logger.TRACE_HIGH)) {
162 logger.exit(Logger.TRACE_HIGH, MN);
163 }
164
165 return retVal;
166 }
167
168
176 public void makeAvailable(String regHandle, String portletHandle)
177 throws WSRPException {
178 String MN = "makeAvailable";
179 if (logger.isLogging(Logger.TRACE_HIGH)) {
180 logger.entry(Logger.TRACE_HIGH, MN);
181 }
182
183 ConsumerPortletRegistrationImpl cpr = null;
184
185 if (!consumerPortletRegistrationMap.containsKey(regHandle)) {
186 cpr = new ConsumerPortletRegistrationImpl();
187 cpr.setRegistrationHandle(regHandle);
188 consumerPortletRegistrationMap.put(regHandle, cpr);
189 }
190 else {
191 cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
192 .get(regHandle);
193 }
194
195 cpr.addPortletHandle(portletHandle);
197
198 if (logger.isLogging(Logger.TRACE_HIGH)) {
199 logger.exit(Logger.TRACE_HIGH, MN);
200 }
201 }
202
203
214 public void makeAvailable(String regHandle, Iterator portletHandles)
215 throws WSRPException {
216 String MN = "makeAvailable";
217 if (logger.isLogging(Logger.TRACE_HIGH)) {
218 logger.entry(Logger.TRACE_HIGH, MN);
219 }
220
221 while (portletHandles.hasNext()) {
222 makeAvailable(regHandle, (String) portletHandles.next());
223 }
224
225 if (logger.isLogging(Logger.TRACE_HIGH)) {
226 logger.exit(Logger.TRACE_HIGH, MN);
227 }
228 }
229
230
237 public void remove(String regHandle) {
238 String MN = "remove";
239 if (logger.isLogging(Logger.TRACE_HIGH)) {
240 logger.entry(Logger.TRACE_HIGH, MN);
241 }
242
243 if (consumerPortletRegistrationMap.containsKey(regHandle)) {
244 ConsumerPortletRegistrationImpl cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
245 .get(regHandle);
246
247 consumerPortletRegistrationMap.remove(regHandle);
248 }
249
250 if (logger.isLogging(Logger.TRACE_HIGH)) {
251 logger.exit(Logger.TRACE_HIGH, MN);
252 }
253
254 }
255
256
264 public void remove(String regHandle, String portletHandle)
265 throws WSRPException {
266
267 String MN = "remove";
268 if (logger.isLogging(Logger.TRACE_HIGH)) {
269 logger.entry(Logger.TRACE_HIGH, MN);
270 }
271
272 if (consumerPortletRegistrationMap.containsKey(regHandle)) {
273 ConsumerPortletRegistrationImpl cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
274 .get(regHandle);
275 cpr.deletePortletHandle(portletHandle);
276
277 if (cpr.isEmpty()) {
279 consumerPortletRegistrationMap.remove(regHandle);
281 }
282 }
283
284 if (logger.isLogging(Logger.TRACE_HIGH)) {
285 logger.exit(Logger.TRACE_HIGH, MN);
286 }
287
288 }
289
290
299 public void remove(String regHandle, Iterator portletHandles)
300 throws WSRPException {
301 String MN = "remove";
302 if (logger.isLogging(Logger.TRACE_HIGH)) {
303 logger.entry(Logger.TRACE_HIGH, MN);
304 }
305
306 if (portletHandles != null) {
307 while (portletHandles.hasNext()) {
308 remove(regHandle, (String) portletHandles.next());
309 }
310 }
311
312 if (logger.isLogging(Logger.TRACE_HIGH)) {
313 logger.exit(Logger.TRACE_HIGH, MN);
314 }
315 }
316
317 }