martinc 2004/02/16 21:51:48 Modified: conf/share struts-config_1_1.dtd src/share/org/apache/struts/config ConfigRuleSet.java ModuleConfig.java src/share/org/apache/struts/config/impl ModuleConfigImpl.java Log: Restore the functionality for the 'type' attribute on form-beans and global-forwards elements in the config file. This allows the class name to be specified for all sub-elements, rather than having to specify it explicitly for each one. PR: 26942 Submitted by: Charlie Jones Revision Changes Path 1.42 +1 -3 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.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- struts-config_1_1.dtd 1 Feb 2004 16:14:07 -0000 1.41 +++ struts-config_1_1.dtd 17 Feb 2004 05:51:47 -0000 1.42 @@ -135,7 +135,6 @@ type Fully qualified Java class to use when instantiating ActionFormBean objects. If specified, the object must be a subclass of the default class type. - DEPRECATED. WARNING: For Struts 1.0, this value is ignored. You can set the default implementation class name with the @@ -282,7 +281,6 @@ type Fully qualified Java class to use when instantiating ActionForward objects. If specified, the object must be a subclass of the default class type. - DEPRECATED. WARNING: For Struts 1.0, this value is ignored. You can set the default implementation class name with the 1.17 +128 -12 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ConfigRuleSet.java 10 Jan 2004 21:03:34 -0000 1.16 +++ ConfigRuleSet.java 17 Feb 2004 05:51:47 -0000 1.17 @@ -177,11 +177,13 @@ ("struts-config/controller/set-property", "property", "value"); - digester.addObjectCreate + digester.addRule + ("struts-config/form-beans", + new SetActionFormBeanClassRule()); + + digester.addFactoryCreate ("struts-config/form-beans/form-bean", - // "org.apache.struts.config.FormBeanConfig", - "org.apache.struts.action.ActionFormBean", - "className"); + new ActionFormBeanFactory()); digester.addSetProperties ("struts-config/form-beans/form-bean"); digester.addSetNext @@ -223,11 +225,13 @@ ("struts-config/global-exceptions/exception/set-property", "property", "value"); - digester.addObjectCreate + digester.addRule + ("struts-config/global-forwards", + new SetGlobalForwardClassRule()); + + digester.addFactoryCreate ("struts-config/global-forwards/forward", - // "org.apache.struts.config.ForwardConfig", - "org.apache.struts.action.ActionForward", - "className"); + new GlobalForwardFactory()); digester.addSetProperties ("struts-config/global-forwards/forward"); digester.addSetNext @@ -315,6 +319,62 @@ /** + * Class that sets the name of the class to use when creating action form bean + * instances. The value is set on the object on the top of the stack, which + * must be a <code>org.apache.struts.config.ModuleConfig</code>. + */ +final class SetActionFormBeanClassRule extends Rule { + + public SetActionFormBeanClassRule() { + super(); + } + + public void begin(String namespace, String name, Attributes attributes) throws Exception { + String className = attributes.getValue("type"); + if (className != null) { + ModuleConfig mc = (ModuleConfig) digester.peek(); + mc.setActionFormBeanClass(className); + } + } + +} + + +/** + * An object creation factory which creates action form bean 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.ModuleConfig</code>. + */ +final class ActionFormBeanFactory extends AbstractObjectCreationFactory { + + public Object createObject(Attributes attributes) { + + // Identify the name of the class to instantiate + String className = attributes.getValue("className"); + if (className == null) { + ModuleConfig mc = (ModuleConfig) digester.peek(); + className = mc.getActionFormBeanClass(); + } + + // Instantiate the new object and return it + Object actionFormBean = null; + try { + actionFormBean = + RequestUtils.applicationInstance(className); + } catch (Exception e) { + digester.getLogger().error( + "ActionFormBeanFactory.createObject: ", e); + } + + return actionFormBean; + } + +} + + +/** * 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.ModuleConfig</code>. @@ -365,6 +425,62 @@ } return actionMapping; + } + +} + + +/** + * Class that sets the name of the class to use when creating global forward + * instances. The value is set on the object on the top of the stack, which + * must be a <code>org.apache.struts.config.ModuleConfig</code>. + */ +final class SetGlobalForwardClassRule extends Rule { + + public SetGlobalForwardClassRule() { + super(); + } + + public void begin(String namespace, String name, Attributes attributes) throws Exception { + String className = attributes.getValue("type"); + if (className != null) { + ModuleConfig mc = (ModuleConfig) digester.peek(); + mc.setGlobalForwardClass(className); + } + } + +} + + +/** + * An object creation factory which creates global forward 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.ModuleConfig</code>. + */ +final class GlobalForwardFactory extends AbstractObjectCreationFactory { + + public Object createObject(Attributes attributes) { + + // Identify the name of the class to instantiate + String className = attributes.getValue("className"); + if (className == null) { + ModuleConfig mc = (ModuleConfig) digester.peek(); + className = mc.getGlobalForwardClass(); + } + + // Instantiate the new object and return it + Object globalForward = null; + try { + globalForward = + RequestUtils.applicationInstance(className); + } catch (Exception e) { + digester.getLogger().error( + "GlobalForwardFactory.createObject: ", e); + } + + return globalForward; } } 1.6 +37 -9 jakarta-struts/src/share/org/apache/struts/config/ModuleConfig.java Index: ModuleConfig.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ModuleConfig.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ModuleConfig.java 13 Jan 2004 12:48:45 -0000 1.5 +++ ModuleConfig.java 17 Feb 2004 05:51:47 -0000 1.6 @@ -107,18 +107,33 @@ * @param prefix The prefix of the context-relative portion of the request URI. */ public void setPrefix(String prefix); + /** - * The default class name to be used when creating action mapping + * The default class name to be used when creating action form bean * instances. */ - String getActionMappingClass(); + String getActionFormBeanClass(); + /** - * The default class name to be used when creating action mapping - * instances. - * @param actionMappingClass default class name to be used when creating action mapping + * The default class name to be used when creating action form bean * instances. + * + * @param actionFormBeanClass default class name to be used when creating + * action form bean instances. */ + void setActionFormBeanClass(String actionFormBeanClass); + /** + * The default class name to be used when creating action mapping instances. + */ + String getActionMappingClass(); + + /** + * The default class name to be used when creating action mapping instances. + * + * @param actionMappingClass default class name to be used when creating + * action mapping instances. + */ void setActionMappingClass(String actionMappingClass); /** @@ -164,6 +179,19 @@ * has been frozen */ void addFormBeanConfig(FormBeanConfig config); + + /** + * The default class name to be used when creating global forward instances. + */ + String getGlobalForwardClass(); + + /** + * The default class name to be used when creating global forward instances. + * + * @param globalForwardClass default class name to be used when creating + * global forward instances. + */ + void setGlobalForwardClass(String globalForwardClass); /** * Add a new <code>ForwardConfig</code> instance to the set of global 1.10 +57 -11 jakarta-struts/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java Index: ModuleConfigImpl.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ModuleConfigImpl.java 13 Jan 2004 12:48:45 -0000 1.9 +++ ModuleConfigImpl.java 17 Feb 2004 05:51:48 -0000 1.10 @@ -100,7 +100,9 @@ super(); this.prefix = prefix; this.actionConfigs = new HashMap(); - this.actionMappingClass = "org.apache.struts.action.ActionMapping"; + this.actionFormBeanClass = "org.apache.struts.action.ActionFormBean"; + this.actionMappingClass = "org.apache.struts.action.ActionMapping"; + this.globalForwardClass = "org.apache.struts.action.ActionForward"; this.configured = false; this.controllerConfig = null; this.dataSources = new HashMap(); @@ -167,20 +169,37 @@ this.prefix = prefix; } + /** + * The default class name to be used when creating action form bean + * instances. + */ + public String getActionFormBeanClass() { + return this.actionFormBeanClass; + } /** - * The default class name to be used when creating action mapping + * The default class name to be used when creating action form bean * instances. + * + * @param actionFormBeanClass default class name to be used when creating + * action form bean instances. + */ + public void setActionFormBeanClass(String actionFormBeanClass) { + this.actionFormBeanClass = actionFormBeanClass; + } + + /** + * The default class name to be used when creating action mapping instances. */ public String getActionMappingClass() { return this.actionMappingClass; } /** - * The default class name to be used when creating action mapping - * instances. - * @param actionMappingClass default class name to be used when creating - * action mapping instances. + * The default class name to be used when creating action mapping instances. + * + * @param actionMappingClass default class name to be used when creating + * action mapping instances. */ public void setActionMappingClass(String actionMappingClass) { this.actionMappingClass = actionMappingClass; @@ -261,6 +280,23 @@ } /** + * The default class name to be used when creating global forward instances. + */ + public String getGlobalForwardClass() { + return this.globalForwardClass; + } + + /** + * The default class name to be used when creating global forward instances. + * + * @param globalForwardClass default class name to be used when creating + * action mapping instances. + */ + public void setGlobalForwardClass(String globalForwardClass) { + this.globalForwardClass = globalForwardClass; + } + + /** * Add a new <code>ForwardConfig</code> instance to the set of global * forwards associated with this module. * @@ -690,10 +726,20 @@ protected String prefix = null; /** - * The default class name to be used when creating action mapping + * The default class name to be used when creating action form bean * instances. */ + protected String actionFormBeanClass = "org.apache.struts.action.ActionFormBean"; + + /** + * The default class name to be used when creating action mapping instances. + */ protected String actionMappingClass = "org.apache.struts.action.ActionMapping"; + + /** + * The default class name to be used when creating global forward instances. + */ + protected String globalForwardClass = "org.apache.struts.action.ActionForward"; /** * Matches action config paths against compiled wildcard patterns
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]