001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.pluto;
018:
019: import javax.servlet.http.HttpServletRequest;
020:
021: import org.apache.avalon.framework.context.Context;
022: import org.apache.avalon.framework.context.ContextException;
023: import org.apache.avalon.framework.context.Contextualizable;
024: import org.apache.avalon.framework.service.ServiceException;
025: import org.apache.avalon.framework.service.ServiceManager;
026: import org.apache.avalon.framework.service.Serviceable;
027: import org.apache.cocoon.components.ContextHelper;
028: import org.apache.cocoon.portal.pluto.om.PortletDefinitionRegistry;
029: import org.apache.pluto.services.PortletContainerEnvironment;
030: import org.apache.pluto.services.information.DynamicInformationProvider;
031: import org.apache.pluto.services.information.InformationProviderService;
032: import org.apache.pluto.services.information.StaticInformationProvider;
033:
034: /**
035: * Our own information provider service
036: *
037: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
038: *
039: * @version CVS $Id: InformationProviderServiceImpl.java 433543 2006-08-22 06:22:54Z crossley $
040: */
041: public class InformationProviderServiceImpl implements
042: InformationProviderService, PortletContainerEnabled,
043: Serviceable, Contextualizable {
044:
045: /** The service manager */
046: protected ServiceManager manager;
047:
048: /** The portlet container environment */
049: protected PortletContainerEnvironmentImpl portletContainerEnvironment;
050:
051: /** The static information provider (thread safe) */
052: protected StaticInformationProvider staticProvider;
053:
054: /** The portal context provider (thread safe) */
055: protected PortalContextProviderImpl provider;
056:
057: /** The component context */
058: protected Context context;
059:
060: final static protected String dynamicProviderRole = InformationProviderServiceImpl.class
061: .getName();
062:
063: /* (non-Javadoc)
064: * @see org.apache.cocoon.portal.pluto.PortletContainerEnabled#setPortletContainerEnvironment(org.apache.pluto.services.PortletContainerEnvironment)
065: */
066: public void setPortletContainerEnvironment(
067: PortletContainerEnvironment env) {
068: this .portletContainerEnvironment = (PortletContainerEnvironmentImpl) env;
069: }
070:
071: /* (non-Javadoc)
072: * @see org.apache.pluto.services.information.InformationProviderService#getStaticProvider()
073: */
074: public StaticInformationProvider getStaticProvider() {
075: if (this .staticProvider == null) {
076: this .staticProvider = new StaticInformationProviderImpl(
077: this .getPortalContextProvider(),
078: (PortletDefinitionRegistry) this .portletContainerEnvironment
079: .getContainerService(PortletDefinitionRegistry.class));
080: }
081: return this .staticProvider;
082: }
083:
084: /* (non-Javadoc)
085: * @see org.apache.pluto.services.information.InformationProviderService#getDynamicProvider(javax.servlet.http.HttpServletRequest)
086: */
087: public DynamicInformationProvider getDynamicProvider(
088: HttpServletRequest request) {
089: DynamicInformationProvider dynProvider = (DynamicInformationProvider) request
090: .getAttribute(dynamicProviderRole);
091:
092: if (dynProvider == null) {
093: dynProvider = new DynamicInformationProviderImpl(
094: this .manager, this .getPortalContextProvider());
095: request.setAttribute(dynamicProviderRole, dynProvider);
096: }
097:
098: return dynProvider;
099: }
100:
101: /* (non-Javadoc)
102: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
103: */
104: public void contextualize(Context context) throws ContextException {
105: this .context = context;
106: }
107:
108: /* (non-Javadoc)
109: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
110: */
111: public void service(ServiceManager manager) throws ServiceException {
112: this .manager = manager;
113: }
114:
115: /**
116: * Get the portal context provider
117: * We have to do a lazy initialization, as the provider needs the object model
118: */
119: protected PortalContextProviderImpl getPortalContextProvider() {
120: if (this .provider == null) {
121: this .provider = new PortalContextProviderImpl(ContextHelper
122: .getObjectModel(context));
123: }
124: return this.provider;
125: }
126:
127: }
|