Source Code Cross Referenced for AbstractRefreshableWebApplicationContext.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » context » support » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.web.context.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.web.context.support;
018:
019:        import javax.servlet.ServletConfig;
020:        import javax.servlet.ServletContext;
021:
022:        import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
023:        import org.springframework.context.support.AbstractRefreshableApplicationContext;
024:        import org.springframework.core.io.Resource;
025:        import org.springframework.core.io.support.ResourcePatternResolver;
026:        import org.springframework.ui.context.Theme;
027:        import org.springframework.ui.context.ThemeSource;
028:        import org.springframework.ui.context.support.UiApplicationContextUtils;
029:        import org.springframework.util.SystemPropertyUtils;
030:        import org.springframework.web.context.ConfigurableWebApplicationContext;
031:        import org.springframework.web.context.ServletConfigAware;
032:        import org.springframework.web.context.ServletContextAware;
033:        import org.springframework.web.context.request.RequestScope;
034:        import org.springframework.web.context.request.SessionScope;
035:
036:        /**
037:         * {@link org.springframework.context.support.AbstractRefreshableApplicationContext}
038:         * subclass which implements the
039:         * {@link org.springframework.web.context.ConfigurableWebApplicationContext}
040:         * interface for web environments. Provides a "configLocations" property,
041:         * to be populated through the ConfigurableWebApplicationContext interface
042:         * on web application startup.
043:         *
044:         * <p>This class is as easy to subclass as AbstractRefreshableApplicationContext:
045:         * All you need to implements is the {@link #loadBeanDefinitions} method;
046:         * see the superclass javadoc for details. Note that implementations are supposed
047:         * to load bean definitions from the files specified by the locations returned
048:         * by the {@link #getConfigLocations} method.
049:         *
050:         * <p>Interprets resource paths as servlet context resources, i.e. as paths beneath
051:         * the web application root. Absolute paths, e.g. for files outside the web app root,
052:         * can be accessed via "file:" URLs, as implemented by
053:         * {@link org.springframework.core.io.DefaultResourceLoader}.
054:         *
055:         * <p>In addition to the special beans detected by
056:         * {@link org.springframework.context.support.AbstractApplicationContext},
057:         * this class detects a bean of type {@link org.springframework.ui.context.ThemeSource}
058:         * in the context, under the special bean name "themeSource".
059:         *
060:         * <p><b>This is the web context to be subclassed for a different bean definition format.</b>
061:         * Such a context implementation can be specified as "contextClass" context-param
062:         * for {@link org.springframework.web.context.ContextLoader} or as "contextClass"
063:         * init-param for {@link org.springframework.web.servlet.FrameworkServlet},
064:         * replacing the default {@link XmlWebApplicationContext}. It will then automatically
065:         * receive the "contextConfigLocation" context-param or init-param, respectively.
066:         *
067:         * <p>Note that WebApplicationContext implementations are generally supposed
068:         * to configure themselves based on the configuration received through the
069:         * {@link ConfigurableWebApplicationContext} interface. In contrast, a standalone
070:         * application context might allow for configuration in custom startup code
071:         * (for example, {@link org.springframework.context.support.GenericApplicationContext}).
072:         *
073:         * @author Juergen Hoeller
074:         * @since 1.1.3
075:         * @see #loadBeanDefinitions
076:         * @see org.springframework.web.context.ConfigurableWebApplicationContext#setConfigLocations
077:         * @see org.springframework.ui.context.ThemeSource
078:         * @see XmlWebApplicationContext
079:         */
080:        public abstract class AbstractRefreshableWebApplicationContext extends
081:                AbstractRefreshableApplicationContext implements 
082:                ConfigurableWebApplicationContext, ThemeSource {
083:
084:            /** Servlet context that this context runs in */
085:            private ServletContext servletContext;
086:
087:            /** Servlet config that this context runs in, if any */
088:            private ServletConfig servletConfig;
089:
090:            /** Namespace of this context, or <code>null</code> if root */
091:            private String namespace;
092:
093:            /** Paths to XML configuration files */
094:            private String[] configLocations;
095:
096:            /** the ThemeSource for this ApplicationContext */
097:            private ThemeSource themeSource;
098:
099:            public AbstractRefreshableWebApplicationContext() {
100:                setDisplayName("Root WebApplicationContext");
101:            }
102:
103:            public void setServletContext(ServletContext servletContext) {
104:                this .servletContext = servletContext;
105:            }
106:
107:            public ServletContext getServletContext() {
108:                return this .servletContext;
109:            }
110:
111:            public void setServletConfig(ServletConfig servletConfig) {
112:                this .servletConfig = servletConfig;
113:                if (servletConfig != null && this .servletContext == null) {
114:                    this .servletContext = servletConfig.getServletContext();
115:                }
116:            }
117:
118:            public ServletConfig getServletConfig() {
119:                return this .servletConfig;
120:            }
121:
122:            public void setNamespace(String namespace) {
123:                this .namespace = namespace;
124:                if (namespace != null) {
125:                    setDisplayName("WebApplicationContext for namespace '"
126:                            + namespace + "'");
127:                }
128:            }
129:
130:            public String getNamespace() {
131:                return this .namespace;
132:            }
133:
134:            public void setConfigLocations(String[] locations) {
135:                this .configLocations = new String[locations.length];
136:                for (int i = 0; i < locations.length; i++) {
137:                    this .configLocations[i] = resolvePath(locations[i]);
138:                }
139:            }
140:
141:            public String[] getConfigLocations() {
142:                return (this .configLocations != null ? this .configLocations
143:                        : getDefaultConfigLocations());
144:            }
145:
146:            /**
147:             * Return the default config locations to use, for the case where no
148:             * explicit config locations have been specified.
149:             * <p>The default implementation returns <code>null</code>,
150:             * requiring explicit config locations.
151:             * @see #setConfigLocations
152:             */
153:            protected String[] getDefaultConfigLocations() {
154:                return null;
155:            }
156:
157:            /**
158:             * Register request/session scopes, a {@link ServletContextAwareProcessor}, etc.
159:             */
160:            protected void postProcessBeanFactory(
161:                    ConfigurableListableBeanFactory beanFactory) {
162:                beanFactory.registerScope(SCOPE_REQUEST, new RequestScope());
163:                beanFactory.registerScope(SCOPE_SESSION,
164:                        new SessionScope(false));
165:                beanFactory.registerScope(SCOPE_GLOBAL_SESSION,
166:                        new SessionScope(true));
167:
168:                beanFactory
169:                        .addBeanPostProcessor(new ServletContextAwareProcessor(
170:                                this .servletContext, this .servletConfig));
171:                beanFactory
172:                        .ignoreDependencyInterface(ServletContextAware.class);
173:                beanFactory.ignoreDependencyInterface(ServletConfigAware.class);
174:            }
175:
176:            /**
177:             * Resolve the given path, replacing placeholders with corresponding
178:             * system property values if necessary. Applied to config locations.
179:             * @param path the original file path
180:             * @return the resolved file path
181:             * @see org.springframework.util.SystemPropertyUtils#resolvePlaceholders
182:             */
183:            protected String resolvePath(String path) {
184:                return SystemPropertyUtils.resolvePlaceholders(path);
185:            }
186:
187:            /**
188:             * This implementation supports file paths beneath the root of the ServletContext.
189:             * @see ServletContextResource
190:             */
191:            protected Resource getResourceByPath(String path) {
192:                return new ServletContextResource(this .servletContext, path);
193:            }
194:
195:            /**
196:             * This implementation supports pattern matching in unexpanded WARs too.
197:             * @see ServletContextResourcePatternResolver
198:             */
199:            protected ResourcePatternResolver getResourcePatternResolver() {
200:                return new ServletContextResourcePatternResolver(this );
201:            }
202:
203:            /**
204:             * Initialize the theme capability.
205:             */
206:            protected void onRefresh() {
207:                this .themeSource = UiApplicationContextUtils
208:                        .initThemeSource(this );
209:            }
210:
211:            public Theme getTheme(String themeName) {
212:                return this.themeSource.getTheme(themeName);
213:            }
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.