001: /*
002: * Copyright 2000-2001,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: /*
018:
019: */
020:
021: package org.apache.wsrp4j.producer.provider.driver;
022:
023: import java.util.HashMap;
024: import java.util.Iterator;
025:
026: import org.apache.wsrp4j.exception.WSRPException;
027: import org.apache.wsrp4j.log.LogManager;
028: import org.apache.wsrp4j.log.Logger;
029: import org.apache.wsrp4j.producer.provider.PortletRegistrationFilter;
030: import org.apache.wsrp4j.producer.provider.PortletRegistrationFilterWriter;
031:
032: /**
033: * This class implements the interfaces PortletRegistrationFilter and
034: * PortletRegistrationFilterWriter.
035: *
036: * @author <a href="mailto:stefan.behl@de.ibm.com">Stefan Behl</a>
037: * @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
038: */
039: public class PortletRegistrationFilterImpl implements
040: PortletRegistrationFilter, PortletRegistrationFilterWriter {
041:
042: // a filter
043: private static PortletRegistrationFilterImpl filter = null;
044:
045: // collects ConsumerPortletRegistration objects. RegistrationHandle
046: // is the key
047: private static HashMap consumerPortletRegistrationMap = new HashMap();
048:
049: // for logging and exception support
050: private Logger logger = LogManager.getLogManager().getLogger(
051: this .getClass());
052:
053: /**
054: * @return PortletRegistrationFilterWriter
055: */
056: public static PortletRegistrationFilterWriter createWriter() {
057: if (filter == null) {
058: filter = new PortletRegistrationFilterImpl();
059: }
060:
061: return filter;
062: }
063:
064: /**
065: * @return PortletRegistrationFilter
066: */
067: public static PortletRegistrationFilter createReader() {
068: if (filter == null) {
069: filter = new PortletRegistrationFilterImpl();
070: }
071:
072: return filter;
073: }
074:
075: /**
076: * Private constructor
077: */
078: private PortletRegistrationFilterImpl() {
079:
080: String MN = "Constructor";
081: if (logger.isLogging(Logger.TRACE_HIGH)) {
082: logger.entry(Logger.TRACE_HIGH, MN);
083: }
084:
085: if (logger.isLogging(Logger.TRACE_HIGH)) {
086: logger.exit(Logger.TRACE_HIGH, MN);
087: }
088: }
089:
090: /**
091: * Returns all portlet handles of portlets, a certain consumer (identified
092: * by regHandle) can utilize. Returns null if there are no entries for the provided
093: * regHandle.
094: *
095: * @param regHandle String representing the registration handle of a consumer
096: *
097: * @return Iterator of portlet handles
098: */
099: 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,
110: "RegistrationHandle " + regHandle
111: + " found in Map.");
112: }
113:
114: ConsumerPortletRegistrationImpl cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
115: .get(regHandle);
116: iter = cpr.getPortletHandles().iterator();
117: }
118:
119: if (logger.isLogging(Logger.TRACE_HIGH)) {
120: logger.exit(Logger.TRACE_HIGH, MN);
121: }
122:
123: return iter;
124: }
125:
126: /**
127: * Indicates whether a certain consumer is allowed to utilize the portlet identified
128: * by portletHandle or not. Returns false if there is no entry for the provided handles.
129: *
130: * @param regHandle String representing the registration handle of a consumer
131: * @param portletHandle String representing the portlet handle of an portlet
132: *
133: * @return boolean indicating whether the consumer corresponding to regHandle is
134: * allowed to use the portlet identified by portletHandle
135: */
136: public boolean isAvailable(String regHandle, String portletHandle) {
137: String MN = "isAvailable";
138: if (logger.isLogging(Logger.TRACE_HIGH)) {
139: logger.entry(Logger.TRACE_HIGH, MN);
140: }
141:
142: boolean retVal = false;
143:
144: if (consumerPortletRegistrationMap.containsKey(regHandle)) {
145: if (logger.isLogging(Logger.TRACE_MEDIUM)) {
146: logger.text(Logger.TRACE_MEDIUM, MN,
147: "RegistrationHandle " + regHandle
148: + "found in Map.");
149: }
150:
151: ConsumerPortletRegistrationImpl cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
152: .get(regHandle);
153: if (cpr.containsPortletHandle(portletHandle)) {
154: retVal = true;
155:
156: if (logger.isLogging(Logger.TRACE_MEDIUM)) {
157: logger.text(Logger.TRACE_MEDIUM, MN,
158: "PortletHandle " + portletHandle
159: + "found for registration.");
160: }
161: }
162: }
163:
164: if (logger.isLogging(Logger.TRACE_HIGH)) {
165: logger.exit(Logger.TRACE_HIGH, MN);
166: }
167:
168: return retVal;
169: }
170:
171: /**
172: * Makes a certain portlet (identified by portletHandle) available to a consumer
173: * (identified by regHandle). If there is no portlet in the portlet pool that
174: * corresponds to portletHandle, the method performs nothing.
175: *
176: * @param regHandle String representing the registration handle of a consumer
177: * @param portletHandle String representing the portlet handle of a consumer
178: */
179: public void makeAvailable(String regHandle, String portletHandle)
180: throws WSRPException {
181: String MN = "makeAvailable";
182: if (logger.isLogging(Logger.TRACE_HIGH)) {
183: logger.entry(Logger.TRACE_HIGH, MN);
184: }
185:
186: ConsumerPortletRegistrationImpl cpr = null;
187:
188: if (!consumerPortletRegistrationMap.containsKey(regHandle)) {
189: cpr = new ConsumerPortletRegistrationImpl();
190: cpr.setRegistrationHandle(regHandle);
191: consumerPortletRegistrationMap.put(regHandle, cpr);
192: } else {
193: cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
194: .get(regHandle);
195: }
196:
197: // add the current portlet handle to the registration
198: cpr.addPortletHandle(portletHandle);
199:
200: if (logger.isLogging(Logger.TRACE_HIGH)) {
201: logger.exit(Logger.TRACE_HIGH, MN);
202: }
203: }
204:
205: /**
206: * Makes several portlets (identified by portletHandles) available to
207: * a certain consumer (identified by regHandle). For portlet handles that do not
208: * correspond to portlets kept within the portlet pool, the method makes no
209: * availability-entry.
210: *
211: * @param regHandle String representing the registration handle of a consumer
212: * @param portletHandles Iterator containing some portlet handles of portlets
213: *
214: * @throws WSRPException
215: */
216: public void makeAvailable(String regHandle, Iterator portletHandles)
217: throws WSRPException {
218: String MN = "makeAvailable";
219: if (logger.isLogging(Logger.TRACE_HIGH)) {
220: logger.entry(Logger.TRACE_HIGH, MN);
221: }
222:
223: while (portletHandles.hasNext()) {
224: makeAvailable(regHandle, (String) portletHandles.next());
225: }
226:
227: if (logger.isLogging(Logger.TRACE_HIGH)) {
228: logger.exit(Logger.TRACE_HIGH, MN);
229: }
230: }
231:
232: /**
233: * Removes an entire entry for a certain consumer (identified by regHandle).
234: * If there are no entries for the provided regHandle, the method performs
235: * nothing. The method is useful when a consumer deregisters.
236: *
237: * @param regHandle String representing the registration handle of a consumer
238: */
239: public void remove(String regHandle) {
240: String MN = "remove";
241: if (logger.isLogging(Logger.TRACE_HIGH)) {
242: logger.entry(Logger.TRACE_HIGH, MN);
243: }
244:
245: if (consumerPortletRegistrationMap.containsKey(regHandle)) {
246: ConsumerPortletRegistrationImpl cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
247: .get(regHandle);
248:
249: consumerPortletRegistrationMap.remove(regHandle);
250: }
251:
252: if (logger.isLogging(Logger.TRACE_HIGH)) {
253: logger.exit(Logger.TRACE_HIGH, MN);
254: }
255:
256: }
257:
258: /**
259: * Abrogates the availability of a certain portlet (identified by portletHandle)
260: * regarding a certain consumer (identified by regHandle). If there is no entry
261: * for the provided regHandle and portletHandle, the method performs nothing.
262: *
263: * @param regHandle String representing the registration handle of a consumer
264: * @param portletHandle String representing the portlet handle of a consumer
265: */
266: public void remove(String regHandle, String portletHandle)
267: throws WSRPException {
268:
269: String MN = "remove";
270: if (logger.isLogging(Logger.TRACE_HIGH)) {
271: logger.entry(Logger.TRACE_HIGH, MN);
272: }
273:
274: if (consumerPortletRegistrationMap.containsKey(regHandle)) {
275: ConsumerPortletRegistrationImpl cpr = (ConsumerPortletRegistrationImpl) consumerPortletRegistrationMap
276: .get(regHandle);
277: cpr.deletePortletHandle(portletHandle);
278:
279: // Is the registration list empty? No more Portlets are assigned?
280: if (cpr.isEmpty()) {
281: // delete the registration list
282: consumerPortletRegistrationMap.remove(regHandle);
283: }
284: }
285:
286: if (logger.isLogging(Logger.TRACE_HIGH)) {
287: logger.exit(Logger.TRACE_HIGH, MN);
288: }
289:
290: }
291:
292: /**
293: * Abrogates the availability of several portlets (identified by portletHandles)
294: * regarding a certain consumer (identified by regHandle). For portlet handles
295: * that do not correspond to portlets kept within the portlet pool, the method
296: * performs nothing.
297: *
298: * @param regHandle String representing the registration handle of a consumer
299: * @param portletHandles Iterator containing some portlet handles of portlets
300: */
301: public void remove(String regHandle, Iterator portletHandles)
302: throws WSRPException {
303: String MN = "remove";
304: if (logger.isLogging(Logger.TRACE_HIGH)) {
305: logger.entry(Logger.TRACE_HIGH, MN);
306: }
307:
308: if (portletHandles != null) {
309: while (portletHandles.hasNext()) {
310: remove(regHandle, (String) portletHandles.next());
311: }
312: }
313:
314: if (logger.isLogging(Logger.TRACE_HIGH)) {
315: logger.exit(Logger.TRACE_HIGH, MN);
316: }
317: }
318:
319: }
|