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.consumer.driver;
022:
023: import java.util.Hashtable;
024: import java.util.Iterator;
025:
026: import org.apache.wsrp4j.consumer.PortletKey;
027: import org.apache.wsrp4j.consumer.PortletRegistry;
028: import org.apache.wsrp4j.consumer.WSRPPortlet;
029: import org.apache.wsrp4j.exception.WSRPException;
030:
031: public abstract class GenericPortletRegistryImpl implements
032: PortletRegistry {
033:
034: // maps portlet keys to portlets
035: private Hashtable portlets = null;
036:
037: public GenericPortletRegistryImpl() {
038: portlets = new Hashtable();
039: }
040:
041: /**
042: * Add a portlet to the registry
043: *
044: * @param portlet The portlet to add
045: */
046: public void addPortlet(WSRPPortlet portlet) throws WSRPException {
047: if (portlet != null) {
048:
049: portlets.put(portlet.getPortletKey().toString(), portlet);
050:
051: }
052: }
053:
054: /**
055: * Get the portlet for the given producer and portlet handle
056: *
057: * @param portletKey The portlet key identifying the portlet
058: *
059: * @return The portlet with the given portlet key
060: **/
061: public WSRPPortlet getPortlet(PortletKey portletKey) {
062:
063: if (portletKey == null)
064: return null;
065:
066: WSRPPortlet portlet = (WSRPPortlet) portlets.get(portletKey
067: .toString());
068:
069: return portlet;
070: }
071:
072: /**
073: * Remove the portlet with the given portlet key
074: *
075: * @param portletKey The portlet key identifying the portlet
076: * @return The portlet which has been removed or null
077: **/
078: public WSRPPortlet removePortlet(PortletKey portletKey) {
079: if (portletKey == null)
080: return null;
081:
082: return (WSRPPortlet) portlets.remove(portletKey.toString());
083: }
084:
085: /**
086: * Remove all portlets from the registry
087: **/
088: public void removeAllPortlets() {
089: portlets.clear();
090: }
091:
092: /**
093: * Tests if a portlet with the given portlet key
094: *
095: * @param portletKey The portlet key identifying the portlet
096: *
097: * @return True if portlet exists with this portlet key
098: **/
099: public boolean existsPortlet(PortletKey portletKey) {
100: if (portletKey == null)
101: return false;
102:
103: return portlets.containsKey(portletKey.toString());
104: }
105:
106: /**
107: * Get all the portlets in the register
108: *
109: * @return Iterator with all portlets in the registry
110: **/
111: public Iterator getAllPortlets() {
112: return portlets.values().iterator();
113: }
114: }
|