You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ma...@apache.org on 2002/03/04 06:38:24 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/config ApplicationConfig.java ConfigRuleSet.java
martinc 02/03/03 21:38:24
Modified: conf/share struts-config_1_1.dtd
src/share/org/apache/struts/action ActionServlet.java
src/share/org/apache/struts/config ApplicationConfig.java
ConfigRuleSet.java
Log:
Extend support for the specification of the class to instantiate for action
mappings. The class name may now be specified on a per-module basis, using:
<action-mappings type="com.mycompany.MyActionMapping">
Support for the global setting, using the 'mapping' servlet init-param, has
also been re-introduced for backward compatibility.
PR: 6583
Submitted by: Martin Cooper, Andre Beskrowni
Revision Changes Path
1.13 +2 -2 jakarta-struts/conf/share/struts-config_1_1.dtd
Index: struts-config_1_1.dtd
===================================================================
RCS file: /home/cvs/jakarta-struts/conf/share/struts-config_1_1.dtd,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- struts-config_1_1.dtd 23 Feb 2002 22:54:17 -0000 1.12
+++ struts-config_1_1.dtd 4 Mar 2002 05:38:23 -0000 1.13
@@ -11,7 +11,7 @@
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
- $Id: struts-config_1_1.dtd,v 1.12 2002/02/23 22:54:17 craigmcc Exp $
+ $Id: struts-config_1_1.dtd,v 1.13 2002/03/04 05:38:23 martinc Exp $
-->
@@ -304,7 +304,7 @@
defined:
type Fully qualified Java class name of the ActionMapping
- implementation class to be used. DEPRECATED.
+ implementation class to be used.
WARNING: For Struts 1.0, this value is ignored. You
can set the default implementation class name with the
1.94 +12 -5 jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
Index: ActionServlet.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -r1.93 -r1.94
--- ActionServlet.java 26 Feb 2002 03:38:56 -0000 1.93
+++ ActionServlet.java 4 Mar 2002 05:38:23 -0000 1.94
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.93 2002/02/26 03:38:56 dwinterfeldt Exp $
- * $Revision: 1.93 $
- * $Date: 2002/02/26 03:38:56 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.94 2002/03/04 05:38:23 martinc Exp $
+ * $Revision: 1.94 $
+ * $Date: 2002/03/04 05:38:23 $
*
* ====================================================================
*
@@ -269,7 +269,7 @@
*
* @author Craig R. McClanahan
* @author Ted Husted
- * @version $Revision: 1.93 $ $Date: 2002/02/26 03:38:56 $
+ * @version $Revision: 1.94 $ $Date: 2002/03/04 05:38:23 $
*/
public class ActionServlet
@@ -756,9 +756,16 @@
// Parse the application configuration for this application
ApplicationConfig config = null;
InputStream input = null;
- String value = null;
+ String mapping = null;
try {
config = new ApplicationConfig(prefix, this);
+
+ // Support for application-wide ActionMapping override
+ mapping = getServletConfig().getInitParameter("mapping");
+ if (mapping != null) {
+ config.setActionMappingClass(mapping);
+ }
+
Digester digester = initConfigDigester();
digester.push(config);
input = getServletContext().getResourceAsStream(path);
1.11 +20 -4 jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java
Index: ApplicationConfig.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ApplicationConfig.java 23 Feb 2002 23:53:29 -0000 1.10
+++ ApplicationConfig.java 4 Mar 2002 05:38:23 -0000 1.11
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v 1.10 2002/02/23 23:53:29 craigmcc Exp $
- * $Revision: 1.10 $
- * $Date: 2002/02/23 23:53:29 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v 1.11 2002/03/04 05:38:23 martinc Exp $
+ * $Revision: 1.11 $
+ * $Date: 2002/03/04 05:38:23 $
*
* ====================================================================
*
@@ -84,7 +84,7 @@
* previous Struts behavior that only supported one application.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.10 $ $Date: 2002/02/23 23:53:29 $
+ * @version $Revision: 1.11 $ $Date: 2002/03/04 05:38:23 $
* @since Struts 1.1
*/
@@ -244,6 +244,22 @@
public ActionServlet getServlet() {
return (this.servlet);
+ }
+
+
+ /**
+ * The default class name to be used when creating action mapping
+ * instances.
+ */
+ protected String actionMappingClass =
+ "org.apache.struts.action.ActionMapping";
+
+ public String getActionMappingClass() {
+ return this.actionMappingClass;
+ }
+
+ public void setActionMappingClass(String actionMappingClass) {
+ this.actionMappingClass = actionMappingClass;
}
1.9 +65 -8 jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java
Index: ConfigRuleSet.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ConfigRuleSet.java 27 Feb 2002 06:20:59 -0000 1.8
+++ ConfigRuleSet.java 4 Mar 2002 05:38:23 -0000 1.9
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v 1.8 2002/02/27 06:20:59 martinc Exp $
- * $Revision: 1.8 $
- * $Date: 2002/02/27 06:20:59 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v 1.9 2002/03/04 05:38:23 martinc Exp $
+ * $Revision: 1.9 $
+ * $Date: 2002/03/04 05:38:23 $
*
* ====================================================================
*
@@ -63,6 +63,7 @@
package org.apache.struts.config;
+import org.apache.commons.digester.AbstractObjectCreationFactory;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.Rule;
import org.apache.commons.digester.RuleSetBase;
@@ -74,7 +75,7 @@
* configuration file (<code>struts-config.xml</code>).</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.8 $ $Date: 2002/02/27 06:20:59 $
+ * @version $Revision: 1.9 $ $Date: 2002/03/04 05:38:23 $
* @since Struts 1.1
*/
@@ -112,11 +113,13 @@
("struts-config/data-sources/data-source/set-property",
new AddDataSourcePropertyRule(digester));
- digester.addObjectCreate
+ digester.addRule
+ ("struts-config/action-mappings",
+ new SetActionMappingClassRule(digester));
+
+ digester.addFactoryCreate
("struts-config/action-mappings/action",
- // "org.apache.struts.config.ActionConfig",
- "org.apache.struts.action.ActionMapping",
- "className");
+ new ActionMappingFactory());
digester.addSetProperties
("struts-config/action-mappings/action");
digester.addSetNext
@@ -291,3 +294,57 @@
}
+
+/**
+ * Class that sets the name of the class to use when creating action mapping
+ * instances. The value is set on the object on the top of the stack, which
+ * must be a <code>org.apache.struts.config.ApplicationConfig</code>.
+ */
+final class SetActionMappingClassRule extends Rule {
+
+ public SetActionMappingClassRule(Digester digester) {
+ super(digester);
+ }
+
+ public void begin(Attributes attributes) throws Exception {
+ String className = attributes.getValue("type");
+ if (className != null) {
+ ApplicationConfig ac = (ApplicationConfig) digester.peek();
+ ac.setActionMappingClass(className);
+ }
+ }
+
+}
+
+
+/**
+ * An object creation factory which creates action mapping instances, taking
+ * into account the default class name, which may have been specified on the
+ * parent element and which is made available through the object on the top
+ * of the stack, which must be a
+ * <code>org.apache.struts.config.ApplicationConfig</code>.
+ */
+final class ActionMappingFactory extends AbstractObjectCreationFactory {
+
+ public Object createObject(Attributes attributes) {
+
+ // Identify the name of the class to instantiate
+ String className = attributes.getValue("className");
+ if (className == null) {
+ ApplicationConfig ac = (ApplicationConfig) digester.peek();
+ className = ac.getActionMappingClass();
+ }
+
+ // Instantiate the new object and return it
+ Object actionMapping = null;
+ try {
+ Class clazz = digester.getClassLoader().loadClass(className);
+ actionMapping = clazz.newInstance();
+ } catch (Exception e) {
+ digester.log("ActionMappingFactory.createObject: ", e);
+ }
+
+ return actionMapping;
+ }
+
+}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>