KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > InformationProviderServiceImpl


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;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19
20 import org.apache.avalon.framework.context.Context;
21 import org.apache.avalon.framework.context.ContextException;
22 import org.apache.avalon.framework.context.Contextualizable;
23 import org.apache.avalon.framework.service.ServiceException;
24 import org.apache.avalon.framework.service.ServiceManager;
25 import org.apache.avalon.framework.service.Serviceable;
26 import org.apache.cocoon.components.ContextHelper;
27 import org.apache.cocoon.portal.pluto.om.PortletDefinitionRegistry;
28 import org.apache.pluto.services.PortletContainerEnvironment;
29 import org.apache.pluto.services.information.DynamicInformationProvider;
30 import org.apache.pluto.services.information.InformationProviderService;
31 import org.apache.pluto.services.information.StaticInformationProvider;
32
33 /**
34  * Our own information provider service
35  *
36  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
37  *
38  * @version CVS $Id: InformationProviderServiceImpl.java 30932 2004-07-29 17:35:38Z vgritsenko $
39  */

40 public class InformationProviderServiceImpl
41 implements InformationProviderService, PortletContainerEnabled, Serviceable, Contextualizable {
42
43     /** The service manager */
44     protected ServiceManager manager;
45     
46     /** The portlet container environment */
47     protected PortletContainerEnvironmentImpl portletContainerEnvironment;
48     
49     /** The static information provider (thread safe) */
50     protected StaticInformationProvider staticProvider;
51
52     /** The portal context provider (thread safe) */
53     protected PortalContextProviderImpl provider;
54     
55     /** The component context */
56     protected Context context;
57
58     final static protected String JavaDoc dynamicProviderRole= InformationProviderServiceImpl.class.getName();
59     
60     /* (non-Javadoc)
61      * @see org.apache.cocoon.portal.pluto.PortletContainerEnabled#setPortletContainerEnvironment(org.apache.pluto.services.PortletContainerEnvironment)
62      */

63     public void setPortletContainerEnvironment(PortletContainerEnvironment env) {
64         this.portletContainerEnvironment = (PortletContainerEnvironmentImpl)env;
65     }
66
67     /* (non-Javadoc)
68      * @see org.apache.pluto.services.information.InformationProviderService#getStaticProvider()
69      */

70     public StaticInformationProvider getStaticProvider() {
71         if ( this.staticProvider == null ) {
72             this.staticProvider = new StaticInformationProviderImpl(this.getPortalContextProvider(),
73                     (PortletDefinitionRegistry)this.portletContainerEnvironment.getContainerService(PortletDefinitionRegistry.class));
74         }
75         return this.staticProvider;
76     }
77
78     /* (non-Javadoc)
79      * @see org.apache.pluto.services.information.InformationProviderService#getDynamicProvider(javax.servlet.http.HttpServletRequest)
80      */

81     public DynamicInformationProvider getDynamicProvider(HttpServletRequest JavaDoc request) {
82         DynamicInformationProvider dynProvider = (DynamicInformationProvider)request.getAttribute(dynamicProviderRole);
83
84         if (dynProvider == null) {
85             dynProvider = new DynamicInformationProviderImpl(this.manager,
86                                                           this.getPortalContextProvider());
87             request.setAttribute(dynamicProviderRole, dynProvider);
88         }
89
90         return dynProvider;
91     }
92
93
94     /* (non-Javadoc)
95      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
96      */

97     public void contextualize(Context context) throws ContextException {
98         this.context = context;
99     }
100
101     /* (non-Javadoc)
102      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
103      */

104     public void service(ServiceManager manager) throws ServiceException {
105         this.manager = manager;
106     }
107
108     /**
109      * Get the portal context provider
110      * We have to do a lazy initialization, as the provider needs the object model
111      */

112     protected PortalContextProviderImpl getPortalContextProvider() {
113         if ( this.provider == null ) {
114             this.provider = new PortalContextProviderImpl(ContextHelper.getObjectModel(context));
115         }
116         return this.provider;
117     }
118     
119 }
120
Popular Tags