KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > factory > PortletInvokerFactoryImpl


1 /*
2  * Copyright 2004,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 package org.apache.cocoon.portal.pluto.factory;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.avalon.framework.activity.Disposable;
24 import org.apache.avalon.framework.container.ContainerUtil;
25 import org.apache.avalon.framework.context.Context;
26 import org.apache.avalon.framework.context.ContextException;
27 import org.apache.avalon.framework.context.Contextualizable;
28 import org.apache.avalon.framework.service.ServiceException;
29 import org.apache.avalon.framework.service.ServiceManager;
30 import org.apache.avalon.framework.service.Serviceable;
31 import org.apache.avalon.framework.thread.ThreadSafe;
32 import org.apache.cocoon.portal.pluto.om.PortletDefinitionImpl;
33 import org.apache.pluto.factory.PortletInvokerFactory;
34 import org.apache.pluto.invoker.PortletInvoker;
35 import org.apache.pluto.invoker.impl.PortletInvokerImpl;
36 import org.apache.pluto.om.portlet.PortletDefinition;
37
38 /**
39  * The implementation of the invoker factory
40  *
41  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
42  *
43  * @version CVS $Id: PortletInvokerFactoryImpl.java 30932 2004-07-29 17:35:38Z vgritsenko $
44  */

45 public class PortletInvokerFactoryImpl
46 extends AbstractFactory
47 implements PortletInvokerFactory, Serviceable, Contextualizable, ThreadSafe, Disposable {
48
49     /** The avalon context */
50     protected Context context;
51     
52     /** The service manager */
53     protected ServiceManager manager;
54     
55     /** All local portlets */
56     protected List JavaDoc localPortlets = Collections.synchronizedList(new ArrayList JavaDoc());
57     
58     /* (non-Javadoc)
59      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
60      */

61     public void contextualize(Context context) throws ContextException {
62         this.context = context;
63     }
64     
65     /* (non-Javadoc)
66      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
67      */

68     public void service(ServiceManager manager) throws ServiceException {
69         this.manager = manager;
70     }
71
72     /* (non-Javadoc)
73      * @see org.apache.avalon.framework.activity.Disposable#dispose()
74      */

75     public void dispose() {
76         final Iterator JavaDoc i = this.localPortlets.iterator();
77         while (i.hasNext()) {
78             LocalPortletInvokerImpl current = (LocalPortletInvokerImpl)i.next();
79             current.destroy();
80         }
81         this.localPortlets.clear();
82         this.manager = null;
83         this.context = null;
84     }
85
86     /* (non-Javadoc)
87      * @see org.apache.pluto.factory.PortletInvokerFactory#getPortletInvoker(org.apache.pluto.om.portlet.PortletDefinition)
88      */

89     public PortletInvoker getPortletInvoker(PortletDefinition portletDefinition) {
90         // test, if this is a local portlet
91
boolean local = false;
92         PortletInvoker invoker;
93         if ( portletDefinition instanceof PortletDefinitionImpl ) {
94             local = ((PortletDefinitionImpl)portletDefinition).isLocalPortlet();
95         }
96         if (local) {
97             invoker = ((PortletDefinitionImpl)portletDefinition).getLocalPortletInvoker();
98             if ( invoker == null ) {
99                 invoker = new LocalPortletInvokerImpl(portletDefinition, this.servletConfig);
100                 this.localPortlets.add(invoker);
101                 ((PortletDefinitionImpl)portletDefinition).setLocalPortletInvoker(invoker);
102                 try {
103                     ContainerUtil.enableLogging(invoker, this.getLogger());
104                     ContainerUtil.contextualize(invoker, this.context);
105                     ContainerUtil.service(invoker, this.manager);
106                     ContainerUtil.initialize(invoker);
107                 } catch (Exception JavaDoc ignore) {
108                     this.getLogger().warn("Unable to initialize local portlet invoker.", ignore);
109                 }
110             }
111         } else {
112             invoker = new PortletInvokerImpl(portletDefinition, this.servletConfig);
113         }
114         
115         return invoker;
116     }
117
118     /* (non-Javadoc)
119      * @see org.apache.pluto.factory.PortletInvokerFactory#releasePortletInvoker(org.apache.pluto.invoker.PortletInvoker)
120      */

121     public void releasePortletInvoker(PortletInvoker invoker) {
122         // nothing to do here
123
}
124
125 }
126
Popular Tags