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: * $Header:$
018: */
019: package org.apache.beehive.controls.runtime.servlet;
020:
021: import java.beans.beancontext.BeanContextServices;
022: import java.beans.beancontext.BeanContextServiceProvider;
023: import java.util.Iterator;
024:
025: import javax.servlet.ServletContext;
026: import javax.servlet.ServletRequest;
027: import javax.servlet.ServletResponse;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030:
031: /**
032: * The ServletContextProvider helper class acts at the BeanContextServiceProvider provides
033: * instances of web tier services associated with a ServletBeanContext
034: */
035: class ServletServiceProvider implements BeanContextServiceProvider {
036: static final private ServletServiceProvider _provider = new ServletServiceProvider();
037:
038: static ServletServiceProvider getProvider() {
039: return _provider;
040: }
041:
042: /* package */ServletServiceProvider() {
043: }
044:
045: public Object getService(BeanContextServices bcs, Object requestor,
046: Class serviceClass, Object serviceSelector) {
047: //
048: // These services are only available to controls running within the scope of a
049: // ServletBeanContext
050: //
051: if (!(bcs instanceof ServletBeanContext))
052: return null;
053:
054: ServletBeanContext sbc = (ServletBeanContext) bcs;
055: if (serviceClass.equals(ServletContext.class))
056: return new ServletContextService(sbc);
057:
058: if (serviceClass.equals(HttpServletRequest.class)) {
059: HttpRequestService requestService = new HttpRequestService(
060: sbc);
061: if (sbc.useWrappers())
062: return requestService.getHttpRequestWrapper();
063: return requestService;
064: }
065:
066: if (serviceClass.equals(HttpServletResponse.class)) {
067: HttpResponseService responseService = new HttpResponseService(
068: sbc);
069: if (sbc.useWrappers())
070: return responseService.getHttpResponseWrapper();
071: return responseService;
072: }
073:
074: if (serviceClass.equals(ServletRequest.class)) {
075: ServletRequestService requestService = new ServletRequestService(
076: sbc);
077: if (sbc.useWrappers())
078: return requestService.getRequestWrapper();
079: return requestService;
080: }
081:
082: if (serviceClass.equals(ServletResponse.class)) {
083: ServletResponseService responseService = new ServletResponseService(
084: sbc);
085: if (sbc.useWrappers())
086: return responseService.getResponseWrapper();
087: return responseService;
088: }
089:
090: return null;
091: }
092:
093: public void releaseService(BeanContextServices bcs,
094: Object requestor, Object service) {
095: // noop, because the provider isn't tracking service instances.
096: }
097:
098: public Iterator getCurrentServiceSelectors(BeanContextServices bcs,
099: Class serviceClass) {
100: return null; // no selectors
101: }
102: }
|