1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.services.information;
1819import java.util.Map;
2021import javax.servlet.ServletConfig;
22import javax.servlet.ServletRequest;
23import javax.servlet.http.HttpServletRequest;
24import javax.servlet.http.HttpServletRequestWrapper;
2526import org.apache.pluto.factory.Factory;
27import org.apache.pluto.services.information.DynamicInformationProvider;
28import org.apache.pluto.services.information.InformationProviderService;
29import org.apache.pluto.services.information.StaticInformationProvider;
3031import org.apache.jetspeed.aggregator.CurrentWorkerContext;
3233/***34 * Factory class for getting Information Provider access35 *36 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>37 * @version $Id: InformationProviderServiceImpl.java 587813 2007-10-24 08:20:39Z woonsan $38 */39publicclassInformationProviderServiceImpl implements Factory, InformationProviderService
40 {
41private javax.servlet.ServletConfig servletConfig;
42privatefinal StaticInformationProvider staticInformationProvider;
4344publicInformationProviderServiceImpl(StaticInformationProvider staticInformationProvider, ServletConfig config)
45 {
46this.staticInformationProvider = staticInformationProvider;
4748 }
4950publicvoid init(ServletConfig config, Map properties) throws Exception
51 {
52// does nothing at all 53 }
5455public StaticInformationProvider getStaticProvider()
56 {
57return staticInformationProvider;
58 }
5960public DynamicInformationProvider getDynamicProvider(HttpServletRequest request)
61 {
62 DynamicInformationProvider provider = null;
6364boolean isParallel = CurrentWorkerContext.getParallelRenderingMode();
65 ServletRequest servletRequest = null;
6667if (isParallel)
68 {
69// request should be an instance of org.apache.jetspeed.engine.servlet.ServletRequestImpl70// unwrap the real request instance provided by the container to synchronize71 servletRequest = ((HttpServletRequestWrapper) request).getRequest();
7273// if it is not an instance of HttpServletRequestWrapper any more, then it is not AdjustedSRTServletRequest instance.74if (servletRequest instanceof HttpServletRequestWrapper)
75 {
76 servletRequest = ((HttpServletRequestWrapper) servletRequest).getRequest();
77 }
7879synchronized (servletRequest)
80 {
81 provider = (DynamicInformationProvider) servletRequest.getAttribute("org.apache.jetspeed.engine.core.DynamicInformationProvider");
82 }
83 }
84else85 {
86 provider = (DynamicInformationProvider) request.getAttribute("org.apache.jetspeed.engine.core.DynamicInformationProvider");
87 }
8889if (provider == null)
90 {
91 provider = newDynamicInformationProviderImpl(request, servletConfig);
9293if (isParallel)
94 {
95synchronized (servletRequest)
96 {
97 servletRequest.setAttribute("org.apache.jetspeed.engine.core.DynamicInformationProvider", provider);
98 }
99 }
100else101 {
102 request.setAttribute("org.apache.jetspeed.engine.core.DynamicInformationProvider", provider);
103 }
104 }
105106return provider;
107 }
108109/***110 * <p>111 * destroy112 * </p>113 *114 * @see org.apache.pluto.factory.Factory#destroy()115 * @throws java.lang.Exception116 */117publicvoid destroy() throws Exception
118 {
119// also does nothing120 }
121 }