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.jetspeed.services.information;
018:
019: import java.util.Map;
020:
021: import javax.servlet.ServletConfig;
022: import javax.servlet.ServletRequest;
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletRequestWrapper;
025:
026: import org.apache.pluto.factory.Factory;
027: import org.apache.pluto.services.information.DynamicInformationProvider;
028: import org.apache.pluto.services.information.InformationProviderService;
029: import org.apache.pluto.services.information.StaticInformationProvider;
030:
031: import org.apache.jetspeed.aggregator.CurrentWorkerContext;
032:
033: /**
034: * Factory class for getting Information Provider access
035: *
036: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
037: * @version $Id: InformationProviderServiceImpl.java 587813 2007-10-24 08:20:39Z woonsan $
038: */
039: public class InformationProviderServiceImpl implements Factory,
040: InformationProviderService {
041: private javax.servlet.ServletConfig servletConfig;
042: private final StaticInformationProvider staticInformationProvider;
043:
044: public InformationProviderServiceImpl(
045: StaticInformationProvider staticInformationProvider,
046: ServletConfig config) {
047: this .staticInformationProvider = staticInformationProvider;
048:
049: }
050:
051: public void init(ServletConfig config, Map properties)
052: throws Exception {
053: // does nothing at all
054: }
055:
056: public StaticInformationProvider getStaticProvider() {
057: return staticInformationProvider;
058: }
059:
060: public DynamicInformationProvider getDynamicProvider(
061: HttpServletRequest request) {
062: DynamicInformationProvider provider = null;
063:
064: boolean isParallel = CurrentWorkerContext
065: .getParallelRenderingMode();
066: ServletRequest servletRequest = null;
067:
068: if (isParallel) {
069: // request should be an instance of org.apache.jetspeed.engine.servlet.ServletRequestImpl
070: // unwrap the real request instance provided by the container to synchronize
071: servletRequest = ((HttpServletRequestWrapper) request)
072: .getRequest();
073:
074: // if it is not an instance of HttpServletRequestWrapper any more, then it is not AdjustedSRTServletRequest instance.
075: if (servletRequest instanceof HttpServletRequestWrapper) {
076: servletRequest = ((HttpServletRequestWrapper) servletRequest)
077: .getRequest();
078: }
079:
080: synchronized (servletRequest) {
081: provider = (DynamicInformationProvider) servletRequest
082: .getAttribute("org.apache.jetspeed.engine.core.DynamicInformationProvider");
083: }
084: } else {
085: provider = (DynamicInformationProvider) request
086: .getAttribute("org.apache.jetspeed.engine.core.DynamicInformationProvider");
087: }
088:
089: if (provider == null) {
090: provider = new DynamicInformationProviderImpl(request,
091: servletConfig);
092:
093: if (isParallel) {
094: synchronized (servletRequest) {
095: servletRequest
096: .setAttribute(
097: "org.apache.jetspeed.engine.core.DynamicInformationProvider",
098: provider);
099: }
100: } else {
101: request
102: .setAttribute(
103: "org.apache.jetspeed.engine.core.DynamicInformationProvider",
104: provider);
105: }
106: }
107:
108: return provider;
109: }
110:
111: /**
112: * <p>
113: * destroy
114: * </p>
115: *
116: * @see org.apache.pluto.factory.Factory#destroy()
117: * @throws java.lang.Exception
118: */
119: public void destroy() throws Exception {
120: // also does nothing
121: }
122: }
|