Repository: struts Updated Branches: refs/heads/support-2-3 d028886cd -> 9860ef829
WW-4410 Adds dedicated interface to allow inject ServletContext Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/9860ef82 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/9860ef82 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/9860ef82 Branch: refs/heads/support-2-3 Commit: 9860ef829a95428be4fd2638f984b830855e5812 Parents: d028886 Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Thu Feb 25 21:29:25 2016 +0100 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Thu Feb 25 21:29:25 2016 +0100 ---------------------------------------------------------------------- ...ervletContextAwareConfigurationProvider.java | 32 ++++++++++++++++++++ .../apache/struts2/dispatcher/Dispatcher.java | 3 ++ 2 files changed, 35 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/9860ef82/core/src/main/java/com/opensymphony/xwork2/config/ServletContextAwareConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/com/opensymphony/xwork2/config/ServletContextAwareConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/ServletContextAwareConfigurationProvider.java new file mode 100644 index 0000000..506d906 --- /dev/null +++ b/core/src/main/java/com/opensymphony/xwork2/config/ServletContextAwareConfigurationProvider.java @@ -0,0 +1,32 @@ +/* + * Copyright 2002-2006,2009 The Apache Software Foundation. + * + * 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 com.opensymphony.xwork2.config; + +import javax.servlet.ServletContext; + +/** + * Dedicated interface to allow inject {@link ServletContext} and perform initialisation based in it + */ +public interface ServletContextAwareConfigurationProvider extends ConfigurationProvider { + + /** + * This is a lazy constructor, called just after class was initiated + * + * @param servletContext current instance of {@link ServletContext} + */ + void initWithContext(ServletContext servletContext); + +} http://git-wip-us.apache.org/repos/asf/struts/blob/9860ef82/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index 3a4e305..18e8a90 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -394,6 +394,9 @@ public class Dispatcher { try { Class cls = ClassLoaderUtil.loadClass(cname, this.getClass()); ConfigurationProvider prov = (ConfigurationProvider)cls.newInstance(); + if (prov instanceof ServletContextAwareConfigurationProvider) { + ((ServletContextAwareConfigurationProvider)prov).initWithContext(servletContext); + } configurationManager.addContainerProvider(prov); } catch (InstantiationException e) { throw new ConfigurationException("Unable to instantiate provider: "+cname, e);