You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by pb...@apache.org on 2007/08/18 21:34:51 UTC
svn commit: r567318 - in
/struts/struts1/trunk/core/src/main/java/org/apache/struts:
action/ActionServlet.java config/ModuleConfigPostProcessor.java
Author: pbenedict
Date: Sat Aug 18 12:34:50 2007
New Revision: 567318
URL: http://svn.apache.org/viewvc?view=rev&rev=567318
Log:
STR-3085: Enhance post-processing by adding before/after events for child configs
Modified:
struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java
struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ModuleConfigPostProcessor.java
Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java?view=diff&rev=567318&r1=567317&r2=567318
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java Sat Aug 18 12:34:50 2007
@@ -42,6 +42,7 @@
import org.apache.struts.Globals;
import org.apache.struts.chain.ComposableRequestProcessor;
import org.apache.struts.config.ActionConfig;
+import org.apache.struts.config.BaseConfig;
import org.apache.struts.config.ConfigRuleSet;
import org.apache.struts.config.ExceptionConfig;
import org.apache.struts.config.FormBeanConfig;
@@ -56,7 +57,6 @@
import org.apache.struts.util.MessageResourcesFactory;
import org.apache.struts.util.ModuleUtils;
import org.apache.struts.util.RequestUtils;
-import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.servlet.ServletContext;
@@ -68,14 +68,10 @@
import java.io.IOException;
import java.io.InputStream;
-
import java.math.BigDecimal;
import java.math.BigInteger;
-
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLConnection;
-
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
@@ -365,7 +361,7 @@
initModuleForwards(moduleConfig);
initModuleExceptionConfigs(moduleConfig);
initModuleActions(moduleConfig);
- postProcessModule(moduleConfig);
+ postProcessConfig(moduleConfig);
moduleConfig.freeze();
Enumeration names = getServletConfig().getInitParameterNames();
@@ -388,7 +384,7 @@
initModuleForwards(moduleConfig);
initModuleExceptionConfigs(moduleConfig);
initModuleActions(moduleConfig);
- postProcessModule(moduleConfig);
+ postProcessConfig(moduleConfig);
moduleConfig.freeze();
}
@@ -896,22 +892,7 @@
}
}
}
-
- protected void postProcessModule(ModuleConfig moduleConfig) {
- String plugInKey = Globals.PLUG_INS_KEY + moduleConfig.getPrefix();
- PlugIn[] plugIns = (PlugIn[]) getServletContext().getAttribute(plugInKey);
- if ((plugIns == null) || (plugIns.length == 0)) {
- log.debug("No plugins to attempt post processing");
- }
-
- for (int i = 0; i < plugIns.length; i++) {
- PlugIn plugIn = plugIns[i];
- if (plugIn instanceof ModuleConfigPostProcessor) {
- ((ModuleConfigPostProcessor) plugIn).postProcessModule(moduleConfig);
- }
- }
- }
-
+
/**
* <p>Initialize the form beans for the specified module.</p>
*
@@ -932,7 +913,9 @@
for (int i = 0; i < formBeans.length; i++) {
FormBeanConfig beanConfig = formBeans[i];
+ postProcessConfig(beanConfig, config, true);
processFormBeanExtension(beanConfig, config);
+ postProcessConfig(beanConfig, config, false);
}
for (int i = 0; i < formBeans.length; i++) {
@@ -1078,7 +1061,9 @@
for (int i = 0; i < forwards.length; i++) {
ForwardConfig forward = forwards[i];
+ postProcessConfig(forward, config, true);
processForwardExtension(forward, config, null);
+ postProcessConfig(forward, config, false);
}
for (int i = 0; i < forwards.length; i++) {
@@ -1227,7 +1212,9 @@
for (int i = 0; i < exceptions.length; i++) {
ExceptionConfig exception = exceptions[i];
+ postProcessConfig(exception, config, true);
processExceptionExtension(exception, config, null);
+ postProcessConfig(exception, config, false);
}
for (int i = 0; i < exceptions.length; i++) {
@@ -1374,6 +1361,10 @@
for (int i = 0; i < actionConfigs.length; i++) {
ActionConfig actionConfig = actionConfigs[i];
+ postProcessConfig(actionConfig, config, true);
+ processActionConfigExtension(actionConfig, config);
+ postProcessConfig(actionConfig, config, false);
+
// Verify the form, if specified, exists to help the developer
// detect a possible typo. It is also possible the missing
// reference is a dynamic runtime bean
@@ -1385,8 +1376,6 @@
actionConfig.getPath(), formName));
}
}
-
- processActionConfigExtension(actionConfig, config);
}
for (int i = 0; i < actionConfigs.length; i++) {
@@ -1556,6 +1545,7 @@
continue;
}
+ postProcessConfig(mrcs[i], config, true);
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix()
+ "' message resources from '" + mrcs[i].getParameter()
@@ -1576,6 +1566,8 @@
resources.setReturnNull(mrcs[i].getNull());
resources.setEscape(mrcs[i].isEscape());
+
+ postProcessConfig(mrcs[i], config, false);
getServletContext().setAttribute(mrcs[i].getKey()
+ config.getPrefix(), resources);
}
@@ -1957,4 +1949,64 @@
processor.process(request, response);
}
+
+ /**
+ * Returns the plugins for the specified module
+ *
+ * @param moduleConfig the module configuration
+ * @return the array of plugins or <code>null</code>
+ */
+ private PlugIn[] getModulePlugIns(ModuleConfig moduleConfig) {
+ String plugInKey = Globals.PLUG_INS_KEY + moduleConfig.getPrefix();
+ return (PlugIn[]) getServletContext().getAttribute(plugInKey);
+ }
+
+ /**
+ * Applies the plugin post-processors for the specified configuration
+ * object.
+ *
+ * @param config the configuration
+ * @param moduleConfig the parent module configuration
+ * @param before <code>true</code> if applying before initialization;
+ * otherwise <code>false</code>
+ */
+ private void postProcessConfig(BaseConfig config, ModuleConfig moduleConfig,
+ boolean before) {
+ PlugIn[] plugIns = getModulePlugIns(moduleConfig);
+ if ((plugIns == null) || (plugIns.length == 0)) {
+ return;
+ }
+
+ for (int i = 0; i < plugIns.length; i++) {
+ PlugIn plugIn = plugIns[i];
+ if (plugIn instanceof ModuleConfigPostProcessor) {
+ ModuleConfigPostProcessor p = (ModuleConfigPostProcessor) plugIn;
+ if (before) {
+ p.postProcessBeforeInitialization(config, moduleConfig);
+ } else {
+ p.postProcessAfterInitialization(config, moduleConfig);
+ }
+ }
+ }
+ }
+
+ /**
+ * Applies the plugin post-processors for the specified module.
+ *
+ * @param config the module configuration
+ */
+ private void postProcessConfig(ModuleConfig moduleConfig) {
+ PlugIn[] plugIns = getModulePlugIns(moduleConfig);
+ if ((plugIns == null) || (plugIns.length == 0)) {
+ return;
+ }
+
+ for (int i = 0; i < plugIns.length; i++) {
+ PlugIn plugIn = plugIns[i];
+ if (plugIn instanceof ModuleConfigPostProcessor) {
+ ((ModuleConfigPostProcessor) plugIn).postProcessAfterInitialization(moduleConfig);
+ }
+ }
+ }
+
}
Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ModuleConfigPostProcessor.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ModuleConfigPostProcessor.java?view=diff&rev=567318&r1=567317&r2=567318
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ModuleConfigPostProcessor.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ModuleConfigPostProcessor.java Sat Aug 18 12:34:50 2007
@@ -24,19 +24,52 @@
* This interface is to be implemented by any plugin for custom modification of
* a module after it is been configured but before it is frozen. This allows for
* overriding or adding properties after standard initialization.
+ * <p>
+ * The types of child configurations provided are {@link ActionConfig},
+ * {@link ExceptionConfig}, {@link ForwardConfig} and
+ * {@link MessageResourcesConfig}. If interested in a particular configuration
+ * class, use the <code>instanceof</code> operator to check before casting.
+ * <p>
+ * Possible post-processors implementations may include property substitutions (<code>${...}</code>),
+ * querying additional configuration from a repository, extended configuration
+ * validation, preparing message resources for a particular domain/host,
+ * logging, etc.
*
+ * @see BaseConfig
+ * @see ActionConfig
+ * @see ExceptionConfig
+ * @see ForwardConfig
+ * @see MessageResourcesConfig
* @see ModuleConfig
- * @see ModuleConfig#freeze()
* @since Struts 1.4
* @version $Rev$
*/
public interface ModuleConfigPostProcessor {
/**
+ * Applies this post-processor to the specified configuration object after
+ * it has been initialized by Struts but before it is frozen.
+ *
+ * @param config the configuration
+ * @param moduleConfig the parent module configuration
+ */
+ void postProcessAfterInitialization(BaseConfig config, ModuleConfig moduleConfig);
+
+ /**
* Modify the specified module after its standard initialization.
*
- * @param config the module
+ * @param config the module configuration
+ */
+ void postProcessAfterInitialization(ModuleConfig moduleConfig);
+
+ /**
+ * Applies this post-processor to the specified configuration object
+ * <i>before</i> it has been initialized and processed by Struts (such as
+ * heirarchy extensions).
+ *
+ * @param config the configuration
+ * @param moduleConfig the parent module configuration
*/
- void postProcessModule(ModuleConfig config);
+ void postProcessBeforeInitialization(BaseConfig config, ModuleConfig moduleConfig);
}