/** * <p>Compare the properties of this config with that of the given and * copy those that are not present. This method is used by subclasses * that support configuration inheritance.</p> * * @param baseConfig The config object to copy properties from. */ protected void inheritProperties(BaseConfig baseConfig) { throwIfConfigured(); // Inherit forward 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 = this.getProperty(key); if (value == null) { value = baseProperties.getProperty(key); setProperty(key, value); } } }
/** * Freeze the configuration of this component. */ public void freeze() { super.freeze(); FormPropertyConfig[] fpconfigs = findFormPropertyConfigs(); for (int i = 0; i < fpconfigs.length; i++) { fpconfigs[i].freeze(); } }
/** * <p> 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 * @throws IllegalStateException if this module configuration has been * frozen * @since Struts 1.3 */ public void setProperty(String key, String value) { throwIfConfigured(); properties.setProperty(key, value); }
public void begin(Attributes attributes) throws Exception { if (attributes.getIndex("key") == -1) { super.begin(attributes); return; } if (attributes.getIndex("property") != -1) { throw new IllegalArgumentException( "<set-property> accepts only one of 'key' or 'property' attributes."); } 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") + "]"); } } }
/** * <p> Freeze the configuration of this action. </p> */ public void freeze() { super.freeze(); ExceptionConfig[] econfigs = findExceptionConfigs(); for (int i = 0; i < econfigs.length; i++) { econfigs[i].freeze(); } ForwardConfig[] fconfigs = findForwardConfigs(); for (int i = 0; i < fconfigs.length; i++) { fconfigs[i].freeze(); } }