KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > wsrp > consumer > PortletDriverRegistryImpl


1 /*
2  * Copyright 2005 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 package org.apache.cocoon.portal.wsrp.consumer;
17
18 import java.util.Hashtable JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import org.apache.cocoon.portal.wsrp.adapter.WSRPAdapter;
22 import org.apache.wsrp4j.consumer.ConsumerEnvironment;
23 import org.apache.wsrp4j.consumer.PortletDriver;
24 import org.apache.wsrp4j.consumer.PortletDriverRegistry;
25 import org.apache.wsrp4j.consumer.WSRPPortlet;
26 import org.apache.wsrp4j.exception.WSRPException;
27
28 /**
29  * Manages the drivers for the portlets the consumerEnvironment holds<br/>
30  * Per portlet one portletDriver will be stored<br/>
31  *
32  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
33  * @author <a HREF="mailto:malessandrini@s-und-n.de">Michel Alessandrini</a>
34  *
35  * @version $Id: PortletDriverRegistryImpl.java 264755 2005-08-30 10:29:21Z cziegeler $
36  */

37 public class PortletDriverRegistryImpl
38     implements PortletDriverRegistry,
39                RequiresConsumerEnvironment,
40                RequiresWSRPAdapter {
41
42     /** All portletDrivers the consumerEnvironment needs. */
43     protected final Hashtable JavaDoc portletDrivers = new Hashtable JavaDoc();
44     
45     /** The consumer environment. */
46     protected ConsumerEnvironment consumerEnv;
47
48     /** The WSRP adapter. */
49     protected WSRPAdapter adapter;
50
51     /**
52      * @see org.apache.cocoon.portal.wsrp.consumer.RequiresConsumerEnvironment#setConsumerEnvironment(org.apache.wsrp4j.consumer.ConsumerEnvironment)
53      */

54     public void setConsumerEnvironment(ConsumerEnvironment env) {
55         this.consumerEnv = env;
56     }
57
58     /**
59      * @see org.apache.cocoon.portal.wsrp.consumer.RequiresWSRPAdapter#setWSRPAdapter(org.apache.cocoon.portal.wsrp.adapter.WSRPAdapter)
60      */

61     public void setWSRPAdapter(WSRPAdapter adapter) {
62         this.adapter = adapter;
63     }
64
65     /**
66      * Get an portlet driver for the given portlet. If there is no portlet driver
67      * object cached a new portlet driver will be created and returned.
68      *
69      * @param portlet The portlet the returned portlet driver is bound to.
70      *
71      * @return The portlet driver for this portlet.
72      **/

73     public PortletDriver getPortletDriver(WSRPPortlet portlet)
74     throws WSRPException {
75         PortletDriver driver = null;
76
77         if ((driver = (PortletDriver)portletDrivers.get(portlet.getPortletKey().toString())) == null) {
78             String JavaDoc driverClass = this.adapter.getAdapterConfiguration().getParameter("portlet-driver-class", PortletDriverImpl.class.getName());
79             try {
80                 driver = (PortletDriverImpl)this.adapter.createObject(driverClass);
81             } catch (Exception JavaDoc e) {
82                 throw new WSRPException(0, e);
83             }
84             ((PortletDriverImpl)driver).init(portlet);
85             this.portletDrivers.put(portlet.getPortletKey().toString(), driver);
86         }
87         return driver;
88     }
89
90     /**
91      * Get all cached portlet drivers.
92      *
93      * @return Iterator with all portlet drivers in the registry.
94      **/

95     public Iterator JavaDoc getAllPortletDrivers() {
96         return portletDrivers.values().iterator();
97     }
98 }
99
Popular Tags