Author: germuska Date: Thu May 12 15:41:19 2005 New Revision: 169898 URL: http://svn.apache.org/viewcvs?rev=169898&view=rev Log: Extend arbitrary property maps from ActionConfig to nearly all config objects by introducing BaseConfig class. Add some explanation to the DTD about it. For Bugzilla enhancement request 34691; thanks to Riyaz Mansoor for the basic patch and the motivation.
Note that this does not apply to the PlugInConfig object because (a) that object is not very public to developers, (b) developers must always create a concrete implementation of PlugIn, and so are able to create bean properties as necessary (c) PlugInConfig already had a "properties" object which would have conflicted with the one in BaseConfig. If people are pained by this small inconsistency or clamor for the feature to be extended, we can revisit. Added: struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java (with props) Modified: struts/core/trunk/conf/share/struts-config_1_3.dtd struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java struts/core/trunk/src/share/org/apache/struts/config/ControllerConfig.java struts/core/trunk/src/share/org/apache/struts/config/ExceptionConfig.java struts/core/trunk/src/share/org/apache/struts/config/FormBeanConfig.java struts/core/trunk/src/share/org/apache/struts/config/FormPropertyConfig.java struts/core/trunk/src/share/org/apache/struts/config/ForwardConfig.java struts/core/trunk/src/share/org/apache/struts/config/MessageResourcesConfig.java struts/core/trunk/src/share/org/apache/struts/config/PlugInConfig.java struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java Modified: struts/core/trunk/conf/share/struts-config_1_3.dtd URL: http://svn.apache.org/viewcvs/struts/core/trunk/conf/share/struts-config_1_3.dtd?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/conf/share/struts-config_1_3.dtd (original) +++ struts/core/trunk/conf/share/struts-config_1_3.dtd Thu May 12 15:41:19 2005 @@ -657,18 +657,18 @@ can be passed whatever other properties may be required to configure the object without changing how the struts-config is parsed. - Within the <action> element, an alternate syntax is supported. By using + Since Struts 1.3, an alternate syntax is supported. By using the "key" attribute instead of the "property" attribute, you can set - arbitrary string properties on the ActionConfig object which is populated - based on the <action> element. + arbitrary string properties on the Config object which is populated + based on the containing element. NOTE: the "key" attribute is NOT + supported for <set-property> inside a <plug-in> element. property Name of the JavaBeans property whose setter method will be called. Exactly one of "property" or "key" must be specified. - key In <action> only, the key which will be used to store - the specified value in the ActionConfig object associated - with this path. Exactly one of + key Where supported, the key which will be used to store + the specified value in the given config object. Exactly one of "property" or "key" must be specified. value String representation of the value to which this Modified: struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java Thu May 12 15:41:19 2005 @@ -21,7 +21,6 @@ import org.apache.struts.util.RequestUtils; import org.apache.commons.beanutils.BeanUtils; -import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.Properties; @@ -37,19 +36,13 @@ * @version $Rev$ $Date$ * @since Struts 1.1 */ -public class ActionConfig implements Serializable { +public class ActionConfig extends BaseConfig { // ----------------------------------------------------- Instance Variables /** - * Indicates if configuration of this component been completed. - */ - protected boolean configured = false; - - - /** * The set of exception handling configurations for this * action, if any, keyed by the <code>type</code> property. */ @@ -62,12 +55,6 @@ */ protected HashMap forwards = new HashMap(); - /** - * A map of arbitrary properties configured for this action mapping. - * @since Struts 1.3 - */ - protected Properties properties = new Properties(); - // ------------------------------------------------------------- Properties @@ -800,13 +787,13 @@ } // Inherit forward properties - Properties baseProperties = baseConfig.properties; + Properties baseProperties = baseConfig.getProperties(); Enumeration keys = baseProperties.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // Check if we have this property before copying it - String value = properties.getProperty(key); + String value = this.getProperty(key); if (value == null) { value = baseProperties.getProperty(key); setProperty(key, value); @@ -855,56 +842,6 @@ } - /** - * <p>Set an arbitary key/value pair which can be retrieved by the action - * executed for this mapping. This facility should eliminate many use cases - * for subclassing <code>ActionConfig</code> or <code>ActionMapping</code> by - * providing more than just the single <code>parameter</code> property for passing - * arbitrary configuration information into an action.</p> - * - * <p>This method must not be called after configuration is complete, or an - * <code>IllegalStateException</code> will be thrown. Rather than calling it in Java code, - * it is used by editing the <code>struts-config</code> file. Specifically, these values can - * be set by using a <code><set-property></code> element nested within the <code><action></code> - * element. The element should use the <code>key</code> attribute, not the <code>name</code> - * attribute: the <code>name</code> attribute is for setting bean properties on a custom subclass - * of <code>ActionConfig</code>. - * </p> - * - * <p><b>Example</b> - * <code><pre> - * <action path="/example" type="com.example.MyAction"> - * <set-property key="foo" property="bar" /> - * </action> - * </pre></code> - * </p> - * - * @param key the key by which this value will be retrieved - * @param value the value which should be returned when <code>getProperty(key)</code> is - * called with the corresponding <code>key</code>. - * @since Struts 1.3 - * @exception IllegalStateException if this module configuration - * has been frozen - */ - public void setProperty(String key, String value) { - - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } - properties.setProperty(key,value); - - } - - /** - * Return the property-value for the specified key, if any; - * otherwise return <code>null</code>. - * - * @param key a key specified in the <code>struts-config</code> file. - * @since Struts 1.3 - */ - public String getProperty(String key) { - return properties.getProperty(key); - } /** * Return the exception configuration for the specified type, if any; @@ -1006,7 +943,7 @@ */ public void freeze() { - configured = true; + super.freeze(); ExceptionConfig[] econfigs = findExceptionConfigs(); for (int i = 0; i < econfigs.length; i++) { Added: struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java?rev=169898&view=auto ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java (added) +++ struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java Thu May 12 15:41:19 2005 @@ -0,0 +1,121 @@ +/* + * $Id$ + * + * Copyright 1999-2004 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 org.apache.struts.config; + + +import java.io.Serializable; + +import java.util.Properties; + + +/** + * A abstract base class for all config classes. Provide basic support for arbitrary properties + * + * + * @since Struts 1.3 + */ +public abstract class BaseConfig implements Serializable { + + + /** + * Indicates if configuration of this component been completed. + * TODO change protected to private and use methods provided by extenders? + */ + protected boolean configured = false; + + /** + * A map of arbitrary properties configured for this component. + * @since Struts 1.3 + */ + private Properties properties = new Properties(); + + + + /** + * Freeze the configuration of this action. + */ + public void freeze() { + configured = true; + } + + /** + * Throw <code>IllegalStateException</code> if configuration is + * frozen. + * @throws IllegalStateException if configuration is frozen + */ + public void throwIfConfigured() { + if (configured) { + throw new IllegalStateException("Configuration is frozen"); + } + } + + + /** + * Set an arbitary key/value pair which can be retrieved by + * this config class. This facility should eliminate many use + * cases for subclassing <code>*Config</code> classes by + * providing a mechanism to pass any amount of arbitrary + * configuration information into an config class. + * <p /> + * This method must not be called after configuration is complete, or an + * <code>IllegalStateException</code> will be thrown.</p> + * + * <p><b>Example</b> + * <code><pre> + * <action path="/example" type="com.example.MyAction"> + * <set-property key="foo" property="bar" /> + * </action> + * </pre></code> + * </p> + * + * @param key the key by which this value will be retrieved + * @param value the value to store with the supplied key + * @since Struts 1.3 + * @exception IllegalStateException if this module configuration + * has been frozen + */ + public void setProperty(String key, String value) { + throwIfConfigured(); + properties.setProperty(key,value); + } + + /** + * Return the property-value for the specified key, if any; + * otherwise return <code>null</code>. + * + * @param key a key specified in the <code>struts-config</code> file + * @return the value stored with the supplied key + * @since Struts 1.3 + */ + public String getProperty(String key) { + return properties.getProperty(key); + } + + + /** + * Return the entire set of properties configured for this object. + * At this time, this only needs to be exposed + * to support inheritance, so choosing a conservative access modifier ("protected"). + * @return + */ + protected Properties getProperties() { + return this.properties; + } +} + Propchange: struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java Thu May 12 15:41:19 2005 @@ -72,7 +72,7 @@ digester.addRule ("struts-config/action-mappings/action/set-property", - new ActionConfigSetPropertyRule()); + new BaseConfigSetPropertyRule()); digester.addObjectCreate ("struts-config/action-mappings/action/exception", @@ -85,9 +85,9 @@ "addExceptionConfig", "org.apache.struts.config.ExceptionConfig"); - digester.addSetProperty - ("struts-config/action-mappings/action/exception/set-property", - "property", "value"); + digester.addRule + ("struts-config/action-mappings/action/exception/set-property", + new BaseConfigSetPropertyRule()); digester.addFactoryCreate ("struts-config/action-mappings/action/forward", @@ -99,9 +99,9 @@ "addForwardConfig", "org.apache.struts.config.ForwardConfig"); - digester.addSetProperty + digester.addRule ("struts-config/action-mappings/action/forward/set-property", - "property", "value"); + new BaseConfigSetPropertyRule()); digester.addObjectCreate ("struts-config/controller", @@ -114,9 +114,9 @@ "setControllerConfig", "org.apache.struts.config.ControllerConfig"); - digester.addSetProperty - ("struts-config/controller/set-property", - "property", "value"); + digester.addRule + ("struts-config/controller/forward/set-property", + new BaseConfigSetPropertyRule()); digester.addRule ("struts-config/form-beans", @@ -143,13 +143,13 @@ "addFormPropertyConfig", "org.apache.struts.config.FormPropertyConfig"); - digester.addSetProperty - ("struts-config/form-beans/form-bean/form-property/set-property", - "property", "value"); + digester.addRule + ("struts-config/form-beans/form-bean/form-property/set-property", + new BaseConfigSetPropertyRule()); - digester.addSetProperty + digester.addRule ("struts-config/form-beans/form-bean/set-property", - "property", "value"); + new BaseConfigSetPropertyRule()); digester.addObjectCreate ("struts-config/global-exceptions/exception", @@ -162,9 +162,10 @@ "addExceptionConfig", "org.apache.struts.config.ExceptionConfig"); - digester.addSetProperty + digester.addRule ("struts-config/global-exceptions/exception/set-property", - "property", "value"); + new BaseConfigSetPropertyRule()); + digester.addRule ("struts-config/global-forwards", @@ -180,9 +181,9 @@ "addForwardConfig", "org.apache.struts.config.ForwardConfig"); - digester.addSetProperty - ("struts-config/global-forwards/forward/set-property", - "property", "value"); + digester.addRule + ("struts-config/global-forwards/forward/set-property", + new BaseConfigSetPropertyRule()); digester.addObjectCreate ("struts-config/message-resources", @@ -195,9 +196,9 @@ "addMessageResourcesConfig", "org.apache.struts.config.MessageResourcesConfig"); - digester.addSetProperty - ("struts-config/message-resources/set-property", - "property", "value"); + digester.addRule + ("struts-config/message-resources/set-property", + new BaseConfigSetPropertyRule()); digester.addObjectCreate ("struts-config/plug-in", @@ -212,7 +213,7 @@ digester.addRule ("struts-config/plug-in/set-property", new PlugInSetPropertyRule()); - + // PluginConfig does not extend BaseConfig, at least for now. } } @@ -269,9 +270,9 @@ * In that case, the element being processed is assumed to have attributes * "property" and "value". */ -final class ActionConfigSetPropertyRule extends SetPropertyRule { +final class BaseConfigSetPropertyRule extends SetPropertyRule { - public ActionConfigSetPropertyRule() { + public BaseConfigSetPropertyRule() { super("property", "value"); } @@ -283,13 +284,24 @@ } if (attributes.getIndex("property") != -1) { - throw new IllegalArgumentException("<set-property> inside <action> accepts only one of 'key' or 'property' attributes."); + throw new IllegalArgumentException("<set-property> accepts only one of 'key' or 'property' attributes."); } - ActionConfig actionConfig = (ActionConfig) digester.peek(); - actionConfig.setProperty(attributes.getValue("key"), - attributes.getValue("value")); - + Object topOfStack = digester.peek(); + if (topOfStack instanceof BaseConfig) { + BaseConfig config = (BaseConfig) topOfStack; + config.setProperty(attributes.getValue("key"), + attributes.getValue("value")); + } else { + throw new IllegalArgumentException( + "'key' attribute of <set-property> only applicable to subclasses of BaseConfig; " + + "object on top of stack is " + topOfStack + + " [key: " + + attributes.getValue("key") + + ", value: " + + attributes.getValue("value") + + "]"); + } } Modified: struts/core/trunk/src/share/org/apache/struts/config/ControllerConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/ControllerConfig.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/ControllerConfig.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/ControllerConfig.java Thu May 12 15:41:19 2005 @@ -19,10 +19,6 @@ package org.apache.struts.config; - -import java.io.Serializable; - - /** * <p>A JavaBean representing the configuration information of a * <code><controller></code> element in a Struts @@ -32,16 +28,8 @@ * @since Struts 1.1 */ -public class ControllerConfig implements Serializable { - +public class ControllerConfig extends BaseConfig { - // ----------------------------------------------------- Instance Variables - - - /** - * Has this component been completely configured? - */ - protected boolean configured = false; // ------------------------------------------------------------- Properties @@ -324,17 +312,6 @@ // --------------------------------------------------------- Public Methods - - - /** - * Freeze the configuration of this component. - */ - public void freeze() { - - configured = true; - - } - /** * Return a String representation of this object. Modified: struts/core/trunk/src/share/org/apache/struts/config/ExceptionConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/ExceptionConfig.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/ExceptionConfig.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/ExceptionConfig.java Thu May 12 15:41:19 2005 @@ -19,10 +19,6 @@ package org.apache.struts.config; - -import java.io.Serializable; - - /** * <p>A JavaBean representing the configuration information of an * <code><exception></code> element from a Struts @@ -32,17 +28,7 @@ * @since Struts 1.1 */ -public class ExceptionConfig implements Serializable { - - - // ----------------------------------------------------- Instance Variables - - - /** - * Has this component been completely configured? - */ - protected boolean configured = false; - +public class ExceptionConfig extends BaseConfig { // ------------------------------------------------------------- Properties @@ -409,17 +395,6 @@ extensionProcessed = true; } - - - /** - * Freeze the configuration of this component. - */ - public void freeze() { - - configured = true; - - } - /** * Return a String representation of this object. Modified: struts/core/trunk/src/share/org/apache/struts/config/FormBeanConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/FormBeanConfig.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/FormBeanConfig.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/FormBeanConfig.java Thu May 12 15:41:19 2005 @@ -20,7 +20,6 @@ package org.apache.struts.config; -import java.io.Serializable; import java.util.HashMap; import java.lang.reflect.InvocationTargetException; @@ -49,17 +48,12 @@ * @since Struts 1.1 */ -public class FormBeanConfig implements Serializable { +public class FormBeanConfig extends BaseConfig { private static final Log log = LogFactory.getLog(FormBeanConfig.class); // ----------------------------------------------------- Instance Variables - /** - * Has this component been completely configured? - */ - protected boolean configured = false; - /** * The set of FormProperty elements defining dynamic form properties for @@ -116,9 +110,7 @@ * is now computed automatically in <code>setType()</code> */ public void setDynamic(boolean dynamic) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); ; // No action required } @@ -134,9 +126,7 @@ } public void setExtends(String extend) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); this.inherit = extend; } @@ -164,9 +154,7 @@ } public void setName(String name) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); this.name = name; } @@ -182,9 +170,7 @@ } public void setType(String type) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); this.type = type; Class dynaBeanClass = DynaActionForm.class; Class formBeanClass = formBeanClass(); @@ -267,9 +253,7 @@ InstantiationException, InvocationTargetException { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); // Inherit form property configs FormPropertyConfig[] baseFpcs = config.findFormPropertyConfigs(); @@ -429,9 +413,7 @@ */ public void addFormPropertyConfig(FormPropertyConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); if (formProperties.containsKey(config.getName())) { throw new IllegalArgumentException("Property " + config.getName() + @@ -473,7 +455,7 @@ */ public void freeze() { - configured = true; + super.freeze(); FormPropertyConfig[] fpconfigs = findFormPropertyConfigs(); for (int i = 0; i < fpconfigs.length; i++) { @@ -514,9 +496,7 @@ InstantiationException, InvocationTargetException { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); // Inherit values that have not been overridden if (getName() == null) { Modified: struts/core/trunk/src/share/org/apache/struts/config/FormPropertyConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/FormPropertyConfig.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/FormPropertyConfig.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/FormPropertyConfig.java Thu May 12 15:41:19 2005 @@ -20,7 +20,6 @@ package org.apache.struts.config; -import java.io.Serializable; import java.lang.reflect.Array; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.logging.Log; @@ -36,7 +35,7 @@ * @since Struts 1.1 */ -public class FormPropertyConfig implements Serializable { +public class FormPropertyConfig extends BaseConfig { /** * The logging instance @@ -96,11 +95,6 @@ // ----------------------------------------------------- Instance Variables - /** - * Has this component been completely configured? - */ - protected boolean configured = false; - // ------------------------------------------------------------- Properties @@ -358,17 +352,6 @@ } } - - - /** - * Freeze the configuration of this component. - */ - public void freeze() { - - configured = true; - - } - /** * Return a String representation of this object. Modified: struts/core/trunk/src/share/org/apache/struts/config/ForwardConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/ForwardConfig.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/ForwardConfig.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/ForwardConfig.java Thu May 12 15:41:19 2005 @@ -19,10 +19,6 @@ package org.apache.struts.config; - -import java.io.Serializable; - - /** * <p>A JavaBean representing the configuration information of a * <code><forward></code> element from a Struts @@ -32,7 +28,7 @@ * @since Struts 1.1 */ -public class ForwardConfig implements Serializable { +public class ForwardConfig extends BaseConfig { // ----------------------------------------------------------- Constructors @@ -103,16 +99,6 @@ } - - // ----------------------------------------------------- Instance Variables - - - /** - * Has this component been completely configured? - */ - protected boolean configured = false; - - // ------------------------------------------------------------- Properties @@ -135,9 +121,7 @@ * @deprecated Use module property instead; will be removed in a release following 1.2.0. */ public void setContextRelative(boolean contextRelative) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); this.contextRelative = contextRelative; } @@ -531,17 +515,6 @@ extensionProcessed = true; } - - - /** - * Freeze the configuration of this component. - */ - public void freeze() { - - configured = true; - - } - /** * Return a String representation of this object. Modified: struts/core/trunk/src/share/org/apache/struts/config/MessageResourcesConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/MessageResourcesConfig.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/MessageResourcesConfig.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/MessageResourcesConfig.java Thu May 12 15:41:19 2005 @@ -33,17 +33,7 @@ * @since Struts 1.1 */ -public class MessageResourcesConfig implements Serializable { - - - // ----------------------------------------------------- Instance Variables - - - /** - * Has this component been completely configured? - */ - protected boolean configured = false; - +public class MessageResourcesConfig extends BaseConfig { // ------------------------------------------------------------- Properties @@ -121,17 +111,6 @@ // --------------------------------------------------------- Public Methods - - - /** - * Freeze the configuration of this component. - */ - public void freeze() { - - configured = true; - - } - /** * Return a String representation of this object. Modified: struts/core/trunk/src/share/org/apache/struts/config/PlugInConfig.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/PlugInConfig.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/PlugInConfig.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/PlugInConfig.java Thu May 12 15:41:19 2005 @@ -29,7 +29,12 @@ * <p>A JavaBean representing the configuration information of a * <code><plug-in></code> element in a Struts * configuration file.</p> - * + * <p>Note that this class does not extend <code>BaseConfig</code> because it is more "internal" + * than the other classes which do, and because this class has an existing "properties" object + * which collides with the one in <code>BaseConfig</code>. Also, since one always writes a concrete + * PlugIn implementation, there seems to be less call for an arbitrary property map; one can simply + * use bean properties instead.</p> + * * @version $Rev$ $Date$ * @since Struts 1.1 */ Modified: struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java?rev=169898&r1=169897&r2=169898&view=diff ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java (original) +++ struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java Thu May 12 15:41:19 2005 @@ -25,6 +25,7 @@ import org.apache.struts.config.ActionConfig; import org.apache.struts.config.ActionConfigMatcher; +import org.apache.struts.config.BaseConfig; import org.apache.struts.config.ControllerConfig; import org.apache.struts.config.ExceptionConfig; import org.apache.struts.config.FormBeanConfig; @@ -45,7 +46,7 @@ * @version $Rev$ $Date$ * @since Struts 1.1 */ -public class ModuleConfigImpl implements Serializable, ModuleConfig { +public class ModuleConfigImpl extends BaseConfig implements Serializable, ModuleConfig { /** * Construct an ModuleConfigImpl object according to the specified @@ -97,9 +98,7 @@ * @param cc The controller configuration object for this module. */ public void setControllerConfig(ControllerConfig cc) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); this.controllerConfig = cc; } @@ -120,9 +119,7 @@ * default configuration for this web module. */ public void setPrefix(String prefix) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); this.prefix = prefix; } @@ -173,9 +170,7 @@ */ public void addActionConfig(ActionConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); config.setModuleConfig(this); actionConfigs.put(config.getPath(), config); actionConfigList.add(config); @@ -193,9 +188,7 @@ */ public void addExceptionConfig(ExceptionConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); exceptions.put(config.getType(), config); } @@ -211,9 +204,7 @@ */ public void addFormBeanConfig(FormBeanConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); formBeans.put(config.getName(), config); } @@ -246,9 +237,7 @@ */ public void addForwardConfig(ForwardConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); forwards.put(config.getName(), config); } @@ -264,9 +253,7 @@ */ public void addMessageResourcesConfig(MessageResourcesConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); messageResources.put(config.getKey(), config); } @@ -279,9 +266,7 @@ */ public void addPlugInConfig(PlugInConfig plugInConfig) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); plugIns.add(plugInConfig); } @@ -430,7 +415,7 @@ */ public void freeze() { - this.configured = true; + super.freeze(); ActionConfig[] aconfigs = findActionConfigs(); for (int i = 0; i < aconfigs.length; i++) { @@ -476,9 +461,7 @@ */ public void removeActionConfig(ActionConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); config.setModuleConfig(null); actionConfigs.remove(config.getPath()); actionConfigList.remove(config); @@ -495,9 +478,7 @@ */ public void removeExceptionConfig(ExceptionConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); exceptions.remove(config.getType()); } @@ -512,9 +493,7 @@ */ public void removeFormBeanConfig(FormBeanConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); formBeans.remove(config.getName()); } @@ -529,9 +508,7 @@ */ public void removeForwardConfig(ForwardConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); forwards.remove(config.getName()); } @@ -546,9 +523,7 @@ */ public void removeMessageResourcesConfig(MessageResourcesConfig config) { - if (configured) { - throw new IllegalStateException("Configuration is frozen"); - } + throwIfConfigured(); messageResources.remove(config.getKey()); } @@ -598,13 +573,6 @@ * if any, in the order they were declared and configured. */ protected ArrayList plugIns = null; - - /** - * Has this module been completely configured yet. Once this flag - * has been set, any attempt to modify the configuration will return an - * IllegalStateException. - */ - protected boolean configured = false; /** * The controller configuration object for this module. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]