You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hr...@apache.org on 2005/05/22 01:06:54 UTC

svn commit: r171263 - in /struts/core/trunk/src: share/org/apache/struts/config/ test/org/apache/struts/config/

Author: hrabago
Date: Sat May 21 16:06:53 2005
New Revision: 171263

URL: http://svn.apache.org/viewcvs?rev=171263&view=rev
Log:
Move inheritProperties() to BaseConfig.java.
Implement inheritance of arbitrary config properties for ExceptionConfig, FormBeanConfig, FormPropertyConfig, and ForwardConfig.
Standardize exceptions thrown by config inheritance methods.
Add simple tests for arbitrary config prop inheritance.

Modified:
    struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java
    struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.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/test/org/apache/struts/config/TestFormBeanConfig.java
    struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java
    struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java

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=171263&r1=171262&r2=171263&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 Sat May 21 16:06:53 2005
@@ -770,40 +770,6 @@
     }
 
 
-    /**
-     * <p>Compare the properties of this action with that of the given and
-     * copy those that are not present.</p>
-     *
-     * @param baseConfig    The action config to copy properties from.
-     *
-     * @see #inheritFrom(ActionConfig)
-     */
-    protected void inheritProperties(ActionConfig baseConfig)
-            throws ClassNotFoundException,
-            IllegalAccessException,
-            InstantiationException,
-            InvocationTargetException {
-
-        if (configured) {
-            throw new IllegalStateException("Configuration is frozen");
-        }
-
-        // 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);
-            }
-        }
-    }
-
-
     // --------------------------------------------------------- Public Methods
 
 

Modified: 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=171263&r1=171262&r2=171263&view=diff
==============================================================================
--- struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java (original)
+++ struts/core/trunk/src/share/org/apache/struts/config/BaseConfig.java Sat May 21 16:06:53 2005
@@ -22,6 +22,8 @@
 import java.io.Serializable;
 
 import java.util.Properties;
+import java.util.Enumeration;
+import java.lang.reflect.InvocationTargetException;
 
 
 /**
@@ -53,6 +55,7 @@
     public void freeze() {
         configured = true;
     }
+    
 
     /**
      * Throw <code>IllegalStateException</code> if configuration is 
@@ -94,6 +97,7 @@
         throwIfConfigured();
         properties.setProperty(key,value);
     }
+    
 
     /**
      * Return the property-value for the specified key, if any;
@@ -117,5 +121,33 @@
     protected Properties getProperties() {
         return this.properties;
     }
+
+    
+    /**
+     * <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);
+            }
+        }
+    }
+
 }
 

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=171263&r1=171262&r2=171263&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 Sat May 21 16:06:53 2005
@@ -19,6 +19,8 @@
 
 package org.apache.struts.config;
 
+import java.lang.reflect.InvocationTargetException;
+
 /**
  * <p>A JavaBean representing the configuration information of an
  * <code>&lt;exception&gt;</code> element from a Struts
@@ -289,8 +291,9 @@
      */
     public void inheritFrom(ExceptionConfig config)
             throws ClassNotFoundException,
-            IllegalAccessException,
-            InstantiationException {
+                   IllegalAccessException,
+                   InstantiationException,
+                   InvocationTargetException {
 
         if (configured) {
             throw new IllegalStateException("Configuration is frozen");
@@ -320,6 +323,8 @@
         if (getType() == null) {
             setType(config.getType());
         }
+        
+        inheritProperties(config);
     }
 
 
@@ -340,8 +345,9 @@
                                ActionConfig actionConfig)
             throws ClassNotFoundException,
                    IllegalAccessException,
-                   InstantiationException {
-
+                   InstantiationException,
+                   InvocationTargetException {
+        
         if (configured) {
             throw new IllegalStateException("Configuration is frozen");
         }

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=171263&r1=171262&r2=171263&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 Sat May 21 16:06:53 2005
@@ -512,6 +512,7 @@
         }
 
         inheritFormProperties(config);
+        inheritProperties(config);
     }
 
 

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=171263&r1=171262&r2=171263&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 Sat May 21 16:06:53 2005
@@ -21,6 +21,8 @@
 
 
 import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+
 import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -329,7 +331,11 @@
      * @param config    The object that this instance will be inheriting
      *                  its values from.
      */
-    public void inheritFrom(FormPropertyConfig config) {
+    public void inheritFrom(FormPropertyConfig config) 
+            throws IllegalAccessException, 
+            InvocationTargetException, 
+            InstantiationException, 
+            ClassNotFoundException {
 
         if (configured) {
             throw new IllegalStateException("Configuration is frozen");
@@ -350,7 +356,8 @@
         if (getType() == null) {
             setType(config.getType());
         }
-
+        
+        inheritProperties(config);
     }
 
     /**

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=171263&r1=171262&r2=171263&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 Sat May 21 16:06:53 2005
@@ -19,6 +19,8 @@
 
 package org.apache.struts.config;
 
+import java.lang.reflect.InvocationTargetException;
+
 /**
  * <p>A JavaBean representing the configuration information of a
  * <code>&lt;forward&gt;</code> element from a Struts
@@ -406,7 +408,8 @@
     public void inheritFrom(ForwardConfig config)
             throws ClassNotFoundException,
             IllegalAccessException,
-            InstantiationException {
+            InstantiationException,
+            InvocationTargetException {
 
         if (configured) {
             throw new IllegalStateException("Configuration is frozen");
@@ -441,6 +444,7 @@
             setRedirect(config.getRedirect());
         }
 
+        inheritProperties(config);
     }
 
 
@@ -461,7 +465,8 @@
                                ActionConfig actionConfig)
             throws ClassNotFoundException,
                    IllegalAccessException,
-                   InstantiationException {
+                   InstantiationException,
+                   InvocationTargetException {
 
         if (configured) {
             throw new IllegalStateException("Configuration is frozen");

Modified: struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java?rev=171263&r1=171262&r2=171263&view=diff
==============================================================================
--- struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java (original)
+++ struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java Sat May 21 16:06:53 2005
@@ -232,6 +232,10 @@
     public void testInheritFrom() 
             throws Exception {
         
+        // give baseForm some arbitrary parameters
+        String baseFormCount = "1";
+        baseForm.setProperty("count", baseFormCount);
+        
         // create a basic subform
         FormBeanConfig subForm = new FormBeanConfig();
         String subFormName = "subForm";
@@ -258,7 +262,6 @@
         property.setSize(10);
         subForm.addFormPropertyConfig(property);
         
-
         config.addFormBeanConfig(subForm);
         
         subForm.inheritFrom(baseForm);
@@ -317,74 +320,13 @@
         assertEquals("Wrong initial value for message", original.getInitial(),
                 property.getInitial());
         assertEquals("Wrong size value for message", 10, property.getSize());
+        
+        String count = subForm.getProperty("count");
+        assertEquals("Arbitrary property was not inherited", 
+                baseFormCount, count); 
     }
-    
-    
-    ///**
-    // * Test that a subform's property is changed to use the correct 
-    // * FormPropertyConfig subclass if a superform's prop class is overridden.
-    // * Also test that the subclass' inheritFrom() gets called, and that
-    // * overridden values are retained, even when a prop's class is changed.
-    // */ 
-    //public void testInheritFromCustomFormProperty() 
-    //        throws Exception {
-    //
-    //
-    //    // Modify baseForm, changing 2 props to use a custom config object
-    //    FormPropertyConfig id = baseForm.findFormPropertyConfig("id");
-    //    CustomFormPropertyConfig customId = new CustomFormPropertyConfig();
-    //    customId.setName(id.getName());
-    //    customId.setType(id.getType());
-    //    customId.setInitial(id.getInitial());
-    //    customId.setSize(id.getSize());
-    //    customId.integer = 12;
-    //    baseForm.removeFormPropertyConfig(id);
-    //    baseForm.addFormPropertyConfig(customId);
-    //    
-    //    FormPropertyConfig name = baseForm.findFormPropertyConfig("name");
-    //    CustomFormPropertyConfig customName = new CustomFormPropertyConfig();
-    //    customName.setName(name.getName());
-    //    customName.setType(name.getType());
-    //    customName.setInitial(name.getInitial());
-    //    customName.setSize(name.getSize());
-    //    baseForm.removeFormPropertyConfig(name);
-    //    baseForm.addFormPropertyConfig(customName);
-    //    
-    //    // Create our subform
-    //    FormBeanConfig subForm = new FormBeanConfig();
-    //    String subFormName = "subForm";
-    //    subForm.setName(subFormName);
-    //    subForm.setExtends("baseForm");
-    //    
-    //    // Add an "id" prop with some overridden values
-    //    FormPropertyConfig property = new FormPropertyConfig();
-    //    property.setName("id");
-    //    property.setType("java.lang.Integer");  
-    //    subForm.addFormPropertyConfig(property);
-    //    
-    //    // The "name" property isn't overridden and won't be configured
-    //    
-    //    // now let's run this thing
-    //    subForm.inheritFrom(baseForm);
-    //    
-    //    // Let's see what we have
-    //    
-    //    FormPropertyConfig subId = subForm.findFormPropertyConfig("id");
-    //    assertTrue("Incorrect form property class",
-    //            subId instanceof CustomFormPropertyConfig);
-    //    
-    //    assertEquals("An overridden value was lost", 
-    //            "java.lang.Integer", subId.getType());
-    //    
-    //    assertEquals("Custom class' inheritFrom() was not called.", 12, 
-    //            ((CustomFormPropertyConfig) subId).integer);
-    //
-    //    FormPropertyConfig subName = subForm.findFormPropertyConfig("name");
-    //    assertTrue("Incorrect form property class",
-    //            subName instanceof CustomFormPropertyConfig);
-    //}
-    
-    
+
+
     /**
      * Used to detect that FormBeanConfig is making the right calls.
      */ 
@@ -400,22 +342,5 @@
         }
     }
 
-    
-    ///**
-    // * Used to test custom FormPropertyConfig classes.
-    // */ 
-    //public static class CustomFormPropertyConfig 
-    //        extends FormPropertyConfig {
-    //    
-    //    int integer = 0;
-    //
-    //    public void inheritFrom(FormPropertyConfig config) {
-    //        super.inheritFrom(config);
-    //        if (config instanceof CustomFormPropertyConfig) {
-    //            this.integer = ((CustomFormPropertyConfig) config).integer;
-    //        }
-    //    }
-    //
-    //}
-    
+
 }

Modified: struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java?rev=171263&r1=171262&r2=171263&view=diff
==============================================================================
--- struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java (original)
+++ struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java Sat May 21 16:06:53 2005
@@ -29,9 +29,12 @@
         extends TestCase {
     
     
-    public void testBasicInherit() {
+    public void testBasicInherit() 
+            throws Exception {
         FormPropertyConfig base = 
                 new FormPropertyConfig("base", "java.lang.String[]", "", 10);
+        String baseCount = "10";
+        base.setProperty("count", baseCount);
         
         FormPropertyConfig sub = new FormPropertyConfig();
         sub.setName("base");
@@ -41,10 +44,13 @@
         assertEquals("Type was not inherited", base.getType(), sub.getType());
         assertEquals("Initial is incorrect", 
                 base.getInitial(), sub.getInitial());
-        assertEquals("Size was not inherited", base.getSize(), sub.getSize());        
+        assertEquals("Size was not inherited", base.getSize(), sub.getSize());
+        assertEquals("Arbitrary config property was not inherited",
+                baseCount, sub.getProperty("count"));
     }
     
-    public void testInheritWithInitialOverride() {
+    public void testInheritWithInitialOverride() 
+            throws Exception {
         FormPropertyConfig base = 
                 new FormPropertyConfig("base", "java.lang.String", "value");
         
@@ -61,7 +67,8 @@
         assertEquals("Size is incorrect", base.getSize(), sub.getSize());        
     }
                 
-    public void testInheritWithTypeOverride() {
+    public void testInheritWithTypeOverride() 
+            throws Exception {
         FormPropertyConfig base = 
                 new FormPropertyConfig("base", "java.lang.String", "");
         
@@ -77,7 +84,8 @@
         assertEquals("Size is incorrect", base.getSize(), sub.getSize());        
     }
     
-    public void testInheritWithTypeOverride2() {
+    public void testInheritWithTypeOverride2() 
+            throws Exception {
         FormPropertyConfig base = 
                 new FormPropertyConfig("base", "java.lang.String", "");
         
@@ -96,7 +104,8 @@
         assertEquals("Size is incorrect", size, sub.getSize());        
     }
     
-    public void testInheritWithSizeOverride() {
+    public void testInheritWithSizeOverride() 
+            throws Exception {
         FormPropertyConfig base = 
                 new FormPropertyConfig("base", "java.lang.String[]", "", 20);
         
@@ -112,5 +121,6 @@
                 base.getInitial(), sub.getInitial());
         assertEquals("Size is incorrect", size, sub.getSize());        
     }
+    
     
 }

Modified: struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java?rev=171263&r1=171262&r2=171263&view=diff
==============================================================================
--- struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java (original)
+++ struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java Sat May 21 16:06:53 2005
@@ -317,6 +317,12 @@
      */
     public void testProcessExtendsBasicExtension() 
             throws Exception {
+        
+        String baseCount = "10";
+        baseConfig.setProperty("count", baseCount);
+
+        String baseLabel = "label a";
+        baseConfig.setProperty("label", baseLabel);
 
         String path = baseConfig.getPath();
         String module = baseConfig.getModule();
@@ -325,6 +331,9 @@
         String name = subConfig.getName();
         boolean redirect = subConfig.getRedirect();
         
+        String subLabel = "label b";
+        subConfig.setProperty("label", subLabel);
+        
         moduleConfig.addForwardConfig(baseConfig);
         moduleConfig.addForwardConfig(subConfig);
         subConfig.processExtends(moduleConfig, null);
@@ -337,6 +346,10 @@
                 subConfig.getExtends());
         assertEquals("Redirect shouldn't have changed", redirect,
                 subConfig.getRedirect());
+        assertEquals("Arbitrary config property was not inherited",
+                baseCount, subConfig.getProperty("count"));
+        assertEquals("Overridden config property was not retained",
+                subLabel, subConfig.getProperty("label"));
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org