- /*
- * Copyright 2002-2004 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package org.springframework.web.context.support;
- import javax.servlet.ServletContext;
- import org.springframework.beans.BeansException;
- import org.springframework.context.support.StaticApplicationContext;
- import org.springframework.ui.context.Theme;
- import org.springframework.ui.context.ThemeSource;
- import org.springframework.ui.context.support.UiApplicationContextUtils;
- import org.springframework.web.context.ConfigurableWebApplicationContext;
- /**
- * Static WebApplicationContext implementation for testing.
- * Not for use in production applications.
- *
- * <p>In addition to the special beans detected by AbstractApplicationContext,
- * this class detects a ThemeSource bean in the context, with the name
- * "themeSource".
- *
- * @author Rod Johnson
- * @author Juergen Hoeller
- * @see org.springframework.ui.context.ThemeSource
- */
- public class StaticWebApplicationContext extends StaticApplicationContext
- implements ConfigurableWebApplicationContext {
- private ServletContext servletContext;
- private String namespace;
- private ThemeSource themeSource;
- public void setServletContext(ServletContext servletContext) {
- this.servletContext = servletContext;
- }
- public ServletContext getServletContext() {
- return servletContext;
- }
- public void setNamespace(String namespace) {
- this.namespace = namespace;
- }
- protected String getNamespace() {
- return this.namespace;
- }
- public void setConfigLocations(String[] configLocations) {
- throw new UnsupportedOperationException("StaticWebApplicationContext does not support configLocations");
- }
- public void refresh() throws BeansException {
- if (this.namespace != null) {
- setDisplayName("StaticWebApplicationContext for namespace '" + this.namespace + "'");
- }
- else {
- setDisplayName("Root StaticWebApplicationContext");
- }
- super.refresh();
- }
- /**
- * Initialize the theme capability.
- */
- protected void onRefresh() {
- this.themeSource = UiApplicationContextUtils.initThemeSource(this);
- }
- public Theme getTheme(String themeName) {
- return this.themeSource.getTheme(themeName);
- }
- }