KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > context > support > ServletContextFactoryBean


1 /*
2  * Copyright 2002-2006 the original author or authors.
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
17 package org.springframework.web.context.support;
18
19 import javax.servlet.ServletContext JavaDoc;
20
21 import org.springframework.beans.factory.FactoryBean;
22 import org.springframework.web.context.ServletContextAware;
23
24 /**
25  * Simple FactoryBean that exposes the ServletContext for bean references.
26  * Can be used as alternative to implementing the ServletContextAware
27  * callback interface. Allows for passing the ServletContext reference
28  * to a constructor argument or any custom bean property.
29  *
30  * <p>Note that there's a special FactoryBean for exposing a specific
31  * ServletContext attribute, named ServletContextAttributeFactoryBean.
32  * So if all you need from the ServletContext is access to a specific
33  * attribute, ServletContextAttributeFactoryBean allows you to expose
34  * a constructor argument or bean property of the attribute type,
35  * which is a preferable to a dependency on the full ServletContext.
36  *
37  * @author Juergen Hoeller
38  * @since 1.1.4
39  * @see javax.servlet.ServletContext
40  * @see org.springframework.web.context.ServletContextAware
41  * @see ServletContextAttributeFactoryBean
42  */

43 public class ServletContextFactoryBean implements FactoryBean, ServletContextAware {
44
45     private ServletContext JavaDoc servletContext;
46
47
48     public void setServletContext(ServletContext JavaDoc servletContext) {
49         this.servletContext = servletContext;
50     }
51
52
53     public Object JavaDoc getObject() {
54         return this.servletContext;
55     }
56
57     public Class JavaDoc getObjectType() {
58         return (this.servletContext != null ? this.servletContext.getClass() : ServletContext JavaDoc.class);
59     }
60
61     public boolean isSingleton() {
62         return true;
63     }
64
65 }
66
Popular Tags