001/*
002 * Copyright 2002-2014 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 *      https://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
017package org.springframework.web.context;
018
019import javax.servlet.ServletConfig;
020import javax.servlet.ServletContext;
021
022import org.springframework.context.ConfigurableApplicationContext;
023import org.springframework.lang.Nullable;
024
025/**
026 * Interface to be implemented by configurable web application contexts.
027 * Supported by {@link ContextLoader} and
028 * {@link org.springframework.web.servlet.FrameworkServlet}.
029 *
030 * <p>Note: The setters of this interface need to be called before an
031 * invocation of the {@link #refresh} method inherited from
032 * {@link org.springframework.context.ConfigurableApplicationContext}.
033 * They do not cause an initialization of the context on their own.
034 *
035 * @author Juergen Hoeller
036 * @since 05.12.2003
037 * @see #refresh
038 * @see ContextLoader#createWebApplicationContext
039 * @see org.springframework.web.servlet.FrameworkServlet#createWebApplicationContext
040 */
041public interface ConfigurableWebApplicationContext extends WebApplicationContext, ConfigurableApplicationContext {
042
043        /**
044         * Prefix for ApplicationContext ids that refer to context path and/or servlet name.
045         */
046        String APPLICATION_CONTEXT_ID_PREFIX = WebApplicationContext.class.getName() + ":";
047
048        /**
049         * Name of the ServletConfig environment bean in the factory.
050         * @see javax.servlet.ServletConfig
051         */
052        String SERVLET_CONFIG_BEAN_NAME = "servletConfig";
053
054
055        /**
056         * Set the ServletContext for this web application context.
057         * <p>Does not cause an initialization of the context: refresh needs to be
058         * called after the setting of all configuration properties.
059         * @see #refresh()
060         */
061        void setServletContext(@Nullable ServletContext servletContext);
062
063        /**
064         * Set the ServletConfig for this web application context.
065         * Only called for a WebApplicationContext that belongs to a specific Servlet.
066         * @see #refresh()
067         */
068        void setServletConfig(@Nullable ServletConfig servletConfig);
069
070        /**
071         * Return the ServletConfig for this web application context, if any.
072         */
073        @Nullable
074        ServletConfig getServletConfig();
075
076        /**
077         * Set the namespace for this web application context,
078         * to be used for building a default context config location.
079         * The root web application context does not have a namespace.
080         */
081        void setNamespace(@Nullable String namespace);
082
083        /**
084         * Return the namespace for this web application context, if any.
085         */
086        @Nullable
087        String getNamespace();
088
089        /**
090         * Set the config locations for this web application context in init-param style,
091         * i.e. with distinct locations separated by commas, semicolons or whitespace.
092         * <p>If not set, the implementation is supposed to use a default for the
093         * given namespace or the root web application context, as appropriate.
094         */
095        void setConfigLocation(String configLocation);
096
097        /**
098         * Set the config locations for this web application context.
099         * <p>If not set, the implementation is supposed to use a default for the
100         * given namespace or the root web application context, as appropriate.
101         */
102        void setConfigLocations(String... configLocations);
103
104        /**
105         * Return the config locations for this web application context,
106         * or {@code null} if none specified.
107         */
108        @Nullable
109        String[] getConfigLocations();
110
111}