| PortletDriverRegistryImpl.java |
1 /*
2 * Copyright 2000-2001,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*
18
19 */
20
21 package org.apache.wsrp4j.consumer.driver;
22
23 import java.util.Hashtable;
24 import java.util.Iterator;
25
26 import org.apache.wsrp4j.consumer.ConsumerEnvironment;
27 import org.apache.wsrp4j.consumer.PortletDriver;
28 import org.apache.wsrp4j.consumer.PortletDriverRegistry;
29 import org.apache.wsrp4j.consumer.WSRPPortlet;
30 import org.apache.wsrp4j.exception.WSRPException;
31
32 public class PortletDriverRegistryImpl implements PortletDriverRegistry {
33
34 private static PortletDriverRegistry instance = null;
35
36 private Hashtable portletDrivers = null;
37
38 private ConsumerEnvironment consumerEnv = null;
39
40 private PortletDriverRegistryImpl(ConsumerEnvironment consumerEnv) {
41
42 this.portletDrivers = new Hashtable();
43 this.consumerEnv = consumerEnv;
44 }
45
46 public static PortletDriverRegistry getInstance(
47 ConsumerEnvironment consumerEnv) {
48 if (instance == null) {
49 instance = new PortletDriverRegistryImpl(consumerEnv);
50 }
51
52 return instance;
53 }
54
55 /**
56 * Get an portlet driver for the given portlet. If there is no portlet driver
57 * object cached a new portlet driver will be created and returned.
58 *
59 * @param portlet The portlet the returned portlet driver is bind to
60 *
61 * @return The portlet driver for this portlet
62 **/
63 public PortletDriver getPortletDriver(WSRPPortlet portlet)
64 throws WSRPException {
65
66 PortletDriver driver = null;
67
68 if ((driver = (PortletDriver) portletDrivers.get(portlet
69 .getPortletKey().toString())) == null) {
70 driver = new PortletDriverImpl(portlet, consumerEnv);
71 }
72
73 return driver;
74 }
75
76 /**
77 * Get all cached portlet drivers.
78 *
79 * @return Iterator with all portlet drivers in the registry
80 **/
81 public Iterator getAllPortletDrivers() {
82 return portletDrivers.values().iterator();
83 }
84 }