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/03 03:02:21 UTC

svn commit: r167840 - in /struts/core/trunk/src: share/org/apache/struts/config/ActionConfig.java test/org/apache/struts/config/TestActionConfig.java

Author: hrabago
Date: Mon May  2 18:02:21 2005
New Revision: 167840

URL: http://svn.apache.org/viewcvs?rev=167840&view=rev
Log:
Inherit arbitrary ActionConfig properties.

Modified:
    struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java
    struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.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=167840&r1=167839&r2=167840&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 Mon May  2 18:02:21 2005
@@ -25,6 +25,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Properties;
+import java.util.Enumeration;
 import java.lang.reflect.InvocationTargetException;
 
 
@@ -780,6 +781,40 @@
     }
 
 
+    /**
+     * <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.properties;
+        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);
+            if (value == null) {
+                value = baseProperties.getProperty(key);
+                setProperty(key, value);
+            }            
+        }
+    }
+
+
     // --------------------------------------------------------- Public Methods
 
 
@@ -1092,6 +1127,7 @@
 
         inheritExceptionHandlers(config);
         inheritForwards(config);
+        inheritProperties(config);
     }
 
     

Modified: struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java?rev=167840&r1=167839&r2=167840&view=diff
==============================================================================
--- struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java (original)
+++ struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java Mon May  2 18:02:21 2005
@@ -93,6 +93,10 @@
         exceptionConfig.setType("java.sql.SQLException");
         exceptionConfig.setKey("msg.exception.sql");
         baseConfig.addExceptionConfig(exceptionConfig);
+
+        // set some arbitrary properties
+        baseConfig.setProperty("label", "base");
+        baseConfig.setProperty("version", "1a");
         
         // register it to our config
         config.addActionConfig(baseConfig);
@@ -243,6 +247,9 @@
         handler.setKey("msg.exception.npe");
         subConfig.addExceptionConfig(handler);
         
+        // override arbitrary "label" property
+        subConfig.setProperty("label", "sub");
+        
         config.addActionConfig(subConfig);
         
         subConfig.inheritFrom(baseConfig);
@@ -284,6 +291,15 @@
         handler = subConfig.findExceptionConfig("java.lang.NullPointerException");
         assertNotNull("'NullPointerException' handler disappeared",
                 handler);
+        
+        // check the arbitrary properties
+        String version = subConfig.getProperty("version");
+        assertEquals("Arbitrary property 'version' wasn't inherited", 
+                "1a", version);
+
+        String label = subConfig.getProperty("label");
+        assertEquals("Arbitrary property 'label' shouldn't have changed", 
+                "sub", label);
     }
     
     



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